Skip to content

Commit 6685be0

Browse files
committed
Add 'required' keyword for properties + fields.
1 parent 8978fc3 commit 6685be0

File tree

7 files changed

+443209
-441838
lines changed

7 files changed

+443209
-441838
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Comprehensive supports C# 1 through 10.0 with the following exceptions:
5757
- [x] Newlines in string interpolations
5858
- [x] List patterns
5959
- [x] Slice pattern
60+
- [x] Required members
6061
- [ ] Raw string literals
6162

6263
### References

corpus/type-fields.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class A {
242242
(variable_declarator (identifier)))))))
243243

244244
=======================================
245-
Native interger types
245+
Native integer types
246246
=======================================
247247

248248
class A {
@@ -264,3 +264,26 @@ class A {
264264
(variable_declaration
265265
(predefined_type)
266266
(variable_declarator (identifier)))))))
267+
268+
269+
=======================================
270+
Required fields
271+
=======================================
272+
273+
class A {
274+
public required int B;
275+
}
276+
277+
---
278+
279+
(compilation_unit
280+
(class_declaration
281+
(identifier)
282+
(declaration_list
283+
(field_declaration
284+
(modifier)
285+
(modifier)
286+
(variable_declaration
287+
(predefined_type)
288+
(variable_declarator
289+
(identifier)))))))

corpus/type-properties.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,27 @@ class Foo: IFoo {
194194
(explicit_interface_specifier (identifier))
195195
(identifier)
196196
(accessor_list (accessor_declaration))))))
197+
198+
199+
=======================================
200+
Required properties
201+
=======================================
202+
203+
class A {
204+
public required int B { get; set; }
205+
}
206+
207+
---
208+
209+
(compilation_unit
210+
(class_declaration
211+
(identifier)
212+
(declaration_list
213+
(property_declaration
214+
(modifier)
215+
(modifier)
216+
(predefined_type)
217+
(identifier)
218+
(accessor_list
219+
(accessor_declaration)
220+
(accessor_declaration))))))

grammar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ module.exports = grammar({
259259
'protected',
260260
'public',
261261
'readonly',
262+
'required',
262263
prec(1, 'ref'), //make sure that 'ref' is treated as a modifier for local variable declarations instead of as a ref expression
263264
'sealed',
264265
'static',
@@ -935,7 +936,7 @@ module.exports = grammar({
935936

936937
list_pattern: $ => seq(
937938
'[',
938-
optional(seq(commaSep(choice($._pattern, $.slice_pattern)), optional(','))),
939+
optional(seq(commaSep1(choice($._pattern, $.slice_pattern)), optional(','))),
939940
']'
940941
),
941942

0 commit comments

Comments
 (0)