44
55namespace TypeLang \Parser ;
66
7+ /**
8+ * Configures language features supported by the parser.
9+ *
10+ * Feature flags allow enabling or disabling individual language constructs.
11+ * When a feature is disabled, the parser will treat the corresponding syntax
12+ * as unsupported and report an error.
13+ *
14+ * ```
15+ * $parser = new Parser(new ParserFeatures(
16+ * conditions: false,
17+ * ));
18+ *
19+ * $parser->parse('T is 42 ? U : V');
20+ * // => Error: Conditional expressions not allowed in ...
21+ * ```
22+ */
723final readonly class ParserFeatures
824{
925 public const bool CONDITIONAL_FEATURES_DEFAULT_VALUE = true ;
2036
2137 public function __construct (
2238 /**
23- * Enables or disables support for dependent/conditional
24- * types such as `T ? U : V`
39+ * Enables or disables support for conditional types such as `T ? U : V`
2540 */
2641 public bool $ conditions = self ::CONDITIONAL_FEATURES_DEFAULT_VALUE ,
2742 /**
28- * Enables or disables support for type shapes such
29- * as `T{key: U}`
43+ * Enables or disables support for shape types such as `T{key: U}`
3044 */
3145 public bool $ shapes = self ::SHAPES_FEATURES_DEFAULT_VALUE ,
3246 /**
33- * Enables or disables support for callable types
34- * such as `(T, U): V`
47+ * Enables or disables support for callable types such as `fn(T, U): V`
3548 */
3649 public bool $ callables = self ::CALLABLES_FEATURES_DEFAULT_VALUE ,
3750 /**
38- * Enables or disables support for literal types such
39- * as `42` or `"string"`
51+ * Enables or disables support for literal types such as `42` or `'foo'`
4052 */
4153 public bool $ literals = self ::LITERALS_FEATURES_DEFAULT_VALUE ,
4254 /**
43- * Enables or disables support for template arguments
44- * such as `T<U, V>`
55+ * Enables or disables support for generic type arguments such as `T<U, V>`
4556 */
4657 public bool $ generics = self ::GENERICS_FEATURES_DEFAULT_VALUE ,
4758 /**
48- * Enables or disables support for logical union types
49- * such as `T | U`
59+ * Enables or disables support for union types such as `T | U`
5060 */
5161 public bool $ unions = self ::UNION_FEATURES_DEFAULT_VALUE ,
5262 /**
53- * Enables or disables support for logical intersection
54- * types such as `T & U`
63+ * Enables or disables support for intersection types such as `T & U`
5564 */
5665 public bool $ intersections = self ::INTERSECTION_FEATURES_DEFAULT_VALUE ,
5766 /**
58- * Enables or disables support for square bracket list
59- * types such as `T[]`
67+ * Enables or disables support for short list types such as `T[]`
6068 */
6169 public bool $ lists = self ::LIST_FEATURES_DEFAULT_VALUE ,
6270 /**
63- * Enables or disables support for square bracket offset
64- * access types such as `T[U]`
71+ * Enables or disables support for offset access types such as `T[U]`
6572 */
6673 public bool $ offsets = self ::OFFSETS_FEATURES_DEFAULT_VALUE ,
6774 /**
68- * Enables or disables support for template argument hints
69- * such as `T<out U, in V>`
75+ * Enables or disables support for generic variance hints such as `T<out U, in V>`
7076 */
7177 public bool $ hints = self ::HINTS_FEATURES_DEFAULT_VALUE ,
7278 /**
@@ -76,14 +82,18 @@ public function __construct(
7682 ) {}
7783
7884 /**
79- * A general method with the ability to override a specific feature flag
85+ * Creates a new feature set with one or more feature flags overridden.
86+ *
87+ * Any feature not explicitly specified retains its current value.
8088 *
8189 * ```
8290 * $features = $features->with(
8391 * conditions: true,
8492 * hints: false,
8593 * );
8694 * ```
95+ *
96+ * @phpstan-pure
8797 */
8898 public function with (bool ...$ features ): self
8999 {
0 commit comments