@@ -32,88 +32,15 @@ the automatic section numbering tooling, they **must** be maintained manually.
32
32
33
33
# Verification-Only Replacements & Additions
34
34
35
- This set of replacements and additions is the bare minimum required to allow the grammar to verify and run, though
36
- it may not produce the desired parse (that requires at least the use of modes and/or
37
- lexical predicates).
35
+ This set of replacements and additions is the bare minimum required to allow the grammar
36
+ to verify and run, though it may not produce the desired lex and parse (that requires at
37
+ least the use of modes and/or lexical predicates).
38
38
39
- This set can be used as a basic check that the grammar is a correct ANTLR grammar.
39
+ Pre-processing directives are skipped like whitespace, however lexing confirms the lexical
40
+ grammar is valid.
40
41
41
- ---
42
-
43
- ## Top Level Rule
44
-
45
- The Standard’s * compilation_unit* as is will allow garbage at the end of a file, this
46
- rule has an EOF requirement to ensure the whole of the input must be a correct program.
47
-
48
- > * Note: The section number makes this the first rule in the grammar, not required but it
49
- has to go somewhere…*
50
-
51
- ### 0.0.0 Top Level Rule
52
-
53
- ``` ANTLR
54
- // [ADDED] Rule added as the start point
55
- prog: compilation_unit EOF;
56
- ```
57
- ---
58
-
59
- ## Discarding Whitespace
60
-
61
- The following changes in §7.3.2, §7.3.3 and §7.3.4, add ` -> skip ` to the “whitespace”
62
- token rules so that are not passed to the parser. This behaviour is implicit in the
63
- Standard.
64
-
65
- ### 7.3.2 Line terminators
66
-
67
- ``` ANTLR
68
- // [SKIP]
69
- New_Line
70
- : ( New_Line_Character
71
- | '\u000D\u000A' // carriage return, line feed
72
- ) -> skip
73
- ;
74
- ```
75
-
76
- ### 7.3.3 Comments
77
-
78
- ``` ANTLR
79
- // [SKIP]
80
- Comment
81
- : ( Single_Line_Comment
82
- | Delimited_Comment
83
- ) -> skip
84
- ;
85
- ```
86
-
87
- ### 7.3.4 White space
88
-
89
- ``` ANTLR
90
- // [SKIP]
91
- Whitespace
92
- : ( [\p{Zs}] // any character with Unicode class Zs
93
- | '\u0009' // horizontal tab
94
- | '\u000B' // vertical tab
95
- | '\u000C' // form feed
96
- ) -> skip
97
- ;
98
-
99
- ```
100
-
101
- ---
102
-
103
- ## Pre-processing directives
104
-
105
- This change causes all pre-processor directives to be discarded, they don’t need to be
106
- processed to validate the grammar (processing them would exercise the * implementation*
107
- of the pre-processor, which is not part of the Standard).
42
+ This set can be used as a basic check that the grammar is a valid ANTLR grammar.
108
43
109
- ### 7.5.1 General
110
-
111
- ``` ANTLR
112
- // [CHANGE] Discard pre-processor directives
113
- PP_Directive
114
- : (PP_Start PP_Kind PP_New_Line) -> skip
115
- ;
116
- ```
117
44
118
45
---
119
46
@@ -125,32 +52,73 @@ strive not to introduce any new ones).
125
52
This change resolves the one remaining MLR group by inlining some of the non-terminal
126
53
alternatives in * primary_no_array_creation_expression* .
127
54
128
- Non-terminals that are inlined are commented out and the inlined body is indented.
55
+ Non-terminals that are inlined
56
+ are commented out and the inlined body is indented.
129
57
130
58
This change has not been made to the Standard itself as it makes * primary_no_array_creation_expression*
131
- “uglier” and would obfuscate somewhat the description in the Standard.
59
+ “uglier” and would obfuscate somewhat the description in the Standard – both
60
+ subjective reasons of course...
132
61
133
62
As MLR is not supported by ANTLR without this change the grammar would be rejected.
134
63
135
- ### 12.7 .1 General
64
+ ### 12.8 .1 General
136
65
137
66
``` ANTLR
138
67
// [CHANGE] This removes a mutual left-recursion group which we have (currently?)
139
- // [CHANGE] decided to leave in the Standard. Without this change the grammar will fail.
68
+ // [CHANGE] decided to leave in the Standard. Without this change the grammar will
69
+ // [CHANGE] fail to verify.
70
+ # Expect
140
71
primary_no_array_creation_expression
141
72
: literal
73
+ | interpolated_string_expression
142
74
| simple_name
143
75
| parenthesized_expression
76
+ | tuple_expression
77
+ | member_access
78
+ | null_conditional_member_access
79
+ | invocation_expression
80
+ | element_access
81
+ | null_conditional_element_access
82
+ | this_access
83
+ | base_access
84
+ | post_increment_expression
85
+ | post_decrement_expression
86
+ | object_creation_expression
87
+ | delegate_creation_expression
88
+ | anonymous_object_creation_expression
89
+ | typeof_expression
90
+ | sizeof_expression
91
+ | checked_expression
92
+ | unchecked_expression
93
+ | default_value_expression
94
+ | nameof_expression
95
+ | anonymous_method_expression
96
+ | pointer_member_access // unsafe code support
97
+ | pointer_element_access // unsafe code support
98
+ | stackalloc_expression
99
+ ;
100
+ # ReplaceWith
101
+ primary_no_array_creation_expression
102
+ : literal
103
+ | interpolated_string_expression
104
+ | simple_name
105
+ | parenthesized_expression
106
+ | tuple_expression
144
107
// | member_access
145
108
| primary_no_array_creation_expression '.' identifier type_argument_list?
146
109
| array_creation_expression '.' identifier type_argument_list?
147
110
| predefined_type '.' identifier type_argument_list?
148
111
| qualified_alias_member '.' identifier type_argument_list?
112
+ // | null_conditional_member_access
113
+ | primary_no_array_creation_expression '?' '.' identifier type_argument_list? dependent_access*
114
+ | array_creation_expression '?' '.' identifier type_argument_list? dependent_access*
149
115
// | invocation_expression
150
116
| primary_no_array_creation_expression '(' argument_list? ')'
151
117
| array_creation_expression '(' argument_list? ')'
152
118
// | element_access and pointer_element_access (unsafe code support)
153
119
| primary_no_array_creation_expression '[' argument_list ']'
120
+ // | null_conditional_element_access
121
+ | primary_no_array_creation_expression '?' '[' argument_list ']' dependent_access*
154
122
| this_access
155
123
| base_access
156
124
// | post_increment_expression
@@ -174,5 +142,31 @@ primary_no_array_creation_expression
174
142
| array_creation_expression '->' identifier type_argument_list?
175
143
// | pointer_element_access // unsafe code support
176
144
// covered by element_access replacement above
145
+ | stackalloc_expression
146
+ ;
147
+ ```
148
+
149
+
150
+ ---
151
+
152
+ ## Interpolated strings
153
+
154
+ The lexical rules for interpolated strings are context-sensitive and are not ANLTR-ready in the Standard
155
+ as how such rules are handled is an implementation detail, e.g. using ANTLR modes.
156
+ Here we just define one token in terms of another to remove the overlap warnings.
157
+
158
+ ### 12.8.3 Interpolated string expressions
159
+
160
+ ``` ANTLR
161
+ // [CHANGE] This allows the grammar to verify without warnings, it does NOT correctly
162
+ // [CHANGE] parse interpolated strings – that requires modes and/or lexical predicates.
163
+ // [CHANGE] Note: Interpolated strings are properly parsed in Base and other sets.
164
+ # Expect
165
+ Interpolated_Verbatim_String_End
166
+ : '"'
167
+ ;
168
+ # ReplaceWith
169
+ Interpolated_Verbatim_String_End
170
+ : Interpolated_Regular_String_End
177
171
;
178
172
```
0 commit comments