Skip to content

Commit

Permalink
Lambda attributes + record trailing semicolons (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
damieng authored Sep 1, 2022
1 parent ad8e698 commit 7bfc87d
Show file tree
Hide file tree
Showing 6 changed files with 487,750 additions and 405,607 deletions.
30 changes: 29 additions & 1 deletion corpus/attributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,32 @@ void A() { }
(void_keyword)
(identifier)
(parameter_list)
(block))))
(block))))

=======================================
Lambda with attribute
=======================================

var greeting = [Hello] () => Console.WriteLine("hello");

---

(compilation_unit
(global_statement
(local_declaration_statement
(variable_declaration
(implicit_type)
(variable_declarator
(identifier)
(equals_value_clause
(lambda_expression
(attribute_list (attribute (identifier)))
(parameter_list)
(invocation_expression
(member_access_expression
(identifier)
(identifier))
(argument_list
(argument
(string_literal)))))))))))

22 changes: 21 additions & 1 deletion corpus/records.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,31 @@ record Teacher(string FirstName, string LastName, string Subject) : Person(First
(identifier)
(identifier))))

=====================================
Record types can end with a semicolon
=====================================

public record Person { };

public record struct Person2 { };

---

(compilation_unit
(record_declaration
(modifier)
(identifier)
(declaration_list))
(record_struct_declaration
(modifier)
(identifier)
(declaration_list)))

=====================================
Record types can seal ToString()
=====================================

record A{
record A {
public sealed override string ToString(){
return "";
}
Expand Down
3 changes: 3 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ module.exports = grammar({
field('bases', optional(alias($.record_base, $.base_list))),
repeat($.type_parameter_constraints_clause),
field('body', $._record_body),
optional(';')
),

record_struct_declaration: $ => seq(
Expand All @@ -617,6 +618,7 @@ module.exports = grammar({
field('bases', optional(alias($.record_base, $.base_list))),
repeat($.type_parameter_constraints_clause),
field('body', $._record_body),
optional(';')
),

record_base: $ => choice(
Expand Down Expand Up @@ -1087,6 +1089,7 @@ module.exports = grammar({
),

lambda_expression: $ => prec(-1, seq(
repeat($.attribute_list),
optional(alias(choice('async', 'static', seq('async', 'static'), seq('static', 'async')), $.modifier)),
choice(field('parameters', $.parameter_list), $.identifier),
'=>',
Expand Down
Loading

0 comments on commit 7bfc87d

Please sign in to comment.