From d9c7f6c500178f8eeb4b10040f73fb701c391194 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 14 Jan 2021 17:06:12 -0500 Subject: [PATCH 1/8] generate ANTLR file Rework the bat file to generate an ANTLR file, and update the grammar in the standard. Note that this does pick up a couple PRs that affected the grammar. --- standard/grammar.md | 25 +- tools/GetGrammar/GetGrammar.bat | 108 +- tools/GetGrammar/GetGrammar.csproj | 3 +- tools/GetGrammar/Program.cs | 74 +- tools/GetGrammar/grammar.antlr | 2112 ++++++++++++++++++++++++++++ 5 files changed, 2246 insertions(+), 76 deletions(-) create mode 100644 tools/GetGrammar/grammar.antlr diff --git a/standard/grammar.md b/standard/grammar.md index 41868ff1c..217b50c0b 100644 --- a/standard/grammar.md +++ b/standard/grammar.md @@ -1242,30 +1242,17 @@ throw_statement ; try_statement - : 'try' block catch_clauses - | 'try' block catch_clauses? finally_clause + : 'try' block catch_clause+ + | 'try' block finally_clause + | 'try' block catch_clause+ finally_clause ; catch_clauses - : specific_catch_clauses - | specific_catch_clauses? general_catch_clause + : 'catch' exception_specifier? block ; -specific_catch_clauses - : specific_catch_clause - | specific_catch_clauses specific_catch_clause - ; - -specific_catch_clause - : 'catch' '(' type identifier? ')' block - ; - -general_catch_clause - : 'catch' block - ; - -finally_clause - : 'finally' block +exception_specifier + : '(' type identifier? ')' ; checked_statement diff --git a/tools/GetGrammar/GetGrammar.bat b/tools/GetGrammar/GetGrammar.bat index b678fbdbb..06386b3a4 100644 --- a/tools/GetGrammar/GetGrammar.bat +++ b/tools/GetGrammar/GetGrammar.bat @@ -1,33 +1,103 @@ echo off -dotnet build -dotnet publish +dotnet build -c Release +dotnet publish -o publish +del grammar.antlr del ..\..\standard\grammar.md echo Insert General/Lexical Headers type grammar-general-lexical-insert.md >..\..\standard\grammar.md echo Extract Lexical Grammar -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\lexical-structure.md >>..\..\standard\grammar.md +publish\GetGrammar <..\..\standard\lexical-structure.md >lexical-structure.antlr +type lexical-structure.antlr >grammar.antlr +type lexical-structure.antlr >>..\..\standard\grammar.md +del lexical-structure.antlr + echo Insert Syntactic Header type grammar-syntactic-insert.md >>..\..\standard\grammar.md echo Extract Syntactic Grammar -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\basic-concepts.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\types.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\variables.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\conversions.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\expressions.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\statements.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\namespaces.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\classes.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\structs.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\arrays.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\interfaces.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\enums.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\delegates.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\exceptions.md >>..\..\standard\grammar.md -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\attributes.md >>..\..\standard\grammar.md + +publish\GetGrammar <..\..\standard\basic-concepts.md >basic-concepts.antlr +type basic-concepts.antlr >>grammar.antlr +type basic-concepts.antlr >>..\..\standard\grammar.md +del basic-concepts.antlr + +publish\GetGrammar <..\..\standard\types.md >types.antlr +type types.antlr >>grammar.antlr +type types.antlr >>..\..\standard\grammar.md +del types.antlr + +publish\GetGrammar <..\..\standard\variables.md >variables.antlr +type variables.antlr >>grammar.antlr +type variables.antlr >>..\..\standard\grammar.md +del variables.antlr + +publish\GetGrammar <..\..\standard\conversions.md >conversions.antlr +type conversions.antlr >>grammar.antlr +type conversions.antlr >>..\..\standard\grammar.md +del conversions.antlr + +publish\GetGrammar <..\..\standard\expressions.md >expressions.antlr +type expressions.antlr >>grammar.antlr +type expressions.antlr >>..\..\standard\grammar.md +del expressions.antlr + +publish\GetGrammar <..\..\standard\statements.md >statements.antlr +type statements.antlr >>grammar.antlr +type statements.antlr >>..\..\standard\grammar.md +del statements.antlr + +publish\GetGrammar <..\..\standard\namespaces.md >namespaces.antlr +type namespaces.antlr >>grammar.antlr +type namespaces.antlr >>..\..\standard\grammar.md +del namespaces.antlr + +publish\GetGrammar <..\..\standard\classes.md >classes.antlr +type classes.antlr >>grammar.antlr +type classes.antlr >>..\..\standard\grammar.md +del classes.antlr + +publish\GetGrammar <..\..\standard\structs.md >structs.antlr +type structs.antlr >>grammar.antlr +type structs.antlr >>..\..\standard\grammar.md +del structs.antlr + +publish\GetGrammar <..\..\standard\arrays.md >arrays.antlr +type arrays.antlr >>grammar.antlr +type arrays.antlr >>..\..\standard\grammar.md +del arrays.antlr + +publish\GetGrammar <..\..\standard\interfaces.md >interfaces.antlr +type interfaces.antlr >>grammar.antlr +type interfaces.antlr >>..\..\standard\grammar.md +del interfaces.antlr + +publish\GetGrammar <..\..\standard\enums.md >enums.antlr +type enums.antlr >>grammar.antlr +type enums.antlr >>..\..\standard\grammar.md +del enums.antlr + +publish\GetGrammar <..\..\standard\delegates.md >delegates.antlr +type delegates.antlr >>grammar.antlr +type delegates.antlr >>..\..\standard\grammar.md +del delegates.antlr + +publish\GetGrammar <..\..\standard\exceptions.md >exceptions.antlr +type exceptions.antlr >>grammar.antlr +type exceptions.antlr >>..\..\standard\grammar.md +del exceptions.antlr + +publish\GetGrammar <..\..\standard\attributes.md >attributes.antlr +type attributes.antlr >>grammar.antlr +type attributes.antlr >>..\..\standard\grammar.md +del attributes.antlr + echo Insert Unsafe Header type grammar-unsafe-extensions-insert.md >>..\..\standard\grammar.md echo Extract Unsafe Grammar -bin\Debug\netcoreapp3.1\publish\GetGrammar <..\..\standard\unsafe-code.md >>..\..\standard\grammar.md +publish\GetGrammar <..\..\standard\unsafe-code.md >unsafe-code.antlr +type unsafe-code.antlr >>grammar.antlr +type unsafe-code.antlr >>..\..\standard\grammar.md +del unsafe-code.antlr + echo Insert EOF Stuff type grammar-eof-insert.md >>..\..\standard\grammar.md diff --git a/tools/GetGrammar/GetGrammar.csproj b/tools/GetGrammar/GetGrammar.csproj index c73e0d169..d75be9161 100644 --- a/tools/GetGrammar/GetGrammar.csproj +++ b/tools/GetGrammar/GetGrammar.csproj @@ -2,7 +2,8 @@ Exe - netcoreapp3.1 + net5.0 + enable diff --git a/tools/GetGrammar/Program.cs b/tools/GetGrammar/Program.cs index cd5e77447..c5b567a9a 100644 --- a/tools/GetGrammar/Program.cs +++ b/tools/GetGrammar/Program.cs @@ -29,48 +29,48 @@ namespace ExtractGrammar { class Program { - public static void Main() - { - string inputLine; + public static void Main() + { + string? inputLine; - while ((inputLine = Console.ReadLine()) != null) - { - if (inputLine.Length < 8) // Is it long enough to contain an opening fence? + while ((inputLine = Console.ReadLine()) != null) + { + if (inputLine.Length < 8) // Is it long enough to contain an opening fence? { - continue; + continue; } - string leader = inputLine.Substring(0, 8); // grab what might be an opening fence -// Console.WriteLine(">" + leader + "<"); - if (leader != "```ANTLR" && leader != "```antlr") - { - continue; + string leader = inputLine.Substring(0, 8); // grab what might be an opening fence + // Console.WriteLine(">" + leader + "<"); + if (leader != "```ANTLR" && leader != "```antlr") + { + continue; } -// Console.WriteLine("------ Start of a production"); - Console.WriteLine(); // write out blank line before each new production + // Console.WriteLine("------ Start of a production"); + Console.WriteLine(); // write out blank line before each new production - while (true) - { - inputLine = Console.ReadLine(); - if (inputLine == null) - { - Console.WriteLine("Unexpected EOF; no closing grammar fence"); - Environment.Exit(1); - } - if (inputLine.Length < 3) // Is it long enough to contain a closing fence? - { - Console.WriteLine(inputLine); - } - else if (inputLine.Substring(0, 3) == "```") // If line starts with ``` - { -// Console.WriteLine("------ End of a production"); - break; - } - else + while (true) + { + inputLine = Console.ReadLine(); + if (inputLine == null) + { + Console.WriteLine("Unexpected EOF; no closing grammar fence"); + Environment.Exit(1); + } + if (inputLine.Length < 3) // Is it long enough to contain a closing fence? { - Console.WriteLine(inputLine); - } - } - } - } + Console.WriteLine(inputLine); + } + else if (inputLine.Substring(0, 3) == "```") // If line starts with ``` + { + // Console.WriteLine("------ End of a production"); + break; + } + else + { + Console.WriteLine(inputLine); + } + } + } + } } } diff --git a/tools/GetGrammar/grammar.antlr b/tools/GetGrammar/grammar.antlr new file mode 100644 index 000000000..6d5e205cf --- /dev/null +++ b/tools/GetGrammar/grammar.antlr @@ -0,0 +1,2112 @@ + +input + : input_section? + ; + +input_section + : input_section_part+ + ; + +input_section_part + : input_element* new_line + | pp_directive + ; + +input_element + : whitespace + | comment + | token + ; + +new_line + : '' + | '' + | '' + | '' + | '' + | '' + ; + +comment + : single_line_comment + | delimited_comment + ; + +single_line_comment + : '//' input_character* + ; + +input_character + : '' + ; + +new_line_character + : '' + | '' + | '' + | '' + | '' + ; + +delimited_comment + : '/*' delimited_comment_section* asterisk+ '/' + ; + +delimited_comment_section + : '/' + | asterisk* not_slash_or_asterisk + ; + +asterisk + : '*' + ; + +not_slash_or_asterisk + : '' + ; + +whitespace + : '' + | '' + | '' + | '
' + ; + +token + : identifier + | keyword + | integer_literal + | real_literal + | character_literal + | string_literal + | operator_or_punctuator + ; + +unicode_escape_sequence + : '\\u' hex_digit hex_digit hex_digit hex_digit + | '\\U' hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit + ; + +identifier + : available_identifier + | '@' identifier_or_keyword + ; + +available_identifier + : '' + ; + +identifier_or_keyword + : identifier_start_character identifier_part_character* + ; + +identifier_start_character + : letter_character + | underscore_character + ; + +underscore_character + : '<_ the underscore character (U+005F)>' + | '' + ; + +identifier_part_character + : letter_character + | decimal_digit_character + | connecting_character + | combining_character + | formatting_character + ; + +letter_character + : '' + | '' + ; + +combining_character + : '' + | '' + ; + +decimal_digit_character + : '' + | '' + ; + +connecting_character + : '' + | '' + ; + +formatting_character + : '' + | '' + ; + +keyword + : 'abstract' | 'as' | 'base' | 'bool' | 'break' + | 'byte' | 'case' | 'catch' | 'char' | 'checked' + | 'class' | 'const' | 'continue' | 'decimal' | 'default' + | 'delegate' | 'do' | 'double' | 'else' | 'enum' + | 'event' | 'explicit' | 'extern' | 'false' | 'finally' + | 'fixed' | 'float' | 'for' | 'foreach' | 'goto' + | 'if' | 'implicit' | 'in' | 'int' | 'interface' + | 'internal' | 'is' | 'lock' | 'long' | 'namespace' + | 'new' | 'null' | 'object' | 'operator' | 'out' + | 'override' | 'params' | 'private' | 'protected' | 'public' + | 'readonly' | 'ref' | 'return' | 'sbyte' | 'sealed' + | 'short' | 'sizeof' | 'stackalloc' | 'static' | 'string' + | 'struct' | 'switch' | 'this' | 'throw' | 'true' + | 'try' | 'typeof' | 'uint' | 'ulong' | 'unchecked' + | 'unsafe' | 'ushort' | 'using' | 'virtual' | 'void' + | 'volatile' | 'while' + ; + +contextual_keyword + : 'add' 'alias' 'ascending' 'async' 'await' + | 'by' 'descending' 'dynamic' 'equals' 'from' + | 'get' 'global' 'group' 'into' 'join' + | 'let' 'orderby' 'partial' 'remove' 'select' + | 'set' 'value' 'var' 'where' 'yield' + ; + +literal + : boolean_literal + | integer_literal + | real_literal + | character_literal + | string_literal + | null_literal + ; + +boolean_literal + : 'true' + | 'false' + ; + +integer_literal + : decimal_integer_literal + | hexadecimal_integer_literal + ; + +decimal_integer_literal + : decimal_digit+ integer_type_suffix? + ; + +decimal_digit + : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' + ; + +integer_type_suffix + : 'U' | 'u' | 'L' | 'l' | 'UL' | 'Ul' | 'uL' | 'ul' | 'LU' | 'Lu' | 'lU' | 'lu' + ; + +hexadecimal_integer_literal + : '0x' hex_digit+ integer_type_suffix? + | '0X' hex_digit+ integer_type_suffix? + ; + +hex_digit + : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' + | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'; + +real_literal + : decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? + | '.' decimal_digit+ exponent_part? real_type_suffix? + | decimal_digit+ exponent_part real_type_suffix? + | decimal_digit+ real_type_suffix + ; + +exponent_part + : 'e' sign? decimal_digit+ + | 'E' sign? decimal_digit+ + ; + +sign + : '+' | '-' + ; + +real_type_suffix + : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' + ; + +character_literal + : '\'' character '\'' + ; + +character + : single_character + | simple_escape_sequence + | hexadecimal_escape_sequence + | unicode_escape_sequence + ; + +single_character + : '' + ; + +simple_escape_sequence + : '\\\'' | '\\"' | '\\\\' | '\\0' | '\\a' | '\\b' | '\\f' | '\\n' | '\\r' | '\\t' | '\\v' + ; + +hexadecimal_escape_sequence + : '\\x' hex_digit hex_digit? hex_digit? hex_digit? + ; + +string_literal + : regular_string_literal + | verbatim_string_literal + ; + +regular_string_literal + : '"' regular_string_literal_character* '"' + ; + +regular_string_literal_character + : single_regular_string_literal_character + | simple_escape_sequence + | hexadecimal_escape_sequence + | unicode_escape_sequence + ; + +single_regular_string_literal_character + : '' + ; + +verbatim_string_literal + : '@"' verbatim_string_literal_character* '"' + ; + +verbatim_string_literal_character + : single_verbatim_string_literal_character + | quote_escape_sequence + ; + +single_verbatim_string_literal_character + : '' + ; + +quote_escape_sequence + : '""' + ; + +null_literal + : 'null' + ; + +operator_or_punctuator + : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' + | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' + | '=' | '<' | '>' | '?' | '??' | '::' | '++' | '--' | '&&' | '||' + | '->' | '==' | '!=' | '<=' | '>=' | '+=' | '-=' | '*=' | '/=' | '%=' + | '&=' | '|=' | '^=' | '<<' | '<<=' | '=>' + ; + +right_shift + : '>' '>' + ; + +right_shift_assignment + : '>' '>=' + ; + +pp_directive + : pp_declaration + | pp_conditional + | pp_line + | pp_diagnostic + | pp_region + | pp_pragma + ; + +conditional_symbol + : '' + ; + +pp_expression + : whitespace? pp_or_expression whitespace? + ; + +pp_or_expression + : pp_and_expression + | pp_or_expression whitespace? '||' whitespace? pp_and_expression + ; + +pp_and_expression + : pp_equality_expression + | pp_and_expression whitespace? '&&' whitespace? pp_equality_expression + ; + +pp_equality_expression + : pp_unary_expression + | pp_equality_expression whitespace? '==' whitespace? pp_unary_expression + | pp_equality_expression whitespace? '!=' whitespace? pp_unary_expression + ; + +pp_unary_expression + : pp_primary_expression + | '!' whitespace? pp_unary_expression + ; + +pp_primary_expression + : 'true' + | 'false' + | conditional_symbol + | '(' whitespace? pp_expression whitespace? ')' + ; + +pp_declaration + : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line + | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line + ; + +pp_new_line + : whitespace? single_line_comment? new_line + ; + +pp_conditional + : pp_if_section pp_elif_section* pp_else_section? pp_endif + ; + +pp_if_section + : whitespace? '#' whitespace? 'if' whitespace pp_expression pp_new_line conditional_section? + ; + +pp_elif_section + : whitespace? '#' whitespace? 'elif' whitespace pp_expression pp_new_line conditional_section? + ; + +pp_else_section + : whitespace? '#' whitespace? 'else' pp_new_line conditional_section? + ; + +pp_endif + : whitespace? '#' whitespace? 'endif' pp_new_line + ; + +conditional_section + : input_section + | skipped_section_part+ + ; + +skipped_section_part + : skipped_characters? new_line + | pp_directive + ; + +skipped_characters + : whitespace? not_number_sign input_character* + ; + +not_number_sign + : '' + ; + +pp_diagnostic + : whitespace? '#' whitespace? 'error' pp_message + | whitespace? '#' whitespace? 'warning' pp_message + ; + +pp_message + : new_line + | whitespace input_character* new_line + ; + +pp_region + : pp_start_region conditional_section? pp_end_region + ; + +pp_start_region + : whitespace? '#' whitespace? 'region' pp_message + ; + +pp_end_region + : whitespace? '#' whitespace? 'endregion' pp_message + ; + +pp_line + : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line + ; + +line_indicator + : decimal_digit+ whitespace compilation_unit_name + | decimal_digit+ + | 'default' + | 'hidden' + ; + +compilation_unit_name + : '"' compilation_unit_name_character+ '"' + ; + +compilation_unit_name_character + : '' + ; + +pp_pragma + : whitespace? '#' whitespace? 'pragma' pp_pragma_text + ; + +pp_pragma_text + : new_line + | whitespace input_character* new_line + ; + +namespace_name + : namespace_or_type_name + ; + +type_name + : namespace_or_type_name + ; + +namespace_or_type_name + : identifier type_argument_list? + | namespace_or_type_name '.' identifier type_argument_list? + | qualified_alias_member + ; + +type + : reference_type + | value_type + | type_parameter + ; + +reference_type + : class_type + | interface_type + | array_type + | delegate_type + | 'dynamic' + ; + +class_type + : type_name + | 'object' + | 'string' + ; + +interface_type + : type_name + ; + +array_type + : non_array_type rank_specifier+ + ; + +non_array_type + : value_type + | class_type + | interface_type + | delegate_type + | 'dynamic' + | type_parameter + ; + +rank_specifier + : '[' ','* ']' + ; + +delegate_type + : type_name + ; + +value_type + : struct_type + | enum_type + ; + +struct_type + : type_name + | simple_type + | nullable_value_type + ; + +simple_type + : numeric_type + | 'bool' + ; + +numeric_type + : integral_type + | floating_point_type + | 'decimal' + ; + +integral_type + : 'sbyte' + | 'byte' + | 'short' + | 'ushort' + | 'int' + | 'uint' + | 'long' + | 'ulong' + | 'char' + ; + +floating_point_type + : 'float' + | 'double' + ; + +nullable_value_type + : non_nullable_value_type '?' + ; + +non_nullable_value_type + : type + ; + +enum_type + : type_name + ; + +type_argument_list + : '<' type_arguments '>' + ; + +type_arguments + : type_argument (',' type_argument)* + ; + +type_argument + : type + ; + +type_parameter + : identifier + ; + +variable_reference + : expression + ; + +argument_list + : argument (',' argument)* + ; + +argument + : argument_name? argument_value + ; + +argument_name + : identifier ':' + ; + +argument_value + : expression + | 'ref' variable_reference + | 'out' variable_reference + ; + +primary_expression + : primary_no_array_creation_expression + | array_creation_expression + ; + +primary_no_array_creation_expression + : literal + | simple_name + | parenthesized_expression + | member_access + | invocation_expression + | element_access + | this_access + | base_access + | post_increment_expression + | post_decrement_expression + | object_creation_expression + | delegate_creation_expression + | anonymous_object_creation_expression + | typeof_expression + | sizeof_expression + | checked_expression + | unchecked_expression + | default_value_expression + | anonymous_method_expression + ; + +simple_name + : identifier type_argument_list? + ; + +parenthesized_expression + : '(' expression ')' + ; + +member_access + : primary_expression '.' identifier type_argument_list? + | predefined_type '.' identifier type_argument_list? + | qualified_alias_member '.' identifier type_argument_list? + ; + +predefined_type + : 'bool' | 'byte' | 'char' | 'decimal' | 'double' | 'float' | 'int' | 'long' + | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' + ; + +invocation_expression + : primary_expression '(' argument_list? ')' + ; + +element_access + : primary_no_array_creation_expression '[' argument_list ']' + ; + +this_access + : 'this' + ; + +base_access + : 'base' '.' identifier type_argument_list? + | 'base' '[' argument_list ']' + ; + +post_increment_expression + : primary_expression '++' + ; + +post_decrement_expression + : primary_expression '--' + ; + +object_creation_expression + : 'new' type '(' argument_list? ')' object_or_collection_initializer? + | 'new' type object_or_collection_initializer + ; + +object_or_collection_initializer + : object_initializer + | collection_initializer + ; + +object_initializer + : '{' member_initializer_list? '}' + | '{' member_initializer_list ',' '}' + ; + +member_initializer_list + : member_initializer (',' member_initializer)* + ; + +member_initializer + : identifier '=' initializer_value + ; + +initializer_value + : expression + | object_or_collection_initializer + ; + +collection_initializer + : '{' element_initializer_list '}' + | '{' element_initializer_list ',' '}' + ; + +element_initializer_list + : element_initializer (',' element_initializer)* + ; + +element_initializer + : non_assignment_expression + | '{' expression_list '}' + ; + +expression_list + : expression + | expression_list ',' expression + ; + +array_creation_expression + : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? + | 'new' array_type array_initializer + | 'new' rank_specifier array_initializer + ; + +delegate_creation_expression + : 'new' delegate_type '(' expression ')' + ; + +anonymous_object_creation_expression + : 'new' anonymous_object_initializer + ; + +anonymous_object_initializer + : '{' member_declarator_list? '}' + | '{' member_declarator_list ',' '}' + ; + +member_declarator_list + : member_declarator (',' member_declarator)* + ; + +member_declarator + : simple_name + | member_access + | base_access + | identifier '=' expression + ; + +typeof_expression + : 'typeof' '(' type ')' + | 'typeof' '(' unbound_type_name ')' + | 'typeof' '(' 'void' ')' + ; + +unbound_type_name + : identifier generic_dimension_specifier? + | identifier '::' identifier generic_dimension_specifier? + | unbound_type_name '.' identifier generic_dimension_specifier? + ; + +generic_dimension_specifier + : '<' comma* '>' + ; + +comma + : ',' + ; + + +sizeof_expression + : 'sizeof' '(' unmanaged_type ')' + ; + +checked_expression + : 'checked' '(' expression ')' + ; + +unchecked_expression + : 'unchecked' '(' expression ')' + ; + +default_value_expression + : 'default' '(' type ')' + ; + +unary_expression + : primary_expression + | '+' unary_expression + | '-' unary_expression + | '!' unary_expression + | '~' unary_expression + | pre_increment_expression + | pre_decrement_expression + | cast_expression + | await_expression + ; + +pre_increment_expression + : '++' unary_expression + ; + +pre_decrement_expression + : '--' unary_expression + ; + +cast_expression + : '(' type ')' unary_expression + ; + +await_expression + : 'await' unary_expression + ; + +multiplicative_expression + : unary_expression + | multiplicative_expression '*' unary_expression + | multiplicative_expression '/' unary_expression + | multiplicative_expression '%' unary_expression + ; + +additive_expression + : multiplicative_expression + | additive_expression '+' multiplicative_expression + | additive_expression '-' multiplicative_expression + ; + +shift_expression + : additive_expression + | shift_expression '<<' additive_expression + | shift_expression right_shift additive_expression + ; + +relational_expression + : shift_expression + | relational_expression '<' shift_expression + | relational_expression '>' shift_expression + | relational_expression '<=' shift_expression + | relational_expression '>=' shift_expression + | relational_expression 'is' type + | relational_expression 'as' type + ; + +equality_expression + : relational_expression + | equality_expression '==' relational_expression + | equality_expression '!=' relational_expression + ; + +and_expression + : equality_expression + | and_expression '&' equality_expression + ; + +exclusive_or_expression + : and_expression + | exclusive_or_expression '^' and_expression + ; + +inclusive_or_expression + : exclusive_or_expression + | inclusive_or_expression '|' exclusive_or_expression + ; + +conditional_and_expression + : inclusive_or_expression + | conditional_and_expression '&&' inclusive_or_expression + ; + +conditional_or_expression + : conditional_and_expression + | conditional_or_expression '||' conditional_and_expression + ; + +null_coalescing_expression + : conditional_or_expression + | conditional_or_expression '??' null_coalescing_expression + ; + +conditional_expression + : null_coalescing_expression + | null_coalescing_expression '?' expression ':' expression + ; + +lambda_expression + : 'async'? anonymous_function_signature '=>' anonymous_function_body + ; + +anonymous_method_expression + : 'async'? 'delegate' explicit_anonymous_function_signature? block + ; + +anonymous_function_signature + : explicit_anonymous_function_signature + | implicit_anonymous_function_signature + ; + +explicit_anonymous_function_signature + : '(' explicit_anonymous_function_parameter_list? ')' + ; + +explicit_anonymous_function_parameter_list + : explicit_anonymous_function_parameter (',' explicit_anonymous_function_parameter)* + ; + +explicit_anonymous_function_parameter + : anonymous_function_parameter_modifier? type identifier + ; + +anonymous_function_parameter_modifier + : 'ref' + | 'out' + ; + +implicit_anonymous_function_signature + : '(' implicit_anonymous_function_parameter_list? ')' + | implicit_anonymous_function_parameter + ; + +implicit_anonymous_function_parameter_list + : implicit_anonymous_function_parameter (',' implicit_anonymous_function_parameter)* + ; + +implicit_anonymous_function_parameter + : identifier + ; + +anonymous_function_body + : expression + | block + ; + +query_expression + : from_clause query_body + ; + +from_clause + : 'from' type? identifier 'in' expression + ; + +query_body + : query_body_clauses? select_or_group_clause query_continuation? + ; + +query_body_clauses + : query_body_clause + | query_body_clauses query_body_clause + ; + +query_body_clause + : from_clause + | let_clause + | where_clause + | join_clause + | join_into_clause + | orderby_clause + ; + +let_clause + : 'let' identifier '=' expression + ; + +where_clause + : 'where' boolean_expression + ; + +join_clause + : 'join' type? identifier 'in' expression 'on' expression 'equals' expression + ; + +join_into_clause + : 'join' type? identifier 'in' expression 'on' expression 'equals' expression 'into' identifier + ; + +orderby_clause + : 'orderby' orderings + ; + +orderings + : ordering (',' ordering)* + ; + +ordering + : expression ordering_direction? + ; + +ordering_direction + : 'ascending' + | 'descending' + ; + +select_or_group_clause + : select_clause + | group_clause + ; + +select_clause + : 'select' expression + ; + +group_clause + : 'group' expression 'by' expression + ; + +query_continuation + : 'into' identifier query_body + ; + +assignment + : unary_expression assignment_operator expression + ; + +assignment_operator + : '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' + | right_shift_assignment + ; + +expression + : non_assignment_expression + | assignment + ; + +non_assignment_expression + : conditional_expression + | lambda_expression + | query_expression + ; + +constant_expression + : expression + ; + +boolean_expression + : expression + ; + +statement + : labeled_statement + | declaration_statement + | embedded_statement + ; + +embedded_statement + : block + | empty_statement + | expression_statement + | selection_statement + | iteration_statement + | jump_statement + | try_statement + | checked_statement + | unchecked_statement + | lock_statement + | using_statement + | yield_statement + ; + +block + : '{' statement_list? '}' + ; + +statement_list + : statement+ + ; + +empty_statement + : ';' + ; + +labeled_statement + : identifier ':' statement + ; + +declaration_statement + : local_variable_declaration ';' + | local_constant_declaration ';' + ; + +local_variable_declaration + : local_variable_type local_variable_declarators + ; + +local_variable_type + : type + | 'var' + ; + +local_variable_declarators + : local_variable_declarator + | local_variable_declarators ',' local_variable_declarator + ; + +local_variable_declarator + : identifier + | identifier '=' local_variable_initializer + ; + +local_variable_initializer + : expression + | array_initializer + ; + +local_constant_declaration + : 'const' type constant_declarators + ; + +constant_declarators + : constant_declarator (',' constant_declarator)* + ; + +constant_declarator + : identifier '=' constant_expression + ; + +expression_statement + : statement_expression ';' + ; + +statement_expression + : invocation_expression + | object_creation_expression + | assignment + | post_increment_expression + | post_decrement_expression + | pre_increment_expression + | pre_decrement_expression + | await_expression + ; + +selection_statement + : if_statement + | switch_statement + ; + +if_statement + : 'if' '(' boolean_expression ')' embedded_statement + | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement + ; + +switch_statement + : 'switch' '(' expression ')' switch_block + ; + +switch_block + : '{' switch_section* '}' + ; + +switch_section + : switch_label+ statement_list + ; + +switch_label + : 'case' constant_expression ':' + | 'default' ':' + ; + +iteration_statement + : while_statement + | do_statement + | for_statement + | foreach_statement + ; + +while_statement + : 'while' '(' boolean_expression ')' embedded_statement + ; + +do_statement + : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' + ; + +for_statement + : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement + ; + +for_initializer + : local_variable_declaration + | statement_expression_list + ; + +for_condition + : boolean_expression + ; + +for_iterator + : statement_expression_list + ; + +statement_expression_list + : statement_expression (',' statement_expression)* + ; + +foreach_statement + : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement + ; + +jump_statement + : break_statement + | continue_statement + | goto_statement + | return_statement + | throw_statement + ; + +break_statement + : 'break' ';' + ; + +continue_statement + : 'continue' ';' + ; + +goto_statement + : 'goto' identifier ';' + | 'goto' 'case' constant_expression ';' + | 'goto' 'default' ';' + ; + +return_statement + : 'return' expression? ';' + ; + +throw_statement + : 'throw' expression? ';' + ; + +try_statement + : 'try' block catch_clause+ + | 'try' block finally_clause + | 'try' block catch_clause+ finally_clause + ; + +catch_clauses + : 'catch' exception_specifier? block + ; + +exception_specifier + : '(' type identifier? ')' + ; + +checked_statement + : 'checked' block + ; + +unchecked_statement + : 'unchecked' block + ; + +lock_statement + : 'lock' '(' expression ')' embedded_statement + ; + +using_statement + : 'using' '(' resource_acquisition ')' embedded_statement + ; + +resource_acquisition + : local_variable_declaration + | expression + ; + +yield_statement + : 'yield' 'return' expression ';' + | 'yield' 'break' ';' + ; + +compilation_unit + : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* + ; + +namespace_declaration + : 'namespace' qualified_identifier namespace_body ';'? + ; + +qualified_identifier + : identifier ('.' identifier)* + ; + +namespace_body + : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' + ; + +extern_alias_directive + : 'extern' 'alias' identifier ';' + ; + +using_directive + : using_alias-directive + | using_namespace-directive + ; + +using_alias_directive + : 'using' identifier '=' namespace_or_type_name ';' + ; + +using_namespace_directive + : 'using' namespace_name ';' + ; + +namespace_member_declaration + : namespace_declaration + | type_declaration + ; + +type_declaration + : class_declaration + | struct_declaration + | interface_declaration + | enum_declaration + | delegate_declaration + ; + +qualified_alias_member + : identifier '::' identifier type_argument_list? + ; + +class_declaration + : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? + class_base? type_parameter_constraints_clause* class_body ';'? + ; + +class_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'abstract' + | 'sealed' + | 'static' + ; + +type_parameter_list + : '<' type_parameters '>' + ; + +type_parameters + : attributes? type_parameter + | type_parameters ',' attributes? type_parameter + ; + +class_base + : ':' class_type + | ':' interface_type_list + | ':' class_type ',' interface_type_list + ; + +interface_type_list + : interface_type (',' interface_type)* + ; + +type_parameter_constraints_clauses + : type_parameter_constraints_clause + | type_parameter_constraints_clauses type_parameter_constraints_clause + ; + +type_parameter_constraints_clause + : 'where' type_parameter ':' type_parameter_constraints + ; + +type_parameter_constraints + : primary_constraint + | secondary_constraints + | constructor_constraint + | primary_constraint ',' secondary_constraints + | primary_constraint ',' constructor_constraint + | secondary_constraints ',' constructor_constraint + | primary_constraint ',' secondary_constraints ',' constructor_constraint + ; + +primary_constraint + : class_type + | 'class' + | 'struct' + ; + +secondary_constraints + : interface_type + | type_parameter + | secondary_constraints ',' interface_type + | secondary_constraints ',' type_parameter + ; + +constructor_constraint + : 'new' '(' ')' + ; + +class_body + : '{' class_member_declaration* '}' + ; + +class_member_declaration + : constant_declaration + | field_declaration + | method_declaration + | property_declaration + | event_declaration + | indexer_declaration + | operator_declaration + | constructor_declaration + | finalizer_declaration + | static_constructor_declaration + | type_declaration + ; + +constant_declaration + : attributes? constant_modifier* 'const' type constant_declarators ';' + ; + +constant_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + ; + +field_declaration + : attributes? field_modifier* type variable_declarators ';' + ; + +field_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'static' + | 'readonly' + | 'volatile' + ; + +variable_declarators + : variable_declarator (',' variable_declarator)* + ; + +variable_declarator + : identifier ('=' variable_initializer)? + ; + +method_declaration + : method_header method_body + ; + +method_header + : attributes? method_modifier* 'partial'? return_type member_name type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* + ; + +method_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'static' + | 'virtual' + | 'sealed' + | 'override' + | 'abstract' + | 'extern' + | 'async' + ; + +return_type + : type + | 'void' + ; + +member_name + : identifier + | interface_type '.' identifier + ; + +method_body + : block + ; + +formal_parameter_list + : fixed_parameters + | fixed_parameters ',' parameter_array + | parameter_array + ; + +fixed_parameters + : fixed_parameter (',' fixed_parameter)* + ; + +fixed_parameter + : attributes? parameter_modifier? type identifier default_argument? + ; + +default_argument + : '=' expression + ; + +parameter_modifier + : parameter_mode_modifier + | 'this' + ; + +parameter_mode_modifier + : 'ref' + | 'out' + ; + +parameter_array + : attributes? 'params' array_type identifier + ; + +property_declaration + : attributes? property_modifiers? type member_name '{' accessor_declarations '}' + ; + +property_modifiers + : property_modifier + | property_modifiers property_modifier + ; + +property_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'static' + | 'virtual' + | 'sealed' + | 'override' + | 'abstract' + | 'extern' + ; + +accessor_declarations + : get_accessor_declaration set_accessor_declaration? + | set_accessor_declaration get_accessor_declaration? + ; + +get_accessor_declaration + : attributes? accessor_modifier? 'get' accessor_body + ; + +set_accessor_declaration + : attributes? accessor_modifier? 'set' accessor_body + ; + +accessor_modifier + : 'protected' + | 'internal' + | 'private' + | 'protected' 'internal' + | 'internal' 'protected' + ; + +accessor_body + : block + | ';' + ; + +event_declaration + : attributes? event_modifier* 'event' type variable_declarators ';' + | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' + ; + +event_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'static' + | 'virtual' + | 'sealed' + | 'override' + | 'abstract' + | 'extern' + ; + +event_accessor_declarations + : add_accessor_declaration remove_accessor_declaration + | remove_accessor_declaration add_accessor_declaration + ; + +add_accessor_declaration + : attributes? 'add' block + ; + +remove_accessor_declaration + : attributes? 'remove' block + ; + +indexer_declaration + : attributes? indexer_modifiers? indexer_declarator '{' accessor_declarations '}' + ; + +indexer_modifiers + : indexer_modifier + | indexer_modifiers indexer_modifier + ; + +indexer_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'virtual' + | 'sealed' + | 'override' + | 'abstract' + | 'extern' + ; + +indexer_declarator + : type 'this' '[' formal_parameter_list ']' + | type interface_type '.' 'this' '[' formal_parameter_list ']' + ; + +operator_declaration + : attributes? operator_modifier+ operator_declarator operator_body + ; + +operator_modifier + : 'public' + | 'static' + | 'extern' + ; + +operator_declarator + : unary_operator_declarator + | binary_operator_declarator + | conversion_operator_declarator + ; + +unary_operator_declarator + : type 'operator' overloadable_unary_operator '(' fixed_parameter ')' + ; + +overloadable_unary_operator + : '+' | '-' | '!' | '~' | '++' | '--' | 'true' | 'false' + ; + +binary_operator_declarator + : type 'operator' overloadable_binary_operator '(' fixed_parameter ',' fixed_parameter ')' + ; + +overloadable_binary_operator + : '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '<<' + | right_shift | '==' | '!=' | '>' | '<' | '>=' | '<=' + ; + +conversion_operator_declarator + : 'implicit' 'operator' type '(' fixed_parameter ')' + | 'explicit' 'operator' type '(' fixed_parameter ')' + ; + +operator_body + : block + | ';' + ; + +constructor_declaration + : attributes? constructor_modifier* constructor_declarator constructor_body + ; + +constructor_modifier + : 'public' + | 'protected' + | 'internal' + | 'private' + | 'extern' + ; + +constructor_declarator + : identifier '(' formal_parameter_list? ')' constructor_initializer? + ; + +constructor_initializer + : ':' 'base' '(' argument_list? ')' + | ':' 'this' '(' argument_list? ')' + ; + +constructor_body + : block + | ';' + ; + +static_constructor_declaration + : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body + ; + +static_constructor_modifiers + : 'extern'? 'static' + | 'static' 'extern'? + ; + +static_constructor_body + : block + | ';' + ; + +finalizer_declaration + : attributes? 'extern'? '~' identifier '(' ')' finalizer_body + ; + +finalizer_body + : block + | ';' + ; + +struct_declaration + : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? + struct_interfaces? type_parameter_constraints_clause* struct_body ';'? + ; + +struct_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + ; + +struct_interfaces + : ':' interface_type_list + ; + +struct_body + : '{' struct_member_declaration* '}' + ; + +struct_member_declaration + : constant_declaration + | field_declaration + | method_declaration + | property_declaration + | event_declaration + | indexer_declaration + | operator_declaration + | constructor_declaration + | static_constructor_declaration + | type_declaration + ; + +array_initializer + : '{' variable_initializer_list? '}' + | '{' variable_initializer_list ',' '}' + ; + +variable_initializer_list + : variable_initializer (',' variable_initializer)* + ; + +variable_initializer + : expression + | array_initializer + ; + +interface_declaration + : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? + ; + +interface_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + ; + +variant_type_parameter_list + : '<' variant_type_parameters '>' + ; + +variant_type_parameters + : attributes? variance_annotation? type_parameter + | variant_type_parameters ',' attributes? variance_annotation? type_parameter + ; + +variance_annotation + : 'in' + | 'out' + ; + +interface_base + : ':' interface_type_list + ; + +interface_body + : '{' interface_member_declaration* '}' + ; + +interface_member_declaration + : interface_method_declaration + | interface_property_declaration + | interface_event_declaration + | interface_indexer_declaration + ; + +interface_method_declaration + : attributes? 'new'? return_type identifier type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' + ; + +interface_property_declaration + : attributes? 'new'? type identifier '{' interface_accessors '}' + ; + +interface_accessors + : attributes? 'get' ';' + | attributes? 'set' ';' + | attributes? 'get' ';' attributes? 'set' ';' + | attributes? 'set' ';' attributes? 'get' ';' + ; + +interface_event_declaration + : attributes? 'new'? 'event' type identifier ';' + ; + +interface_indexer_declaration: + attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' + ; + +enum_declaration + : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? + ; + +enum_base + : ':' struct_type + ; + +enum_body + : '{' enum_member_declarations? '}' + | '{' enum_member_declarations ',' '}' + ; + +enum_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + ; + +enum_member_declarations + : enum_member_declaration (',' enum_member_declaration)* + ; + +enum_member_declaration + : attributes? identifier ('=' constant_expression)? + ; + +delegate_declaration + : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' + ; + +delegate_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + ; + +global_attributes + : global_attribute_section+ + ; + +global_attribute_section + : '[' global_attribute_target_specifier attribute_list ']' + | '[' global_attribute_target_specifier attribute_list ',' ']' + ; + +global_attribute_target_specifier + : global_attribute_target ':' + ; + +global_attribute_target + : identifier + ; + +attributes + : attribute_section+ + ; + +attribute_section + : '[' attribute_target_specifier? attribute_list ']' + | '[' attribute_target_specifier? attribute_list ',' ']' + ; + +attribute_target_specifier + : attribute_target ':' + ; + +attribute_target + : identifier + | keyword + ; + +attribute_list + : attribute (',' attribute)* + ; + +attribute + : attribute_name attribute_arguments? + ; + +attribute_name + : type_name + ; + +attribute_arguments + : '(' positional_argument_list? ')' + | '(' positional_argument_list ',' named_argument_list ')' + | '(' named_argument_list ')' + ; + +positional_argument_list + : positional_argument (',' positional_argument)* + ; + +positional_argument + : argument_name? attribute_argument_expression + ; + +named_argument_list + : named_argument (',' named_argument)* + ; + +named_argument + : identifier '=' attribute_argument_expression + ; + +attribute_argument_expression + : expression + ; + +class_modifier + : ... + | 'unsafe' + ; + +struct_modifier + : ... + | 'unsafe' + ; + +interface_modifier + : ... + | 'unsafe' + ; + +delegate_modifier + : ... + | 'unsafe' + ; + +field_modifier + : ... + | 'unsafe' + ; + +method_modifier + : ... + | 'unsafe' + ; + +property_modifier + : '...' + | 'unsafe' + ; + +event_modifier + : ... + | 'unsafe' + +indexer_modifier + : ... + | 'unsafe' + ; + +operator_modifier + : ... + | 'unsafe' + ; + +constructor_modifier + : ... + | 'unsafe' + ; + +finalizer_declaration + : attributes? 'extern'? 'unsafe'? '~' identifier '(' ')' finalizer_body + | attributes? 'unsafe'? 'extern'? '~' identifier '(' ')' finalizer_body + ; + +static_constructor_modifiers + : 'extern'? 'unsafe'? 'static' + | 'unsafe'? 'extern'? 'static' + | 'extern'? 'static' 'unsafe'? + | 'unsafe'? 'static' 'extern'? + | 'static' 'extern'? 'unsafe'? + | 'static' 'unsafe'? 'extern'? + ; + +embedded_statement + : ... + | unsafe_statement + | fixed_statement + ; + +unsafe_statement + : 'unsafe' block + ; + +type + : ... + | pointer_type + ; + +non_array_type + : ... + | pointer_type + ; + +pointer_type + : unmanaged_type '*' + | 'void' '*' + ; + +unmanaged_type + : type + ; + +primary_no_array_creation_expression + : ... + | pointer_member_access + | pointer_element_access + ; + +unary_expression + : ... + | pointer_indirection_expression + | addressof_expression + ; + +pointer_indirection_expression + : '*' unary_expression + ; + +pointer_member_access + : primary_expression '->' identifier type_argument_list? + ; + +pointer_element_access + : primary_no_array_creation_expression '[' expression ']' + ; + +addressof_expression + : '&' unary_expression + ; + +fixed_statement + : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement + ; + +fixed_pointer_declarators + : fixed_pointer_declarator (',' fixed_pointer_declarator)* + ; + +fixed_pointer_declarator + : identifier '=' fixed_pointer_initializer + ; + +fixed_pointer_initializer + : '&' variable_reference + | expression + ; + +struct_member_declaration + : ... + | fixed_size_buffer_declaration + ; + +fixed_size_buffer_declaration + : attributes? fixed_size_buffer_modifier* 'fixed' buffer_element_type fixed_size_buffer_declarator+ ';' + ; + +fixed_size_buffer_modifier + : 'new' + | 'public' + | 'protected' + | 'internal' + | 'private' + | 'unsafe' + ; + +buffer_element_type + : type + ; + +fixed_size_buffer_declarator + : identifier '[' constant_expression ']' + ; + +local_variable_initializer + : ... + | stackalloc_initializer + ; + +stackalloc_initializer + : 'stackalloc' unmanaged_type '[' expression ']' + ; From 2891a7a9aceca6e4c7d7674ade64916e700ff85d Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 14 Jan 2021 17:30:29 -0500 Subject: [PATCH 2/8] add section numbers to grammar I think this will help us validate the grammar and fix validation errors. --- standard/grammar.md | 162 ++++++++++++++++++++++++++++++++ tools/GetGrammar/GetGrammar.bat | 34 +++---- tools/GetGrammar/Program.cs | 22 +++-- tools/GetGrammar/grammar.antlr | 162 ++++++++++++++++++++++++++++++++ 4 files changed, 356 insertions(+), 24 deletions(-) diff --git a/standard/grammar.md b/standard/grammar.md index 217b50c0b..c58844f41 100644 --- a/standard/grammar.md +++ b/standard/grammar.md @@ -10,6 +10,7 @@ This annex contains the grammar productions found in the specification, includin ```ANTLR +// Source: 7.3.1 General input : input_section? ; @@ -29,6 +30,7 @@ input_element | token ; +// Source: 7.3.2 Line terminators new_line : '' | '' @@ -38,6 +40,7 @@ new_line | '' ; +// Source: 7.3.3 Comments comment : single_line_comment | delimited_comment @@ -76,6 +79,7 @@ not_slash_or_asterisk : '' ; +// Source: 7.3.4 White space whitespace : '' | '' @@ -83,6 +87,7 @@ whitespace | '' ; +// Source: 7.4.1 General token : identifier | keyword @@ -93,11 +98,13 @@ token | operator_or_punctuator ; +// Source: 7.4.2 Unicode character escape sequences unicode_escape_sequence : '\\u' hex_digit hex_digit hex_digit hex_digit | '\\U' hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit ; +// Source: 7.4.3 Identifiers identifier : available_identifier | '@' identifier_or_keyword @@ -154,6 +161,7 @@ formatting_character | '' ; +// Source: 7.4.4 Keywords keyword : 'abstract' | 'as' | 'base' | 'bool' | 'break' | 'byte' | 'case' | 'catch' | 'char' | 'checked' @@ -173,6 +181,7 @@ keyword | 'volatile' | 'while' ; +// Source: 7.4.4 Keywords contextual_keyword : 'add' 'alias' 'ascending' 'async' 'await' | 'by' 'descending' 'dynamic' 'equals' 'from' @@ -181,6 +190,7 @@ contextual_keyword | 'set' 'value' 'var' 'where' 'yield' ; +// Source: 7.4.5.1 General literal : boolean_literal | integer_literal @@ -190,11 +200,13 @@ literal | null_literal ; +// Source: 7.4.5.2 Boolean literals boolean_literal : 'true' | 'false' ; +// Source: 7.4.5.3 Integer literals integer_literal : decimal_integer_literal | hexadecimal_integer_literal @@ -221,6 +233,7 @@ hex_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'; +// Source: 7.4.5.4 Real literals real_literal : decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? | '.' decimal_digit+ exponent_part? real_type_suffix? @@ -241,6 +254,7 @@ real_type_suffix : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' ; +// Source: 7.4.5.5 Character literals character_literal : '\'' character '\'' ; @@ -264,6 +278,7 @@ hexadecimal_escape_sequence : '\\x' hex_digit hex_digit? hex_digit? hex_digit? ; +// Source: 7.4.5.6 String literals string_literal : regular_string_literal | verbatim_string_literal @@ -301,10 +316,12 @@ quote_escape_sequence : '""' ; +// Source: 7.4.5.7 The null literal null_literal : 'null' ; +// Source: 7.4.6 Operators and punctuators operator_or_punctuator : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' @@ -321,6 +338,7 @@ right_shift_assignment : '>' '>=' ; +// Source: 7.5.1 General pp_directive : pp_declaration | pp_conditional @@ -330,10 +348,12 @@ pp_directive | pp_pragma ; +// Source: 7.5.2 Conditional compilation symbols conditional_symbol : '' ; +// Source: 7.5.3 Pre-processing expressions pp_expression : whitespace? pp_or_expression whitespace? ; @@ -366,6 +386,7 @@ pp_primary_expression | '(' whitespace? pp_expression whitespace? ')' ; +// Source: 7.5.4 Definition directives pp_declaration : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line @@ -375,6 +396,7 @@ pp_new_line : whitespace? single_line_comment? new_line ; +// Source: 7.5.5 Conditional compilation directives pp_conditional : pp_if_section pp_elif_section* pp_else_section? pp_endif ; @@ -413,6 +435,7 @@ not_number_sign : '' ; +// Source: 7.5.6 Diagnostic directives pp_diagnostic : whitespace? '#' whitespace? 'error' pp_message | whitespace? '#' whitespace? 'warning' pp_message @@ -423,6 +446,7 @@ pp_message | whitespace input_character* new_line ; +// Source: 7.5.7 Region directives pp_region : pp_start_region conditional_section? pp_end_region ; @@ -435,6 +459,7 @@ pp_end_region : whitespace? '#' whitespace? 'endregion' pp_message ; +// Source: 7.5.8 Line directives pp_line : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line ; @@ -454,6 +479,7 @@ compilation_unit_name_character : '' ; +// Source: 7.5.9 Pragma directives pp_pragma : whitespace? '#' whitespace? 'pragma' pp_pragma_text ; @@ -468,6 +494,7 @@ pp_pragma_text ```ANTLR +// Source: 8.8.1 General namespace_name : namespace_or_type_name ; @@ -482,12 +509,14 @@ namespace_or_type_name | qualified_alias_member ; +// Source: 9.1 General type : reference_type | value_type | type_parameter ; +// Source: 9.2.1 General reference_type : class_type | interface_type @@ -527,6 +556,7 @@ delegate_type : type_name ; +// Source: 9.3.1 General value_type : struct_type | enum_type @@ -578,6 +608,7 @@ enum_type : type_name ; +// Source: 9.4.2 Type arguments type_argument_list : '<' type_arguments '>' ; @@ -590,14 +621,17 @@ type_argument : type ; +// Source: 9.5 Type parameters type_parameter : identifier ; +// Source: 10.5 Variable references variable_reference : expression ; +// Source: 12.6.2.1 General argument_list : argument (',' argument)* ; @@ -616,6 +650,7 @@ argument_value | 'out' variable_reference ; +// Source: 12.7.1 General primary_expression : primary_no_array_creation_expression | array_creation_expression @@ -643,14 +678,17 @@ primary_no_array_creation_expression | anonymous_method_expression ; +// Source: 12.7.3.1 General simple_name : identifier type_argument_list? ; +// Source: 12.7.4 Parenthesized expressions parenthesized_expression : '(' expression ')' ; +// Source: 12.7.5.1 General member_access : primary_expression '.' identifier type_argument_list? | predefined_type '.' identifier type_argument_list? @@ -662,23 +700,28 @@ predefined_type | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' ; +// Source: 12.7.6.1 General invocation_expression : primary_expression '(' argument_list? ')' ; +// Source: 12.7.7.1 General element_access : primary_no_array_creation_expression '[' argument_list ']' ; +// Source: 12.7.8 This access this_access : 'this' ; +// Source: 12.7.9 Base access base_access : 'base' '.' identifier type_argument_list? | 'base' '[' argument_list ']' ; +// Source: 12.7.10 Postfix increment and decrement operators post_increment_expression : primary_expression '++' ; @@ -687,6 +730,7 @@ post_decrement_expression : primary_expression '--' ; +// Source: 12.7.11.2 Object creation expressions object_creation_expression : 'new' type '(' argument_list? ')' object_or_collection_initializer? | 'new' type object_or_collection_initializer @@ -697,6 +741,7 @@ object_or_collection_initializer | collection_initializer ; +// Source: 12.7.11.3 Object initializers object_initializer : '{' member_initializer_list? '}' | '{' member_initializer_list ',' '}' @@ -715,6 +760,7 @@ initializer_value | object_or_collection_initializer ; +// Source: 12.7.11.4 Collection initializers collection_initializer : '{' element_initializer_list '}' | '{' element_initializer_list ',' '}' @@ -734,16 +780,19 @@ expression_list | expression_list ',' expression ; +// Source: 12.7.11.5 Array creation expressions array_creation_expression : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? | 'new' array_type array_initializer | 'new' rank_specifier array_initializer ; +// Source: 12.7.11.6 Delegate creation expressions delegate_creation_expression : 'new' delegate_type '(' expression ')' ; +// Source: 12.7.11.7 Anonymous object creation expressions anonymous_object_creation_expression : 'new' anonymous_object_initializer ; @@ -764,6 +813,7 @@ member_declarator | identifier '=' expression ; +// Source: 12.7.12 The typeof operator typeof_expression : 'typeof' '(' type ')' | 'typeof' '(' unbound_type_name ')' @@ -785,10 +835,12 @@ comma ; +// Source: 12.7.13 The sizeof operator sizeof_expression : 'sizeof' '(' unmanaged_type ')' ; +// Source: 12.7.14 The checked and unchecked operators checked_expression : 'checked' '(' expression ')' ; @@ -797,10 +849,12 @@ unchecked_expression : 'unchecked' '(' expression ')' ; +// Source: 12.7.15 Default value expressions default_value_expression : 'default' '(' type ')' ; +// Source: 12.8.1 General unary_expression : primary_expression | '+' unary_expression @@ -813,6 +867,7 @@ unary_expression | await_expression ; +// Source: 12.8.6 Prefix increment and decrement operators pre_increment_expression : '++' unary_expression ; @@ -821,14 +876,17 @@ pre_decrement_expression : '--' unary_expression ; +// Source: 12.8.7 Cast expressions cast_expression : '(' type ')' unary_expression ; +// Source: 12.8.8.1 General await_expression : 'await' unary_expression ; +// Source: 12.9.1 General multiplicative_expression : unary_expression | multiplicative_expression '*' unary_expression @@ -842,12 +900,14 @@ additive_expression | additive_expression '-' multiplicative_expression ; +// Source: 12.10 Shift operators shift_expression : additive_expression | shift_expression '<<' additive_expression | shift_expression right_shift additive_expression ; +// Source: 12.11.1 General relational_expression : shift_expression | relational_expression '<' shift_expression @@ -864,6 +924,7 @@ equality_expression | equality_expression '!=' relational_expression ; +// Source: 12.12.1 General and_expression : equality_expression | and_expression '&' equality_expression @@ -879,6 +940,7 @@ inclusive_or_expression | inclusive_or_expression '|' exclusive_or_expression ; +// Source: 12.13.1 General conditional_and_expression : inclusive_or_expression | conditional_and_expression '&&' inclusive_or_expression @@ -889,16 +951,19 @@ conditional_or_expression | conditional_or_expression '||' conditional_and_expression ; +// Source: 12.14 The null coalescing operator null_coalescing_expression : conditional_or_expression | conditional_or_expression '??' null_coalescing_expression ; +// Source: 12.15 Conditional operator conditional_expression : null_coalescing_expression | null_coalescing_expression '?' expression ':' expression ; +// Source: 12.16.1 General lambda_expression : 'async'? anonymous_function_signature '=>' anonymous_function_body ; @@ -947,6 +1012,7 @@ anonymous_function_body | block ; +// Source: 12.17.1 General query_expression : from_clause query_body ; @@ -1023,6 +1089,7 @@ query_continuation : 'into' identifier query_body ; +// Source: 12.18.1 General assignment : unary_expression assignment_operator expression ; @@ -1032,6 +1099,7 @@ assignment_operator | right_shift_assignment ; +// Source: 12.19 Expression expression : non_assignment_expression | assignment @@ -1043,14 +1111,17 @@ non_assignment_expression | query_expression ; +// Source: 12.20 Constant expressions constant_expression : expression ; +// Source: 12.21 Boolean expressions boolean_expression : expression ; +// Source: 13.1 General statement : labeled_statement | declaration_statement @@ -1072,27 +1143,33 @@ embedded_statement | yield_statement ; +// Source: 13.3.1 General block : '{' statement_list? '}' ; +// Source: 13.3.2 Statement lists statement_list : statement+ ; +// Source: 13.4 The empty statement empty_statement : ';' ; +// Source: 13.5 Labeled statements labeled_statement : identifier ':' statement ; +// Source: 13.6.1 General declaration_statement : local_variable_declaration ';' | local_constant_declaration ';' ; +// Source: 13.6.2 Local variable declarations local_variable_declaration : local_variable_type local_variable_declarators ; @@ -1117,6 +1194,7 @@ local_variable_initializer | array_initializer ; +// Source: 13.6.3 Local constant declarations local_constant_declaration : 'const' type constant_declarators ; @@ -1129,6 +1207,7 @@ constant_declarator : identifier '=' constant_expression ; +// Source: 13.7 Expression statements expression_statement : statement_expression ';' ; @@ -1144,16 +1223,19 @@ statement_expression | await_expression ; +// Source: 13.8.1 General selection_statement : if_statement | switch_statement ; +// Source: 13.8.2 The if statement if_statement : 'if' '(' boolean_expression ')' embedded_statement | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement ; +// Source: 13.8.3 The switch statement switch_statement : 'switch' '(' expression ')' switch_block ; @@ -1171,6 +1253,7 @@ switch_label | 'default' ':' ; +// Source: 13.9.1 General iteration_statement : while_statement | do_statement @@ -1178,14 +1261,17 @@ iteration_statement | foreach_statement ; +// Source: 13.9.2 The while statement while_statement : 'while' '(' boolean_expression ')' embedded_statement ; +// Source: 13.9.3 The do statement do_statement : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' ; +// Source: 13.9.4 The for statement for_statement : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement ; @@ -1207,10 +1293,12 @@ statement_expression_list : statement_expression (',' statement_expression)* ; +// Source: 13.9.5 The foreach statement foreach_statement : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement ; +// Source: 13.10.1 General jump_statement : break_statement | continue_statement @@ -1219,28 +1307,34 @@ jump_statement | throw_statement ; +// Source: 13.10.2 The break statement break_statement : 'break' ';' ; +// Source: 13.10.3 The continue statement continue_statement : 'continue' ';' ; +// Source: 13.10.4 The goto statement goto_statement : 'goto' identifier ';' | 'goto' 'case' constant_expression ';' | 'goto' 'default' ';' ; +// Source: 13.10.5 The return statement return_statement : 'return' expression? ';' ; +// Source: 13.10.6 The throw statement throw_statement : 'throw' expression? ';' ; +// Source: 13.11 The try statement try_statement : 'try' block catch_clause+ | 'try' block finally_clause @@ -1255,6 +1349,7 @@ exception_specifier : '(' type identifier? ')' ; +// Source: 13.12 The checked and unchecked statements checked_statement : 'checked' block ; @@ -1263,10 +1358,12 @@ unchecked_statement : 'unchecked' block ; +// Source: 13.13 The lock statement lock_statement : 'lock' '(' expression ')' embedded_statement ; +// Source: 13.14 The using statement using_statement : 'using' '(' resource_acquisition ')' embedded_statement ; @@ -1276,15 +1373,18 @@ resource_acquisition | expression ; +// Source: 13.15 The yield statement yield_statement : 'yield' 'return' expression ';' | 'yield' 'break' ';' ; +// Source: 14.2 Compilation units compilation_unit : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* ; +// Source: 14.3 Namespace declarations namespace_declaration : 'namespace' qualified_identifier namespace_body ';'? ; @@ -1297,28 +1397,34 @@ namespace_body : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' ; +// Source: 14.4 Extern alias directives extern_alias_directive : 'extern' 'alias' identifier ';' ; +// Source: 14.5.1 General using_directive : using_alias-directive | using_namespace-directive ; +// Source: 14.5.2 Using alias directives using_alias_directive : 'using' identifier '=' namespace_or_type_name ';' ; +// Source: 14.5.3 Using namespace directives using_namespace_directive : 'using' namespace_name ';' ; +// Source: 14.6 Namespace member declarations namespace_member_declaration : namespace_declaration | type_declaration ; +// Source: 14.7 Type declarations type_declaration : class_declaration | struct_declaration @@ -1327,15 +1433,18 @@ type_declaration | delegate_declaration ; +// Source: 14.8.1 General qualified_alias_member : identifier '::' identifier type_argument_list? ; +// Source: 15.2.1 General class_declaration : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? class_base? type_parameter_constraints_clause* class_body ';'? ; +// Source: 15.2.2.1 General class_modifier : 'new' | 'public' @@ -1347,6 +1456,7 @@ class_modifier | 'static' ; +// Source: 15.2.3 Type parameters type_parameter_list : '<' type_parameters '>' ; @@ -1356,6 +1466,7 @@ type_parameters | type_parameters ',' attributes? type_parameter ; +// Source: 15.2.4.1 General class_base : ':' class_type | ':' interface_type_list @@ -1366,6 +1477,7 @@ interface_type_list : interface_type (',' interface_type)* ; +// Source: 15.2.5 Type parameter constraints type_parameter_constraints_clauses : type_parameter_constraints_clause | type_parameter_constraints_clauses type_parameter_constraints_clause @@ -1402,10 +1514,12 @@ constructor_constraint : 'new' '(' ')' ; +// Source: 15.2.6 Class body class_body : '{' class_member_declaration* '}' ; +// Source: 15.3.1 General class_member_declaration : constant_declaration | field_declaration @@ -1420,6 +1534,7 @@ class_member_declaration | type_declaration ; +// Source: 15.4 Constants constant_declaration : attributes? constant_modifier* 'const' type constant_declarators ';' ; @@ -1432,6 +1547,7 @@ constant_modifier | 'private' ; +// Source: 15.5.1 General field_declaration : attributes? field_modifier* type variable_declarators ';' ; @@ -1455,6 +1571,7 @@ variable_declarator : identifier ('=' variable_initializer)? ; +// Source: 15.6.1 General method_declaration : method_header method_body ; @@ -1492,6 +1609,7 @@ method_body : block ; +// Source: 15.6.2.1 General formal_parameter_list : fixed_parameters | fixed_parameters ',' parameter_array @@ -1524,6 +1642,7 @@ parameter_array : attributes? 'params' array_type identifier ; +// Source: 15.7.1 General property_declaration : attributes? property_modifiers? type member_name '{' accessor_declarations '}' ; @@ -1547,6 +1666,7 @@ property_modifier | 'extern' ; +// Source: 15.7.3 Accessors accessor_declarations : get_accessor_declaration set_accessor_declaration? | set_accessor_declaration get_accessor_declaration? @@ -1573,6 +1693,7 @@ accessor_body | ';' ; +// Source: 15.8.1 General event_declaration : attributes? event_modifier* 'event' type variable_declarators ';' | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' @@ -1605,6 +1726,7 @@ remove_accessor_declaration : attributes? 'remove' block ; +// Source: 15.9 Indexers indexer_declaration : attributes? indexer_modifiers? indexer_declarator '{' accessor_declarations '}' ; @@ -1632,6 +1754,7 @@ indexer_declarator | type interface_type '.' 'this' '[' formal_parameter_list ']' ; +// Source: 15.10.1 General operator_declaration : attributes? operator_modifier+ operator_declarator operator_body ; @@ -1675,6 +1798,7 @@ operator_body | ';' ; +// Source: 15.11.1 General constructor_declaration : attributes? constructor_modifier* constructor_declarator constructor_body ; @@ -1701,6 +1825,7 @@ constructor_body | ';' ; +// Source: 15.12 Static constructors static_constructor_declaration : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body ; @@ -1715,6 +1840,7 @@ static_constructor_body | ';' ; +// Source: 15.13 Finalizers finalizer_declaration : attributes? 'extern'? '~' identifier '(' ')' finalizer_body ; @@ -1724,11 +1850,13 @@ finalizer_body | ';' ; +// Source: 16.2.1 General struct_declaration : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? struct_interfaces? type_parameter_constraints_clause* struct_body ';'? ; +// Source: 16.2.2 Struct modifiers struct_modifier : 'new' | 'public' @@ -1737,14 +1865,17 @@ struct_modifier | 'private' ; +// Source: 16.2.4 Struct interfaces struct_interfaces : ':' interface_type_list ; +// Source: 16.2.5 Struct body struct_body : '{' struct_member_declaration* '}' ; +// Source: 16.3 Struct members struct_member_declaration : constant_declaration | field_declaration @@ -1758,6 +1889,7 @@ struct_member_declaration | type_declaration ; +// Source: 17.7 Array initializers array_initializer : '{' variable_initializer_list? '}' | '{' variable_initializer_list ',' '}' @@ -1772,10 +1904,12 @@ variable_initializer | array_initializer ; +// Source: 18.2.1 General interface_declaration : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? ; +// Source: 18.2.2 Interface modifiers interface_modifier : 'new' | 'public' @@ -1784,28 +1918,34 @@ interface_modifier | 'private' ; +// Source: 18.2.3.1 General variant_type_parameter_list : '<' variant_type_parameters '>' ; +// Source: 18.2.3.1 General variant_type_parameters : attributes? variance_annotation? type_parameter | variant_type_parameters ',' attributes? variance_annotation? type_parameter ; +// Source: 18.2.3.1 General variance_annotation : 'in' | 'out' ; +// Source: 18.2.4 Base interfaces interface_base : ':' interface_type_list ; +// Source: 18.3 Interface body interface_body : '{' interface_member_declaration* '}' ; +// Source: 18.4.1 General interface_member_declaration : interface_method_declaration | interface_property_declaration @@ -1813,14 +1953,17 @@ interface_member_declaration | interface_indexer_declaration ; +// Source: 18.4.2 Interface methods interface_method_declaration : attributes? 'new'? return_type identifier type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; +// Source: 18.4.3 Interface properties interface_property_declaration : attributes? 'new'? type identifier '{' interface_accessors '}' ; +// Source: 18.4.3 Interface properties interface_accessors : attributes? 'get' ';' | attributes? 'set' ';' @@ -1828,14 +1971,17 @@ interface_accessors | attributes? 'set' ';' attributes? 'get' ';' ; +// Source: 18.4.4 Interface events interface_event_declaration : attributes? 'new'? 'event' type identifier ';' ; +// Source: 18.4.5 Interface indexers interface_indexer_declaration: attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' ; +// Source: 19.2 Enum declarations enum_declaration : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? ; @@ -1849,6 +1995,7 @@ enum_body | '{' enum_member_declarations ',' '}' ; +// Source: 19.3 Enum modifiers enum_modifier : 'new' | 'public' @@ -1857,14 +2004,17 @@ enum_modifier | 'private' ; +// Source: 19.4 Enum members enum_member_declarations : enum_member_declaration (',' enum_member_declaration)* ; +// Source: 19.4 Enum members enum_member_declaration : attributes? identifier ('=' constant_expression)? ; +// Source: 20.2 Delegate declarations delegate_declaration : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; @@ -1877,6 +2027,7 @@ delegate_modifier | 'private' ; +// Source: 22.3 Attribute specification global_attributes : global_attribute_section+ ; @@ -1955,6 +2106,7 @@ attribute_argument_expression ```ANTLR +// Source: 23.2 Unsafe contexts class_modifier : ... | 'unsafe' @@ -2033,6 +2185,7 @@ unsafe_statement : 'unsafe' block ; +// Source: 23.3 Pointer types type : ... | pointer_type @@ -2043,6 +2196,7 @@ non_array_type | pointer_type ; +// Source: 23.3 Pointer types pointer_type : unmanaged_type '*' | 'void' '*' @@ -2052,6 +2206,7 @@ unmanaged_type : type ; +// Source: 23.6.1 General primary_no_array_creation_expression : ... | pointer_member_access @@ -2064,22 +2219,27 @@ unary_expression | addressof_expression ; +// Source: 23.6.2 Pointer indirection pointer_indirection_expression : '*' unary_expression ; +// Source: 23.6.3 Pointer member access pointer_member_access : primary_expression '->' identifier type_argument_list? ; +// Source: 23.6.4 Pointer element access pointer_element_access : primary_no_array_creation_expression '[' expression ']' ; +// Source: 23.6.5 The address-of operator addressof_expression : '&' unary_expression ; +// Source: 23.7 The fixed statement fixed_statement : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ; @@ -2097,6 +2257,7 @@ fixed_pointer_initializer | expression ; +// Source: 23.8.2 Fixed-size buffer declarations struct_member_declaration : ... | fixed_size_buffer_declaration @@ -2123,6 +2284,7 @@ fixed_size_buffer_declarator : identifier '[' constant_expression ']' ; +// Source: 23.9 Stack allocation local_variable_initializer : ... | stackalloc_initializer diff --git a/tools/GetGrammar/GetGrammar.bat b/tools/GetGrammar/GetGrammar.bat index 06386b3a4..bb6c9378c 100644 --- a/tools/GetGrammar/GetGrammar.bat +++ b/tools/GetGrammar/GetGrammar.bat @@ -7,7 +7,7 @@ del ..\..\standard\grammar.md echo Insert General/Lexical Headers type grammar-general-lexical-insert.md >..\..\standard\grammar.md echo Extract Lexical Grammar -publish\GetGrammar <..\..\standard\lexical-structure.md >lexical-structure.antlr +publish\GetGrammar ..\..\standard\lexical-structure.md >lexical-structure.antlr type lexical-structure.antlr >grammar.antlr type lexical-structure.antlr >>..\..\standard\grammar.md del lexical-structure.antlr @@ -16,77 +16,77 @@ echo Insert Syntactic Header type grammar-syntactic-insert.md >>..\..\standard\grammar.md echo Extract Syntactic Grammar -publish\GetGrammar <..\..\standard\basic-concepts.md >basic-concepts.antlr +publish\GetGrammar ..\..\standard\basic-concepts.md >basic-concepts.antlr type basic-concepts.antlr >>grammar.antlr type basic-concepts.antlr >>..\..\standard\grammar.md del basic-concepts.antlr -publish\GetGrammar <..\..\standard\types.md >types.antlr +publish\GetGrammar ..\..\standard\types.md >types.antlr type types.antlr >>grammar.antlr type types.antlr >>..\..\standard\grammar.md del types.antlr -publish\GetGrammar <..\..\standard\variables.md >variables.antlr +publish\GetGrammar ..\..\standard\variables.md >variables.antlr type variables.antlr >>grammar.antlr type variables.antlr >>..\..\standard\grammar.md del variables.antlr -publish\GetGrammar <..\..\standard\conversions.md >conversions.antlr +publish\GetGrammar ..\..\standard\conversions.md >conversions.antlr type conversions.antlr >>grammar.antlr type conversions.antlr >>..\..\standard\grammar.md del conversions.antlr -publish\GetGrammar <..\..\standard\expressions.md >expressions.antlr +publish\GetGrammar ..\..\standard\expressions.md >expressions.antlr type expressions.antlr >>grammar.antlr type expressions.antlr >>..\..\standard\grammar.md del expressions.antlr -publish\GetGrammar <..\..\standard\statements.md >statements.antlr +publish\GetGrammar ..\..\standard\statements.md >statements.antlr type statements.antlr >>grammar.antlr type statements.antlr >>..\..\standard\grammar.md del statements.antlr -publish\GetGrammar <..\..\standard\namespaces.md >namespaces.antlr +publish\GetGrammar ..\..\standard\namespaces.md >namespaces.antlr type namespaces.antlr >>grammar.antlr type namespaces.antlr >>..\..\standard\grammar.md del namespaces.antlr -publish\GetGrammar <..\..\standard\classes.md >classes.antlr +publish\GetGrammar ..\..\standard\classes.md >classes.antlr type classes.antlr >>grammar.antlr type classes.antlr >>..\..\standard\grammar.md del classes.antlr -publish\GetGrammar <..\..\standard\structs.md >structs.antlr +publish\GetGrammar ..\..\standard\structs.md >structs.antlr type structs.antlr >>grammar.antlr type structs.antlr >>..\..\standard\grammar.md del structs.antlr -publish\GetGrammar <..\..\standard\arrays.md >arrays.antlr +publish\GetGrammar ..\..\standard\arrays.md >arrays.antlr type arrays.antlr >>grammar.antlr type arrays.antlr >>..\..\standard\grammar.md del arrays.antlr -publish\GetGrammar <..\..\standard\interfaces.md >interfaces.antlr +publish\GetGrammar ..\..\standard\interfaces.md >interfaces.antlr type interfaces.antlr >>grammar.antlr type interfaces.antlr >>..\..\standard\grammar.md del interfaces.antlr -publish\GetGrammar <..\..\standard\enums.md >enums.antlr +publish\GetGrammar ..\..\standard\enums.md >enums.antlr type enums.antlr >>grammar.antlr type enums.antlr >>..\..\standard\grammar.md del enums.antlr -publish\GetGrammar <..\..\standard\delegates.md >delegates.antlr +publish\GetGrammar ..\..\standard\delegates.md >delegates.antlr type delegates.antlr >>grammar.antlr type delegates.antlr >>..\..\standard\grammar.md del delegates.antlr -publish\GetGrammar <..\..\standard\exceptions.md >exceptions.antlr +publish\GetGrammar ..\..\standard\exceptions.md >exceptions.antlr type exceptions.antlr >>grammar.antlr type exceptions.antlr >>..\..\standard\grammar.md del exceptions.antlr -publish\GetGrammar <..\..\standard\attributes.md >attributes.antlr +publish\GetGrammar ..\..\standard\attributes.md >attributes.antlr type attributes.antlr >>grammar.antlr type attributes.antlr >>..\..\standard\grammar.md del attributes.antlr @@ -94,7 +94,7 @@ del attributes.antlr echo Insert Unsafe Header type grammar-unsafe-extensions-insert.md >>..\..\standard\grammar.md echo Extract Unsafe Grammar -publish\GetGrammar <..\..\standard\unsafe-code.md >unsafe-code.antlr +publish\GetGrammar ..\..\standard\unsafe-code.md >unsafe-code.antlr type unsafe-code.antlr >>grammar.antlr type unsafe-code.antlr >>..\..\standard\grammar.md del unsafe-code.antlr diff --git a/tools/GetGrammar/Program.cs b/tools/GetGrammar/Program.cs index c5b567a9a..a509de02e 100644 --- a/tools/GetGrammar/Program.cs +++ b/tools/GetGrammar/Program.cs @@ -24,33 +24,41 @@ using System; using System.IO; +using System.Threading.Tasks; namespace ExtractGrammar { class Program { - public static void Main() + public static async Task Main(string[] args) { + if (args.Length != 1) + { + Console.WriteLine("Usage: GetGrammar "); + Environment.Exit(1); + } + using var inputFile = new StreamReader(args[0]); string? inputLine; + string section = ""; - while ((inputLine = Console.ReadLine()) != null) + while ((inputLine = await inputFile.ReadLineAsync()) != null) { - if (inputLine.Length < 8) // Is it long enough to contain an opening fence? + if (inputLine.StartsWith("#")) { + section = inputLine.Trim('#', ' '); continue; } - string leader = inputLine.Substring(0, 8); // grab what might be an opening fence - // Console.WriteLine(">" + leader + "<"); - if (leader != "```ANTLR" && leader != "```antlr") + if (!inputLine.StartsWith("```ANTLR", StringComparison.InvariantCultureIgnoreCase)) { continue; } // Console.WriteLine("------ Start of a production"); Console.WriteLine(); // write out blank line before each new production + Console.WriteLine($"// Source: §{section}"); while (true) { - inputLine = Console.ReadLine(); + inputLine = await inputFile.ReadLineAsync(); if (inputLine == null) { Console.WriteLine("Unexpected EOF; no closing grammar fence"); diff --git a/tools/GetGrammar/grammar.antlr b/tools/GetGrammar/grammar.antlr index 6d5e205cf..b3ad3a3c2 100644 --- a/tools/GetGrammar/grammar.antlr +++ b/tools/GetGrammar/grammar.antlr @@ -1,4 +1,5 @@ +// Source: 7.3.1 General input : input_section? ; @@ -18,6 +19,7 @@ input_element | token ; +// Source: 7.3.2 Line terminators new_line : '' | '' @@ -27,6 +29,7 @@ new_line | '' ; +// Source: 7.3.3 Comments comment : single_line_comment | delimited_comment @@ -65,6 +68,7 @@ not_slash_or_asterisk : '' ; +// Source: 7.3.4 White space whitespace : '' | '' @@ -72,6 +76,7 @@ whitespace | '' ; +// Source: 7.4.1 General token : identifier | keyword @@ -82,11 +87,13 @@ token | operator_or_punctuator ; +// Source: 7.4.2 Unicode character escape sequences unicode_escape_sequence : '\\u' hex_digit hex_digit hex_digit hex_digit | '\\U' hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit ; +// Source: 7.4.3 Identifiers identifier : available_identifier | '@' identifier_or_keyword @@ -143,6 +150,7 @@ formatting_character | '' ; +// Source: 7.4.4 Keywords keyword : 'abstract' | 'as' | 'base' | 'bool' | 'break' | 'byte' | 'case' | 'catch' | 'char' | 'checked' @@ -162,6 +170,7 @@ keyword | 'volatile' | 'while' ; +// Source: 7.4.4 Keywords contextual_keyword : 'add' 'alias' 'ascending' 'async' 'await' | 'by' 'descending' 'dynamic' 'equals' 'from' @@ -170,6 +179,7 @@ contextual_keyword | 'set' 'value' 'var' 'where' 'yield' ; +// Source: 7.4.5.1 General literal : boolean_literal | integer_literal @@ -179,11 +189,13 @@ literal | null_literal ; +// Source: 7.4.5.2 Boolean literals boolean_literal : 'true' | 'false' ; +// Source: 7.4.5.3 Integer literals integer_literal : decimal_integer_literal | hexadecimal_integer_literal @@ -210,6 +222,7 @@ hex_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'; +// Source: 7.4.5.4 Real literals real_literal : decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? | '.' decimal_digit+ exponent_part? real_type_suffix? @@ -230,6 +243,7 @@ real_type_suffix : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' ; +// Source: 7.4.5.5 Character literals character_literal : '\'' character '\'' ; @@ -253,6 +267,7 @@ hexadecimal_escape_sequence : '\\x' hex_digit hex_digit? hex_digit? hex_digit? ; +// Source: 7.4.5.6 String literals string_literal : regular_string_literal | verbatim_string_literal @@ -290,10 +305,12 @@ quote_escape_sequence : '""' ; +// Source: 7.4.5.7 The null literal null_literal : 'null' ; +// Source: 7.4.6 Operators and punctuators operator_or_punctuator : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' @@ -310,6 +327,7 @@ right_shift_assignment : '>' '>=' ; +// Source: 7.5.1 General pp_directive : pp_declaration | pp_conditional @@ -319,10 +337,12 @@ pp_directive | pp_pragma ; +// Source: 7.5.2 Conditional compilation symbols conditional_symbol : '' ; +// Source: 7.5.3 Pre-processing expressions pp_expression : whitespace? pp_or_expression whitespace? ; @@ -355,6 +375,7 @@ pp_primary_expression | '(' whitespace? pp_expression whitespace? ')' ; +// Source: 7.5.4 Definition directives pp_declaration : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line @@ -364,6 +385,7 @@ pp_new_line : whitespace? single_line_comment? new_line ; +// Source: 7.5.5 Conditional compilation directives pp_conditional : pp_if_section pp_elif_section* pp_else_section? pp_endif ; @@ -402,6 +424,7 @@ not_number_sign : '' ; +// Source: 7.5.6 Diagnostic directives pp_diagnostic : whitespace? '#' whitespace? 'error' pp_message | whitespace? '#' whitespace? 'warning' pp_message @@ -412,6 +435,7 @@ pp_message | whitespace input_character* new_line ; +// Source: 7.5.7 Region directives pp_region : pp_start_region conditional_section? pp_end_region ; @@ -424,6 +448,7 @@ pp_end_region : whitespace? '#' whitespace? 'endregion' pp_message ; +// Source: 7.5.8 Line directives pp_line : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line ; @@ -443,6 +468,7 @@ compilation_unit_name_character : '' ; +// Source: 7.5.9 Pragma directives pp_pragma : whitespace? '#' whitespace? 'pragma' pp_pragma_text ; @@ -452,6 +478,7 @@ pp_pragma_text | whitespace input_character* new_line ; +// Source: 8.8.1 General namespace_name : namespace_or_type_name ; @@ -466,12 +493,14 @@ namespace_or_type_name | qualified_alias_member ; +// Source: 9.1 General type : reference_type | value_type | type_parameter ; +// Source: 9.2.1 General reference_type : class_type | interface_type @@ -511,6 +540,7 @@ delegate_type : type_name ; +// Source: 9.3.1 General value_type : struct_type | enum_type @@ -562,6 +592,7 @@ enum_type : type_name ; +// Source: 9.4.2 Type arguments type_argument_list : '<' type_arguments '>' ; @@ -574,14 +605,17 @@ type_argument : type ; +// Source: 9.5 Type parameters type_parameter : identifier ; +// Source: 10.5 Variable references variable_reference : expression ; +// Source: 12.6.2.1 General argument_list : argument (',' argument)* ; @@ -600,6 +634,7 @@ argument_value | 'out' variable_reference ; +// Source: 12.7.1 General primary_expression : primary_no_array_creation_expression | array_creation_expression @@ -627,14 +662,17 @@ primary_no_array_creation_expression | anonymous_method_expression ; +// Source: 12.7.3.1 General simple_name : identifier type_argument_list? ; +// Source: 12.7.4 Parenthesized expressions parenthesized_expression : '(' expression ')' ; +// Source: 12.7.5.1 General member_access : primary_expression '.' identifier type_argument_list? | predefined_type '.' identifier type_argument_list? @@ -646,23 +684,28 @@ predefined_type | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' ; +// Source: 12.7.6.1 General invocation_expression : primary_expression '(' argument_list? ')' ; +// Source: 12.7.7.1 General element_access : primary_no_array_creation_expression '[' argument_list ']' ; +// Source: 12.7.8 This access this_access : 'this' ; +// Source: 12.7.9 Base access base_access : 'base' '.' identifier type_argument_list? | 'base' '[' argument_list ']' ; +// Source: 12.7.10 Postfix increment and decrement operators post_increment_expression : primary_expression '++' ; @@ -671,6 +714,7 @@ post_decrement_expression : primary_expression '--' ; +// Source: 12.7.11.2 Object creation expressions object_creation_expression : 'new' type '(' argument_list? ')' object_or_collection_initializer? | 'new' type object_or_collection_initializer @@ -681,6 +725,7 @@ object_or_collection_initializer | collection_initializer ; +// Source: 12.7.11.3 Object initializers object_initializer : '{' member_initializer_list? '}' | '{' member_initializer_list ',' '}' @@ -699,6 +744,7 @@ initializer_value | object_or_collection_initializer ; +// Source: 12.7.11.4 Collection initializers collection_initializer : '{' element_initializer_list '}' | '{' element_initializer_list ',' '}' @@ -718,16 +764,19 @@ expression_list | expression_list ',' expression ; +// Source: 12.7.11.5 Array creation expressions array_creation_expression : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? | 'new' array_type array_initializer | 'new' rank_specifier array_initializer ; +// Source: 12.7.11.6 Delegate creation expressions delegate_creation_expression : 'new' delegate_type '(' expression ')' ; +// Source: 12.7.11.7 Anonymous object creation expressions anonymous_object_creation_expression : 'new' anonymous_object_initializer ; @@ -748,6 +797,7 @@ member_declarator | identifier '=' expression ; +// Source: 12.7.12 The typeof operator typeof_expression : 'typeof' '(' type ')' | 'typeof' '(' unbound_type_name ')' @@ -769,10 +819,12 @@ comma ; +// Source: 12.7.13 The sizeof operator sizeof_expression : 'sizeof' '(' unmanaged_type ')' ; +// Source: 12.7.14 The checked and unchecked operators checked_expression : 'checked' '(' expression ')' ; @@ -781,10 +833,12 @@ unchecked_expression : 'unchecked' '(' expression ')' ; +// Source: 12.7.15 Default value expressions default_value_expression : 'default' '(' type ')' ; +// Source: 12.8.1 General unary_expression : primary_expression | '+' unary_expression @@ -797,6 +851,7 @@ unary_expression | await_expression ; +// Source: 12.8.6 Prefix increment and decrement operators pre_increment_expression : '++' unary_expression ; @@ -805,14 +860,17 @@ pre_decrement_expression : '--' unary_expression ; +// Source: 12.8.7 Cast expressions cast_expression : '(' type ')' unary_expression ; +// Source: 12.8.8.1 General await_expression : 'await' unary_expression ; +// Source: 12.9.1 General multiplicative_expression : unary_expression | multiplicative_expression '*' unary_expression @@ -826,12 +884,14 @@ additive_expression | additive_expression '-' multiplicative_expression ; +// Source: 12.10 Shift operators shift_expression : additive_expression | shift_expression '<<' additive_expression | shift_expression right_shift additive_expression ; +// Source: 12.11.1 General relational_expression : shift_expression | relational_expression '<' shift_expression @@ -848,6 +908,7 @@ equality_expression | equality_expression '!=' relational_expression ; +// Source: 12.12.1 General and_expression : equality_expression | and_expression '&' equality_expression @@ -863,6 +924,7 @@ inclusive_or_expression | inclusive_or_expression '|' exclusive_or_expression ; +// Source: 12.13.1 General conditional_and_expression : inclusive_or_expression | conditional_and_expression '&&' inclusive_or_expression @@ -873,16 +935,19 @@ conditional_or_expression | conditional_or_expression '||' conditional_and_expression ; +// Source: 12.14 The null coalescing operator null_coalescing_expression : conditional_or_expression | conditional_or_expression '??' null_coalescing_expression ; +// Source: 12.15 Conditional operator conditional_expression : null_coalescing_expression | null_coalescing_expression '?' expression ':' expression ; +// Source: 12.16.1 General lambda_expression : 'async'? anonymous_function_signature '=>' anonymous_function_body ; @@ -931,6 +996,7 @@ anonymous_function_body | block ; +// Source: 12.17.1 General query_expression : from_clause query_body ; @@ -1007,6 +1073,7 @@ query_continuation : 'into' identifier query_body ; +// Source: 12.18.1 General assignment : unary_expression assignment_operator expression ; @@ -1016,6 +1083,7 @@ assignment_operator | right_shift_assignment ; +// Source: 12.19 Expression expression : non_assignment_expression | assignment @@ -1027,14 +1095,17 @@ non_assignment_expression | query_expression ; +// Source: 12.20 Constant expressions constant_expression : expression ; +// Source: 12.21 Boolean expressions boolean_expression : expression ; +// Source: 13.1 General statement : labeled_statement | declaration_statement @@ -1056,27 +1127,33 @@ embedded_statement | yield_statement ; +// Source: 13.3.1 General block : '{' statement_list? '}' ; +// Source: 13.3.2 Statement lists statement_list : statement+ ; +// Source: 13.4 The empty statement empty_statement : ';' ; +// Source: 13.5 Labeled statements labeled_statement : identifier ':' statement ; +// Source: 13.6.1 General declaration_statement : local_variable_declaration ';' | local_constant_declaration ';' ; +// Source: 13.6.2 Local variable declarations local_variable_declaration : local_variable_type local_variable_declarators ; @@ -1101,6 +1178,7 @@ local_variable_initializer | array_initializer ; +// Source: 13.6.3 Local constant declarations local_constant_declaration : 'const' type constant_declarators ; @@ -1113,6 +1191,7 @@ constant_declarator : identifier '=' constant_expression ; +// Source: 13.7 Expression statements expression_statement : statement_expression ';' ; @@ -1128,16 +1207,19 @@ statement_expression | await_expression ; +// Source: 13.8.1 General selection_statement : if_statement | switch_statement ; +// Source: 13.8.2 The if statement if_statement : 'if' '(' boolean_expression ')' embedded_statement | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement ; +// Source: 13.8.3 The switch statement switch_statement : 'switch' '(' expression ')' switch_block ; @@ -1155,6 +1237,7 @@ switch_label | 'default' ':' ; +// Source: 13.9.1 General iteration_statement : while_statement | do_statement @@ -1162,14 +1245,17 @@ iteration_statement | foreach_statement ; +// Source: 13.9.2 The while statement while_statement : 'while' '(' boolean_expression ')' embedded_statement ; +// Source: 13.9.3 The do statement do_statement : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' ; +// Source: 13.9.4 The for statement for_statement : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement ; @@ -1191,10 +1277,12 @@ statement_expression_list : statement_expression (',' statement_expression)* ; +// Source: 13.9.5 The foreach statement foreach_statement : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement ; +// Source: 13.10.1 General jump_statement : break_statement | continue_statement @@ -1203,28 +1291,34 @@ jump_statement | throw_statement ; +// Source: 13.10.2 The break statement break_statement : 'break' ';' ; +// Source: 13.10.3 The continue statement continue_statement : 'continue' ';' ; +// Source: 13.10.4 The goto statement goto_statement : 'goto' identifier ';' | 'goto' 'case' constant_expression ';' | 'goto' 'default' ';' ; +// Source: 13.10.5 The return statement return_statement : 'return' expression? ';' ; +// Source: 13.10.6 The throw statement throw_statement : 'throw' expression? ';' ; +// Source: 13.11 The try statement try_statement : 'try' block catch_clause+ | 'try' block finally_clause @@ -1239,6 +1333,7 @@ exception_specifier : '(' type identifier? ')' ; +// Source: 13.12 The checked and unchecked statements checked_statement : 'checked' block ; @@ -1247,10 +1342,12 @@ unchecked_statement : 'unchecked' block ; +// Source: 13.13 The lock statement lock_statement : 'lock' '(' expression ')' embedded_statement ; +// Source: 13.14 The using statement using_statement : 'using' '(' resource_acquisition ')' embedded_statement ; @@ -1260,15 +1357,18 @@ resource_acquisition | expression ; +// Source: 13.15 The yield statement yield_statement : 'yield' 'return' expression ';' | 'yield' 'break' ';' ; +// Source: 14.2 Compilation units compilation_unit : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* ; +// Source: 14.3 Namespace declarations namespace_declaration : 'namespace' qualified_identifier namespace_body ';'? ; @@ -1281,28 +1381,34 @@ namespace_body : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' ; +// Source: 14.4 Extern alias directives extern_alias_directive : 'extern' 'alias' identifier ';' ; +// Source: 14.5.1 General using_directive : using_alias-directive | using_namespace-directive ; +// Source: 14.5.2 Using alias directives using_alias_directive : 'using' identifier '=' namespace_or_type_name ';' ; +// Source: 14.5.3 Using namespace directives using_namespace_directive : 'using' namespace_name ';' ; +// Source: 14.6 Namespace member declarations namespace_member_declaration : namespace_declaration | type_declaration ; +// Source: 14.7 Type declarations type_declaration : class_declaration | struct_declaration @@ -1311,15 +1417,18 @@ type_declaration | delegate_declaration ; +// Source: 14.8.1 General qualified_alias_member : identifier '::' identifier type_argument_list? ; +// Source: 15.2.1 General class_declaration : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? class_base? type_parameter_constraints_clause* class_body ';'? ; +// Source: 15.2.2.1 General class_modifier : 'new' | 'public' @@ -1331,6 +1440,7 @@ class_modifier | 'static' ; +// Source: 15.2.3 Type parameters type_parameter_list : '<' type_parameters '>' ; @@ -1340,6 +1450,7 @@ type_parameters | type_parameters ',' attributes? type_parameter ; +// Source: 15.2.4.1 General class_base : ':' class_type | ':' interface_type_list @@ -1350,6 +1461,7 @@ interface_type_list : interface_type (',' interface_type)* ; +// Source: 15.2.5 Type parameter constraints type_parameter_constraints_clauses : type_parameter_constraints_clause | type_parameter_constraints_clauses type_parameter_constraints_clause @@ -1386,10 +1498,12 @@ constructor_constraint : 'new' '(' ')' ; +// Source: 15.2.6 Class body class_body : '{' class_member_declaration* '}' ; +// Source: 15.3.1 General class_member_declaration : constant_declaration | field_declaration @@ -1404,6 +1518,7 @@ class_member_declaration | type_declaration ; +// Source: 15.4 Constants constant_declaration : attributes? constant_modifier* 'const' type constant_declarators ';' ; @@ -1416,6 +1531,7 @@ constant_modifier | 'private' ; +// Source: 15.5.1 General field_declaration : attributes? field_modifier* type variable_declarators ';' ; @@ -1439,6 +1555,7 @@ variable_declarator : identifier ('=' variable_initializer)? ; +// Source: 15.6.1 General method_declaration : method_header method_body ; @@ -1476,6 +1593,7 @@ method_body : block ; +// Source: 15.6.2.1 General formal_parameter_list : fixed_parameters | fixed_parameters ',' parameter_array @@ -1508,6 +1626,7 @@ parameter_array : attributes? 'params' array_type identifier ; +// Source: 15.7.1 General property_declaration : attributes? property_modifiers? type member_name '{' accessor_declarations '}' ; @@ -1531,6 +1650,7 @@ property_modifier | 'extern' ; +// Source: 15.7.3 Accessors accessor_declarations : get_accessor_declaration set_accessor_declaration? | set_accessor_declaration get_accessor_declaration? @@ -1557,6 +1677,7 @@ accessor_body | ';' ; +// Source: 15.8.1 General event_declaration : attributes? event_modifier* 'event' type variable_declarators ';' | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' @@ -1589,6 +1710,7 @@ remove_accessor_declaration : attributes? 'remove' block ; +// Source: 15.9 Indexers indexer_declaration : attributes? indexer_modifiers? indexer_declarator '{' accessor_declarations '}' ; @@ -1616,6 +1738,7 @@ indexer_declarator | type interface_type '.' 'this' '[' formal_parameter_list ']' ; +// Source: 15.10.1 General operator_declaration : attributes? operator_modifier+ operator_declarator operator_body ; @@ -1659,6 +1782,7 @@ operator_body | ';' ; +// Source: 15.11.1 General constructor_declaration : attributes? constructor_modifier* constructor_declarator constructor_body ; @@ -1685,6 +1809,7 @@ constructor_body | ';' ; +// Source: 15.12 Static constructors static_constructor_declaration : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body ; @@ -1699,6 +1824,7 @@ static_constructor_body | ';' ; +// Source: 15.13 Finalizers finalizer_declaration : attributes? 'extern'? '~' identifier '(' ')' finalizer_body ; @@ -1708,11 +1834,13 @@ finalizer_body | ';' ; +// Source: 16.2.1 General struct_declaration : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? struct_interfaces? type_parameter_constraints_clause* struct_body ';'? ; +// Source: 16.2.2 Struct modifiers struct_modifier : 'new' | 'public' @@ -1721,14 +1849,17 @@ struct_modifier | 'private' ; +// Source: 16.2.4 Struct interfaces struct_interfaces : ':' interface_type_list ; +// Source: 16.2.5 Struct body struct_body : '{' struct_member_declaration* '}' ; +// Source: 16.3 Struct members struct_member_declaration : constant_declaration | field_declaration @@ -1742,6 +1873,7 @@ struct_member_declaration | type_declaration ; +// Source: 17.7 Array initializers array_initializer : '{' variable_initializer_list? '}' | '{' variable_initializer_list ',' '}' @@ -1756,10 +1888,12 @@ variable_initializer | array_initializer ; +// Source: 18.2.1 General interface_declaration : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? ; +// Source: 18.2.2 Interface modifiers interface_modifier : 'new' | 'public' @@ -1768,28 +1902,34 @@ interface_modifier | 'private' ; +// Source: 18.2.3.1 General variant_type_parameter_list : '<' variant_type_parameters '>' ; +// Source: 18.2.3.1 General variant_type_parameters : attributes? variance_annotation? type_parameter | variant_type_parameters ',' attributes? variance_annotation? type_parameter ; +// Source: 18.2.3.1 General variance_annotation : 'in' | 'out' ; +// Source: 18.2.4 Base interfaces interface_base : ':' interface_type_list ; +// Source: 18.3 Interface body interface_body : '{' interface_member_declaration* '}' ; +// Source: 18.4.1 General interface_member_declaration : interface_method_declaration | interface_property_declaration @@ -1797,14 +1937,17 @@ interface_member_declaration | interface_indexer_declaration ; +// Source: 18.4.2 Interface methods interface_method_declaration : attributes? 'new'? return_type identifier type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; +// Source: 18.4.3 Interface properties interface_property_declaration : attributes? 'new'? type identifier '{' interface_accessors '}' ; +// Source: 18.4.3 Interface properties interface_accessors : attributes? 'get' ';' | attributes? 'set' ';' @@ -1812,14 +1955,17 @@ interface_accessors | attributes? 'set' ';' attributes? 'get' ';' ; +// Source: 18.4.4 Interface events interface_event_declaration : attributes? 'new'? 'event' type identifier ';' ; +// Source: 18.4.5 Interface indexers interface_indexer_declaration: attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' ; +// Source: 19.2 Enum declarations enum_declaration : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? ; @@ -1833,6 +1979,7 @@ enum_body | '{' enum_member_declarations ',' '}' ; +// Source: 19.3 Enum modifiers enum_modifier : 'new' | 'public' @@ -1841,14 +1988,17 @@ enum_modifier | 'private' ; +// Source: 19.4 Enum members enum_member_declarations : enum_member_declaration (',' enum_member_declaration)* ; +// Source: 19.4 Enum members enum_member_declaration : attributes? identifier ('=' constant_expression)? ; +// Source: 20.2 Delegate declarations delegate_declaration : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; @@ -1861,6 +2011,7 @@ delegate_modifier | 'private' ; +// Source: 22.3 Attribute specification global_attributes : global_attribute_section+ ; @@ -1934,6 +2085,7 @@ attribute_argument_expression : expression ; +// Source: 23.2 Unsafe contexts class_modifier : ... | 'unsafe' @@ -2012,6 +2164,7 @@ unsafe_statement : 'unsafe' block ; +// Source: 23.3 Pointer types type : ... | pointer_type @@ -2022,6 +2175,7 @@ non_array_type | pointer_type ; +// Source: 23.3 Pointer types pointer_type : unmanaged_type '*' | 'void' '*' @@ -2031,6 +2185,7 @@ unmanaged_type : type ; +// Source: 23.6.1 General primary_no_array_creation_expression : ... | pointer_member_access @@ -2043,22 +2198,27 @@ unary_expression | addressof_expression ; +// Source: 23.6.2 Pointer indirection pointer_indirection_expression : '*' unary_expression ; +// Source: 23.6.3 Pointer member access pointer_member_access : primary_expression '->' identifier type_argument_list? ; +// Source: 23.6.4 Pointer element access pointer_element_access : primary_no_array_creation_expression '[' expression ']' ; +// Source: 23.6.5 The address-of operator addressof_expression : '&' unary_expression ; +// Source: 23.7 The fixed statement fixed_statement : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ; @@ -2076,6 +2236,7 @@ fixed_pointer_initializer | expression ; +// Source: 23.8.2 Fixed-size buffer declarations struct_member_declaration : ... | fixed_size_buffer_declaration @@ -2102,6 +2263,7 @@ fixed_size_buffer_declarator : identifier '[' constant_expression ']' ; +// Source: 23.9 Stack allocation local_variable_initializer : ... | stackalloc_initializer From 34e2fe6a2a09502dc67a9c549085a5ea7cb79dc9 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 27 Jan 2021 10:59:56 -0500 Subject: [PATCH 3/8] The getgrammar tool runs as a shell script. --- standard/grammar.md | 324 +++++++++--------- tools/GetGrammar/GetGrammar.bat | 166 ++++----- tools/GetGrammar/GetGrammar.sh | 103 ++++++ .../GetGrammar/{grammar.antlr => grammar.g4} | 324 +++++++++--------- 4 files changed, 510 insertions(+), 407 deletions(-) create mode 100755 tools/GetGrammar/GetGrammar.sh rename tools/GetGrammar/{grammar.antlr => grammar.g4} (87%) diff --git a/standard/grammar.md b/standard/grammar.md index c58844f41..1ade61301 100644 --- a/standard/grammar.md +++ b/standard/grammar.md @@ -10,7 +10,7 @@ This annex contains the grammar productions found in the specification, includin ```ANTLR -// Source: 7.3.1 General +// Source: §7.3.1 General input : input_section? ; @@ -30,7 +30,7 @@ input_element | token ; -// Source: 7.3.2 Line terminators +// Source: §7.3.2 Line terminators new_line : '' | '' @@ -40,7 +40,7 @@ new_line | '' ; -// Source: 7.3.3 Comments +// Source: §7.3.3 Comments comment : single_line_comment | delimited_comment @@ -79,7 +79,7 @@ not_slash_or_asterisk : '' ; -// Source: 7.3.4 White space +// Source: §7.3.4 White space whitespace : '' | '' @@ -87,7 +87,7 @@ whitespace | '' ; -// Source: 7.4.1 General +// Source: §7.4.1 General token : identifier | keyword @@ -98,13 +98,13 @@ token | operator_or_punctuator ; -// Source: 7.4.2 Unicode character escape sequences +// Source: §7.4.2 Unicode character escape sequences unicode_escape_sequence : '\\u' hex_digit hex_digit hex_digit hex_digit | '\\U' hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit ; -// Source: 7.4.3 Identifiers +// Source: §7.4.3 Identifiers identifier : available_identifier | '@' identifier_or_keyword @@ -161,7 +161,7 @@ formatting_character | '' ; -// Source: 7.4.4 Keywords +// Source: §7.4.4 Keywords keyword : 'abstract' | 'as' | 'base' | 'bool' | 'break' | 'byte' | 'case' | 'catch' | 'char' | 'checked' @@ -181,7 +181,7 @@ keyword | 'volatile' | 'while' ; -// Source: 7.4.4 Keywords +// Source: §7.4.4 Keywords contextual_keyword : 'add' 'alias' 'ascending' 'async' 'await' | 'by' 'descending' 'dynamic' 'equals' 'from' @@ -190,7 +190,7 @@ contextual_keyword | 'set' 'value' 'var' 'where' 'yield' ; -// Source: 7.4.5.1 General +// Source: §7.4.5.1 General literal : boolean_literal | integer_literal @@ -200,13 +200,13 @@ literal | null_literal ; -// Source: 7.4.5.2 Boolean literals +// Source: §7.4.5.2 Boolean literals boolean_literal : 'true' | 'false' ; -// Source: 7.4.5.3 Integer literals +// Source: §7.4.5.3 Integer literals integer_literal : decimal_integer_literal | hexadecimal_integer_literal @@ -233,7 +233,7 @@ hex_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'; -// Source: 7.4.5.4 Real literals +// Source: §7.4.5.4 Real literals real_literal : decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? | '.' decimal_digit+ exponent_part? real_type_suffix? @@ -254,7 +254,7 @@ real_type_suffix : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' ; -// Source: 7.4.5.5 Character literals +// Source: §7.4.5.5 Character literals character_literal : '\'' character '\'' ; @@ -278,7 +278,7 @@ hexadecimal_escape_sequence : '\\x' hex_digit hex_digit? hex_digit? hex_digit? ; -// Source: 7.4.5.6 String literals +// Source: §7.4.5.6 String literals string_literal : regular_string_literal | verbatim_string_literal @@ -316,12 +316,12 @@ quote_escape_sequence : '""' ; -// Source: 7.4.5.7 The null literal +// Source: §7.4.5.7 The null literal null_literal : 'null' ; -// Source: 7.4.6 Operators and punctuators +// Source: §7.4.6 Operators and punctuators operator_or_punctuator : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' @@ -338,7 +338,7 @@ right_shift_assignment : '>' '>=' ; -// Source: 7.5.1 General +// Source: §7.5.1 General pp_directive : pp_declaration | pp_conditional @@ -348,12 +348,12 @@ pp_directive | pp_pragma ; -// Source: 7.5.2 Conditional compilation symbols +// Source: §7.5.2 Conditional compilation symbols conditional_symbol : '' ; -// Source: 7.5.3 Pre-processing expressions +// Source: §7.5.3 Pre-processing expressions pp_expression : whitespace? pp_or_expression whitespace? ; @@ -386,7 +386,7 @@ pp_primary_expression | '(' whitespace? pp_expression whitespace? ')' ; -// Source: 7.5.4 Definition directives +// Source: §7.5.4 Definition directives pp_declaration : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line @@ -396,7 +396,7 @@ pp_new_line : whitespace? single_line_comment? new_line ; -// Source: 7.5.5 Conditional compilation directives +// Source: §7.5.5 Conditional compilation directives pp_conditional : pp_if_section pp_elif_section* pp_else_section? pp_endif ; @@ -435,7 +435,7 @@ not_number_sign : '' ; -// Source: 7.5.6 Diagnostic directives +// Source: §7.5.6 Diagnostic directives pp_diagnostic : whitespace? '#' whitespace? 'error' pp_message | whitespace? '#' whitespace? 'warning' pp_message @@ -446,7 +446,7 @@ pp_message | whitespace input_character* new_line ; -// Source: 7.5.7 Region directives +// Source: §7.5.7 Region directives pp_region : pp_start_region conditional_section? pp_end_region ; @@ -459,7 +459,7 @@ pp_end_region : whitespace? '#' whitespace? 'endregion' pp_message ; -// Source: 7.5.8 Line directives +// Source: §7.5.8 Line directives pp_line : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line ; @@ -479,7 +479,7 @@ compilation_unit_name_character : '' ; -// Source: 7.5.9 Pragma directives +// Source: §7.5.9 Pragma directives pp_pragma : whitespace? '#' whitespace? 'pragma' pp_pragma_text ; @@ -494,7 +494,7 @@ pp_pragma_text ```ANTLR -// Source: 8.8.1 General +// Source: §8.8.1 General namespace_name : namespace_or_type_name ; @@ -509,14 +509,14 @@ namespace_or_type_name | qualified_alias_member ; -// Source: 9.1 General +// Source: §9.1 General type : reference_type | value_type | type_parameter ; -// Source: 9.2.1 General +// Source: §9.2.1 General reference_type : class_type | interface_type @@ -556,7 +556,7 @@ delegate_type : type_name ; -// Source: 9.3.1 General +// Source: §9.3.1 General value_type : struct_type | enum_type @@ -608,7 +608,7 @@ enum_type : type_name ; -// Source: 9.4.2 Type arguments +// Source: §9.4.2 Type arguments type_argument_list : '<' type_arguments '>' ; @@ -621,17 +621,17 @@ type_argument : type ; -// Source: 9.5 Type parameters +// Source: §9.5 Type parameters type_parameter : identifier ; -// Source: 10.5 Variable references +// Source: §10.5 Variable references variable_reference : expression ; -// Source: 12.6.2.1 General +// Source: §12.6.2.1 General argument_list : argument (',' argument)* ; @@ -650,7 +650,7 @@ argument_value | 'out' variable_reference ; -// Source: 12.7.1 General +// Source: §12.7.1 General primary_expression : primary_no_array_creation_expression | array_creation_expression @@ -678,17 +678,17 @@ primary_no_array_creation_expression | anonymous_method_expression ; -// Source: 12.7.3.1 General +// Source: §12.7.3.1 General simple_name : identifier type_argument_list? ; -// Source: 12.7.4 Parenthesized expressions +// Source: §12.7.4 Parenthesized expressions parenthesized_expression : '(' expression ')' ; -// Source: 12.7.5.1 General +// Source: §12.7.5.1 General member_access : primary_expression '.' identifier type_argument_list? | predefined_type '.' identifier type_argument_list? @@ -700,28 +700,28 @@ predefined_type | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' ; -// Source: 12.7.6.1 General +// Source: §12.7.6.1 General invocation_expression : primary_expression '(' argument_list? ')' ; -// Source: 12.7.7.1 General +// Source: §12.7.7.1 General element_access : primary_no_array_creation_expression '[' argument_list ']' ; -// Source: 12.7.8 This access +// Source: §12.7.8 This access this_access : 'this' ; -// Source: 12.7.9 Base access +// Source: §12.7.9 Base access base_access : 'base' '.' identifier type_argument_list? | 'base' '[' argument_list ']' ; -// Source: 12.7.10 Postfix increment and decrement operators +// Source: §12.7.10 Postfix increment and decrement operators post_increment_expression : primary_expression '++' ; @@ -730,7 +730,7 @@ post_decrement_expression : primary_expression '--' ; -// Source: 12.7.11.2 Object creation expressions +// Source: §12.7.11.2 Object creation expressions object_creation_expression : 'new' type '(' argument_list? ')' object_or_collection_initializer? | 'new' type object_or_collection_initializer @@ -741,7 +741,7 @@ object_or_collection_initializer | collection_initializer ; -// Source: 12.7.11.3 Object initializers +// Source: §12.7.11.3 Object initializers object_initializer : '{' member_initializer_list? '}' | '{' member_initializer_list ',' '}' @@ -760,7 +760,7 @@ initializer_value | object_or_collection_initializer ; -// Source: 12.7.11.4 Collection initializers +// Source: §12.7.11.4 Collection initializers collection_initializer : '{' element_initializer_list '}' | '{' element_initializer_list ',' '}' @@ -780,19 +780,19 @@ expression_list | expression_list ',' expression ; -// Source: 12.7.11.5 Array creation expressions +// Source: §12.7.11.5 Array creation expressions array_creation_expression : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? | 'new' array_type array_initializer | 'new' rank_specifier array_initializer ; -// Source: 12.7.11.6 Delegate creation expressions +// Source: §12.7.11.6 Delegate creation expressions delegate_creation_expression : 'new' delegate_type '(' expression ')' ; -// Source: 12.7.11.7 Anonymous object creation expressions +// Source: §12.7.11.7 Anonymous object creation expressions anonymous_object_creation_expression : 'new' anonymous_object_initializer ; @@ -813,7 +813,7 @@ member_declarator | identifier '=' expression ; -// Source: 12.7.12 The typeof operator +// Source: §12.7.12 The typeof operator typeof_expression : 'typeof' '(' type ')' | 'typeof' '(' unbound_type_name ')' @@ -835,12 +835,12 @@ comma ; -// Source: 12.7.13 The sizeof operator +// Source: §12.7.13 The sizeof operator sizeof_expression : 'sizeof' '(' unmanaged_type ')' ; -// Source: 12.7.14 The checked and unchecked operators +// Source: §12.7.14 The checked and unchecked operators checked_expression : 'checked' '(' expression ')' ; @@ -849,12 +849,12 @@ unchecked_expression : 'unchecked' '(' expression ')' ; -// Source: 12.7.15 Default value expressions +// Source: §12.7.15 Default value expressions default_value_expression : 'default' '(' type ')' ; -// Source: 12.8.1 General +// Source: §12.8.1 General unary_expression : primary_expression | '+' unary_expression @@ -867,7 +867,7 @@ unary_expression | await_expression ; -// Source: 12.8.6 Prefix increment and decrement operators +// Source: §12.8.6 Prefix increment and decrement operators pre_increment_expression : '++' unary_expression ; @@ -876,17 +876,17 @@ pre_decrement_expression : '--' unary_expression ; -// Source: 12.8.7 Cast expressions +// Source: §12.8.7 Cast expressions cast_expression : '(' type ')' unary_expression ; -// Source: 12.8.8.1 General +// Source: §12.8.8.1 General await_expression : 'await' unary_expression ; -// Source: 12.9.1 General +// Source: §12.9.1 General multiplicative_expression : unary_expression | multiplicative_expression '*' unary_expression @@ -900,14 +900,14 @@ additive_expression | additive_expression '-' multiplicative_expression ; -// Source: 12.10 Shift operators +// Source: §12.10 Shift operators shift_expression : additive_expression | shift_expression '<<' additive_expression | shift_expression right_shift additive_expression ; -// Source: 12.11.1 General +// Source: §12.11.1 General relational_expression : shift_expression | relational_expression '<' shift_expression @@ -924,7 +924,7 @@ equality_expression | equality_expression '!=' relational_expression ; -// Source: 12.12.1 General +// Source: §12.12.1 General and_expression : equality_expression | and_expression '&' equality_expression @@ -940,7 +940,7 @@ inclusive_or_expression | inclusive_or_expression '|' exclusive_or_expression ; -// Source: 12.13.1 General +// Source: §12.13.1 General conditional_and_expression : inclusive_or_expression | conditional_and_expression '&&' inclusive_or_expression @@ -951,19 +951,19 @@ conditional_or_expression | conditional_or_expression '||' conditional_and_expression ; -// Source: 12.14 The null coalescing operator +// Source: §12.14 The null coalescing operator null_coalescing_expression : conditional_or_expression | conditional_or_expression '??' null_coalescing_expression ; -// Source: 12.15 Conditional operator +// Source: §12.15 Conditional operator conditional_expression : null_coalescing_expression | null_coalescing_expression '?' expression ':' expression ; -// Source: 12.16.1 General +// Source: §12.16.1 General lambda_expression : 'async'? anonymous_function_signature '=>' anonymous_function_body ; @@ -1012,7 +1012,7 @@ anonymous_function_body | block ; -// Source: 12.17.1 General +// Source: §12.17.1 General query_expression : from_clause query_body ; @@ -1089,7 +1089,7 @@ query_continuation : 'into' identifier query_body ; -// Source: 12.18.1 General +// Source: §12.18.1 General assignment : unary_expression assignment_operator expression ; @@ -1099,7 +1099,7 @@ assignment_operator | right_shift_assignment ; -// Source: 12.19 Expression +// Source: §12.19 Expression expression : non_assignment_expression | assignment @@ -1111,17 +1111,17 @@ non_assignment_expression | query_expression ; -// Source: 12.20 Constant expressions +// Source: §12.20 Constant expressions constant_expression : expression ; -// Source: 12.21 Boolean expressions +// Source: §12.21 Boolean expressions boolean_expression : expression ; -// Source: 13.1 General +// Source: §13.1 General statement : labeled_statement | declaration_statement @@ -1143,33 +1143,33 @@ embedded_statement | yield_statement ; -// Source: 13.3.1 General +// Source: §13.3.1 General block : '{' statement_list? '}' ; -// Source: 13.3.2 Statement lists +// Source: §13.3.2 Statement lists statement_list : statement+ ; -// Source: 13.4 The empty statement +// Source: §13.4 The empty statement empty_statement : ';' ; -// Source: 13.5 Labeled statements +// Source: §13.5 Labeled statements labeled_statement : identifier ':' statement ; -// Source: 13.6.1 General +// Source: §13.6.1 General declaration_statement : local_variable_declaration ';' | local_constant_declaration ';' ; -// Source: 13.6.2 Local variable declarations +// Source: §13.6.2 Local variable declarations local_variable_declaration : local_variable_type local_variable_declarators ; @@ -1194,7 +1194,7 @@ local_variable_initializer | array_initializer ; -// Source: 13.6.3 Local constant declarations +// Source: §13.6.3 Local constant declarations local_constant_declaration : 'const' type constant_declarators ; @@ -1207,7 +1207,7 @@ constant_declarator : identifier '=' constant_expression ; -// Source: 13.7 Expression statements +// Source: §13.7 Expression statements expression_statement : statement_expression ';' ; @@ -1223,19 +1223,19 @@ statement_expression | await_expression ; -// Source: 13.8.1 General +// Source: §13.8.1 General selection_statement : if_statement | switch_statement ; -// Source: 13.8.2 The if statement +// Source: §13.8.2 The if statement if_statement : 'if' '(' boolean_expression ')' embedded_statement | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement ; -// Source: 13.8.3 The switch statement +// Source: §13.8.3 The switch statement switch_statement : 'switch' '(' expression ')' switch_block ; @@ -1253,7 +1253,7 @@ switch_label | 'default' ':' ; -// Source: 13.9.1 General +// Source: §13.9.1 General iteration_statement : while_statement | do_statement @@ -1261,17 +1261,17 @@ iteration_statement | foreach_statement ; -// Source: 13.9.2 The while statement +// Source: §13.9.2 The while statement while_statement : 'while' '(' boolean_expression ')' embedded_statement ; -// Source: 13.9.3 The do statement +// Source: §13.9.3 The do statement do_statement : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' ; -// Source: 13.9.4 The for statement +// Source: §13.9.4 The for statement for_statement : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement ; @@ -1293,12 +1293,12 @@ statement_expression_list : statement_expression (',' statement_expression)* ; -// Source: 13.9.5 The foreach statement +// Source: §13.9.5 The foreach statement foreach_statement : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement ; -// Source: 13.10.1 General +// Source: §13.10.1 General jump_statement : break_statement | continue_statement @@ -1307,34 +1307,34 @@ jump_statement | throw_statement ; -// Source: 13.10.2 The break statement +// Source: §13.10.2 The break statement break_statement : 'break' ';' ; -// Source: 13.10.3 The continue statement +// Source: §13.10.3 The continue statement continue_statement : 'continue' ';' ; -// Source: 13.10.4 The goto statement +// Source: §13.10.4 The goto statement goto_statement : 'goto' identifier ';' | 'goto' 'case' constant_expression ';' | 'goto' 'default' ';' ; -// Source: 13.10.5 The return statement +// Source: §13.10.5 The return statement return_statement : 'return' expression? ';' ; -// Source: 13.10.6 The throw statement +// Source: §13.10.6 The throw statement throw_statement : 'throw' expression? ';' ; -// Source: 13.11 The try statement +// Source: §13.11 The try statement try_statement : 'try' block catch_clause+ | 'try' block finally_clause @@ -1349,7 +1349,7 @@ exception_specifier : '(' type identifier? ')' ; -// Source: 13.12 The checked and unchecked statements +// Source: §13.12 The checked and unchecked statements checked_statement : 'checked' block ; @@ -1358,12 +1358,12 @@ unchecked_statement : 'unchecked' block ; -// Source: 13.13 The lock statement +// Source: §13.13 The lock statement lock_statement : 'lock' '(' expression ')' embedded_statement ; -// Source: 13.14 The using statement +// Source: §13.14 The using statement using_statement : 'using' '(' resource_acquisition ')' embedded_statement ; @@ -1373,18 +1373,18 @@ resource_acquisition | expression ; -// Source: 13.15 The yield statement +// Source: §13.15 The yield statement yield_statement : 'yield' 'return' expression ';' | 'yield' 'break' ';' ; -// Source: 14.2 Compilation units +// Source: §14.2 Compilation units compilation_unit : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* ; -// Source: 14.3 Namespace declarations +// Source: §14.3 Namespace declarations namespace_declaration : 'namespace' qualified_identifier namespace_body ';'? ; @@ -1397,34 +1397,34 @@ namespace_body : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' ; -// Source: 14.4 Extern alias directives +// Source: §14.4 Extern alias directives extern_alias_directive : 'extern' 'alias' identifier ';' ; -// Source: 14.5.1 General +// Source: §14.5.1 General using_directive : using_alias-directive | using_namespace-directive ; -// Source: 14.5.2 Using alias directives +// Source: §14.5.2 Using alias directives using_alias_directive : 'using' identifier '=' namespace_or_type_name ';' ; -// Source: 14.5.3 Using namespace directives +// Source: §14.5.3 Using namespace directives using_namespace_directive : 'using' namespace_name ';' ; -// Source: 14.6 Namespace member declarations +// Source: §14.6 Namespace member declarations namespace_member_declaration : namespace_declaration | type_declaration ; -// Source: 14.7 Type declarations +// Source: §14.7 Type declarations type_declaration : class_declaration | struct_declaration @@ -1433,18 +1433,18 @@ type_declaration | delegate_declaration ; -// Source: 14.8.1 General +// Source: §14.8.1 General qualified_alias_member : identifier '::' identifier type_argument_list? ; -// Source: 15.2.1 General +// Source: §15.2.1 General class_declaration : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? class_base? type_parameter_constraints_clause* class_body ';'? ; -// Source: 15.2.2.1 General +// Source: §15.2.2.1 General class_modifier : 'new' | 'public' @@ -1456,7 +1456,7 @@ class_modifier | 'static' ; -// Source: 15.2.3 Type parameters +// Source: §15.2.3 Type parameters type_parameter_list : '<' type_parameters '>' ; @@ -1466,7 +1466,7 @@ type_parameters | type_parameters ',' attributes? type_parameter ; -// Source: 15.2.4.1 General +// Source: §15.2.4.1 General class_base : ':' class_type | ':' interface_type_list @@ -1477,7 +1477,7 @@ interface_type_list : interface_type (',' interface_type)* ; -// Source: 15.2.5 Type parameter constraints +// Source: §15.2.5 Type parameter constraints type_parameter_constraints_clauses : type_parameter_constraints_clause | type_parameter_constraints_clauses type_parameter_constraints_clause @@ -1514,12 +1514,12 @@ constructor_constraint : 'new' '(' ')' ; -// Source: 15.2.6 Class body +// Source: §15.2.6 Class body class_body : '{' class_member_declaration* '}' ; -// Source: 15.3.1 General +// Source: §15.3.1 General class_member_declaration : constant_declaration | field_declaration @@ -1534,7 +1534,7 @@ class_member_declaration | type_declaration ; -// Source: 15.4 Constants +// Source: §15.4 Constants constant_declaration : attributes? constant_modifier* 'const' type constant_declarators ';' ; @@ -1547,7 +1547,7 @@ constant_modifier | 'private' ; -// Source: 15.5.1 General +// Source: §15.5.1 General field_declaration : attributes? field_modifier* type variable_declarators ';' ; @@ -1571,7 +1571,7 @@ variable_declarator : identifier ('=' variable_initializer)? ; -// Source: 15.6.1 General +// Source: §15.6.1 General method_declaration : method_header method_body ; @@ -1609,7 +1609,7 @@ method_body : block ; -// Source: 15.6.2.1 General +// Source: §15.6.2.1 General formal_parameter_list : fixed_parameters | fixed_parameters ',' parameter_array @@ -1642,7 +1642,7 @@ parameter_array : attributes? 'params' array_type identifier ; -// Source: 15.7.1 General +// Source: §15.7.1 General property_declaration : attributes? property_modifiers? type member_name '{' accessor_declarations '}' ; @@ -1666,7 +1666,7 @@ property_modifier | 'extern' ; -// Source: 15.7.3 Accessors +// Source: §15.7.3 Accessors accessor_declarations : get_accessor_declaration set_accessor_declaration? | set_accessor_declaration get_accessor_declaration? @@ -1693,7 +1693,7 @@ accessor_body | ';' ; -// Source: 15.8.1 General +// Source: §15.8.1 General event_declaration : attributes? event_modifier* 'event' type variable_declarators ';' | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' @@ -1726,7 +1726,7 @@ remove_accessor_declaration : attributes? 'remove' block ; -// Source: 15.9 Indexers +// Source: §15.9 Indexers indexer_declaration : attributes? indexer_modifiers? indexer_declarator '{' accessor_declarations '}' ; @@ -1754,7 +1754,7 @@ indexer_declarator | type interface_type '.' 'this' '[' formal_parameter_list ']' ; -// Source: 15.10.1 General +// Source: §15.10.1 General operator_declaration : attributes? operator_modifier+ operator_declarator operator_body ; @@ -1798,7 +1798,7 @@ operator_body | ';' ; -// Source: 15.11.1 General +// Source: §15.11.1 General constructor_declaration : attributes? constructor_modifier* constructor_declarator constructor_body ; @@ -1825,7 +1825,7 @@ constructor_body | ';' ; -// Source: 15.12 Static constructors +// Source: §15.12 Static constructors static_constructor_declaration : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body ; @@ -1840,7 +1840,7 @@ static_constructor_body | ';' ; -// Source: 15.13 Finalizers +// Source: §15.13 Finalizers finalizer_declaration : attributes? 'extern'? '~' identifier '(' ')' finalizer_body ; @@ -1850,13 +1850,13 @@ finalizer_body | ';' ; -// Source: 16.2.1 General +// Source: §16.2.1 General struct_declaration : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? struct_interfaces? type_parameter_constraints_clause* struct_body ';'? ; -// Source: 16.2.2 Struct modifiers +// Source: §16.2.2 Struct modifiers struct_modifier : 'new' | 'public' @@ -1865,17 +1865,17 @@ struct_modifier | 'private' ; -// Source: 16.2.4 Struct interfaces +// Source: §16.2.4 Struct interfaces struct_interfaces : ':' interface_type_list ; -// Source: 16.2.5 Struct body +// Source: §16.2.5 Struct body struct_body : '{' struct_member_declaration* '}' ; -// Source: 16.3 Struct members +// Source: §16.3 Struct members struct_member_declaration : constant_declaration | field_declaration @@ -1889,7 +1889,7 @@ struct_member_declaration | type_declaration ; -// Source: 17.7 Array initializers +// Source: §17.7 Array initializers array_initializer : '{' variable_initializer_list? '}' | '{' variable_initializer_list ',' '}' @@ -1904,12 +1904,12 @@ variable_initializer | array_initializer ; -// Source: 18.2.1 General +// Source: §18.2.1 General interface_declaration : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? ; -// Source: 18.2.2 Interface modifiers +// Source: §18.2.2 Interface modifiers interface_modifier : 'new' | 'public' @@ -1918,34 +1918,34 @@ interface_modifier | 'private' ; -// Source: 18.2.3.1 General +// Source: §18.2.3.1 General variant_type_parameter_list : '<' variant_type_parameters '>' ; -// Source: 18.2.3.1 General +// Source: §18.2.3.1 General variant_type_parameters : attributes? variance_annotation? type_parameter | variant_type_parameters ',' attributes? variance_annotation? type_parameter ; -// Source: 18.2.3.1 General +// Source: §18.2.3.1 General variance_annotation : 'in' | 'out' ; -// Source: 18.2.4 Base interfaces +// Source: §18.2.4 Base interfaces interface_base : ':' interface_type_list ; -// Source: 18.3 Interface body +// Source: §18.3 Interface body interface_body : '{' interface_member_declaration* '}' ; -// Source: 18.4.1 General +// Source: §18.4.1 General interface_member_declaration : interface_method_declaration | interface_property_declaration @@ -1953,17 +1953,17 @@ interface_member_declaration | interface_indexer_declaration ; -// Source: 18.4.2 Interface methods +// Source: §18.4.2 Interface methods interface_method_declaration : attributes? 'new'? return_type identifier type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; -// Source: 18.4.3 Interface properties +// Source: §18.4.3 Interface properties interface_property_declaration : attributes? 'new'? type identifier '{' interface_accessors '}' ; -// Source: 18.4.3 Interface properties +// Source: §18.4.3 Interface properties interface_accessors : attributes? 'get' ';' | attributes? 'set' ';' @@ -1971,17 +1971,17 @@ interface_accessors | attributes? 'set' ';' attributes? 'get' ';' ; -// Source: 18.4.4 Interface events +// Source: §18.4.4 Interface events interface_event_declaration : attributes? 'new'? 'event' type identifier ';' ; -// Source: 18.4.5 Interface indexers +// Source: §18.4.5 Interface indexers interface_indexer_declaration: attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' ; -// Source: 19.2 Enum declarations +// Source: §19.2 Enum declarations enum_declaration : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? ; @@ -1995,7 +1995,7 @@ enum_body | '{' enum_member_declarations ',' '}' ; -// Source: 19.3 Enum modifiers +// Source: §19.3 Enum modifiers enum_modifier : 'new' | 'public' @@ -2004,17 +2004,17 @@ enum_modifier | 'private' ; -// Source: 19.4 Enum members +// Source: §19.4 Enum members enum_member_declarations : enum_member_declaration (',' enum_member_declaration)* ; -// Source: 19.4 Enum members +// Source: §19.4 Enum members enum_member_declaration : attributes? identifier ('=' constant_expression)? ; -// Source: 20.2 Delegate declarations +// Source: §20.2 Delegate declarations delegate_declaration : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; @@ -2027,7 +2027,7 @@ delegate_modifier | 'private' ; -// Source: 22.3 Attribute specification +// Source: §22.3 Attribute specification global_attributes : global_attribute_section+ ; @@ -2106,7 +2106,7 @@ attribute_argument_expression ```ANTLR -// Source: 23.2 Unsafe contexts +// Source: §23.2 Unsafe contexts class_modifier : ... | 'unsafe' @@ -2185,7 +2185,7 @@ unsafe_statement : 'unsafe' block ; -// Source: 23.3 Pointer types +// Source: §23.3 Pointer types type : ... | pointer_type @@ -2196,7 +2196,7 @@ non_array_type | pointer_type ; -// Source: 23.3 Pointer types +// Source: §23.3 Pointer types pointer_type : unmanaged_type '*' | 'void' '*' @@ -2206,7 +2206,7 @@ unmanaged_type : type ; -// Source: 23.6.1 General +// Source: §23.6.1 General primary_no_array_creation_expression : ... | pointer_member_access @@ -2219,27 +2219,27 @@ unary_expression | addressof_expression ; -// Source: 23.6.2 Pointer indirection +// Source: §23.6.2 Pointer indirection pointer_indirection_expression : '*' unary_expression ; -// Source: 23.6.3 Pointer member access +// Source: §23.6.3 Pointer member access pointer_member_access : primary_expression '->' identifier type_argument_list? ; -// Source: 23.6.4 Pointer element access +// Source: §23.6.4 Pointer element access pointer_element_access : primary_no_array_creation_expression '[' expression ']' ; -// Source: 23.6.5 The address-of operator +// Source: §23.6.5 The address-of operator addressof_expression : '&' unary_expression ; -// Source: 23.7 The fixed statement +// Source: §23.7 The fixed statement fixed_statement : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ; @@ -2257,7 +2257,7 @@ fixed_pointer_initializer | expression ; -// Source: 23.8.2 Fixed-size buffer declarations +// Source: §23.8.2 Fixed-size buffer declarations struct_member_declaration : ... | fixed_size_buffer_declaration @@ -2284,7 +2284,7 @@ fixed_size_buffer_declarator : identifier '[' constant_expression ']' ; -// Source: 23.9 Stack allocation +// Source: §23.9 Stack allocation local_variable_initializer : ... | stackalloc_initializer diff --git a/tools/GetGrammar/GetGrammar.bat b/tools/GetGrammar/GetGrammar.bat index bb6c9378c..da9db4f18 100644 --- a/tools/GetGrammar/GetGrammar.bat +++ b/tools/GetGrammar/GetGrammar.bat @@ -2,102 +2,102 @@ echo off dotnet build -c Release dotnet publish -o publish -del grammar.antlr +del grammar.g4 del ..\..\standard\grammar.md echo Insert General/Lexical Headers type grammar-general-lexical-insert.md >..\..\standard\grammar.md echo Extract Lexical Grammar -publish\GetGrammar ..\..\standard\lexical-structure.md >lexical-structure.antlr -type lexical-structure.antlr >grammar.antlr -type lexical-structure.antlr >>..\..\standard\grammar.md -del lexical-structure.antlr +publish\GetGrammar ..\..\standard\lexical-structure.md >lexical-structure.g4 +type lexical-structure.g4 >grammar.g4 +type lexical-structure.g4 >>..\..\standard\grammar.md +del lexical-structure.g4 echo Insert Syntactic Header type grammar-syntactic-insert.md >>..\..\standard\grammar.md echo Extract Syntactic Grammar -publish\GetGrammar ..\..\standard\basic-concepts.md >basic-concepts.antlr -type basic-concepts.antlr >>grammar.antlr -type basic-concepts.antlr >>..\..\standard\grammar.md -del basic-concepts.antlr - -publish\GetGrammar ..\..\standard\types.md >types.antlr -type types.antlr >>grammar.antlr -type types.antlr >>..\..\standard\grammar.md -del types.antlr - -publish\GetGrammar ..\..\standard\variables.md >variables.antlr -type variables.antlr >>grammar.antlr -type variables.antlr >>..\..\standard\grammar.md -del variables.antlr - -publish\GetGrammar ..\..\standard\conversions.md >conversions.antlr -type conversions.antlr >>grammar.antlr -type conversions.antlr >>..\..\standard\grammar.md -del conversions.antlr - -publish\GetGrammar ..\..\standard\expressions.md >expressions.antlr -type expressions.antlr >>grammar.antlr -type expressions.antlr >>..\..\standard\grammar.md -del expressions.antlr - -publish\GetGrammar ..\..\standard\statements.md >statements.antlr -type statements.antlr >>grammar.antlr -type statements.antlr >>..\..\standard\grammar.md -del statements.antlr - -publish\GetGrammar ..\..\standard\namespaces.md >namespaces.antlr -type namespaces.antlr >>grammar.antlr -type namespaces.antlr >>..\..\standard\grammar.md -del namespaces.antlr - -publish\GetGrammar ..\..\standard\classes.md >classes.antlr -type classes.antlr >>grammar.antlr -type classes.antlr >>..\..\standard\grammar.md -del classes.antlr - -publish\GetGrammar ..\..\standard\structs.md >structs.antlr -type structs.antlr >>grammar.antlr -type structs.antlr >>..\..\standard\grammar.md -del structs.antlr - -publish\GetGrammar ..\..\standard\arrays.md >arrays.antlr -type arrays.antlr >>grammar.antlr -type arrays.antlr >>..\..\standard\grammar.md -del arrays.antlr - -publish\GetGrammar ..\..\standard\interfaces.md >interfaces.antlr -type interfaces.antlr >>grammar.antlr -type interfaces.antlr >>..\..\standard\grammar.md -del interfaces.antlr - -publish\GetGrammar ..\..\standard\enums.md >enums.antlr -type enums.antlr >>grammar.antlr -type enums.antlr >>..\..\standard\grammar.md -del enums.antlr - -publish\GetGrammar ..\..\standard\delegates.md >delegates.antlr -type delegates.antlr >>grammar.antlr -type delegates.antlr >>..\..\standard\grammar.md -del delegates.antlr - -publish\GetGrammar ..\..\standard\exceptions.md >exceptions.antlr -type exceptions.antlr >>grammar.antlr -type exceptions.antlr >>..\..\standard\grammar.md -del exceptions.antlr - -publish\GetGrammar ..\..\standard\attributes.md >attributes.antlr -type attributes.antlr >>grammar.antlr -type attributes.antlr >>..\..\standard\grammar.md -del attributes.antlr +publish\GetGrammar ..\..\standard\basic-concepts.md >basic-concepts.g4 +type basic-concepts.g4 >>grammar.g4 +type basic-concepts.g4 >>..\..\standard\grammar.md +del basic-concepts.g4 + +publish\GetGrammar ..\..\standard\types.md >types.g4 +type types.g4 >>grammar.g4 +type types.g4 >>..\..\standard\grammar.md +del types.g4 + +publish\GetGrammar ..\..\standard\variables.md >variables.g4 +type variables.g4 >>grammar.g4 +type variables.g4 >>..\..\standard\grammar.md +del variables.g4 + +publish\GetGrammar ..\..\standard\conversions.md >conversions.g4 +type conversions.g4 >>grammar.g4 +type conversions.g4 >>..\..\standard\grammar.md +del conversions.g4 + +publish\GetGrammar ..\..\standard\expressions.md >expressions.g4 +type expressions.g4 >>grammar.g4 +type expressions.g4 >>..\..\standard\grammar.md +del expressions.g4 + +publish\GetGrammar ..\..\standard\statements.md >statements.g4 +type statements.g4 >>grammar.g4 +type statements.g4 >>..\..\standard\grammar.md +del statements.g4 + +publish\GetGrammar ..\..\standard\namespaces.md >namespaces.g4 +type namespaces.g4 >>grammar.g4 +type namespaces.g4 >>..\..\standard\grammar.md +del namespaces.g4 + +publish\GetGrammar ..\..\standard\classes.md >classes.g4 +type classes.g4 >>grammar.g4 +type classes.g4 >>..\..\standard\grammar.md +del classes.g4 + +publish\GetGrammar ..\..\standard\structs.md >structs.g4 +type structs.g4 >>grammar.g4 +type structs.g4 >>..\..\standard\grammar.md +del structs.g4 + +publish\GetGrammar ..\..\standard\arrays.md >arrays.g4 +type arrays.g4 >>grammar.g4 +type arrays.g4 >>..\..\standard\grammar.md +del arrays.g4 + +publish\GetGrammar ..\..\standard\interfaces.md >interfaces.g4 +type interfaces.g4 >>grammar.g4 +type interfaces.g4 >>..\..\standard\grammar.md +del interfaces.g4 + +publish\GetGrammar ..\..\standard\enums.md >enums.g4 +type enums.g4 >>grammar.g4 +type enums.g4 >>..\..\standard\grammar.md +del enums.g4 + +publish\GetGrammar ..\..\standard\delegates.md >delegates.g4 +type delegates.g4 >>grammar.g4 +type delegates.g4 >>..\..\standard\grammar.md +del delegates.g4 + +publish\GetGrammar ..\..\standard\exceptions.md >exceptions.g4 +type exceptions.g4 >>grammar.g4 +type exceptions.g4 >>..\..\standard\grammar.md +del exceptions.g4 + +publish\GetGrammar ..\..\standard\attributes.md >attributes.g4 +type attributes.g4 >>grammar.g4 +type attributes.g4 >>..\..\standard\grammar.md +del attributes.g4 echo Insert Unsafe Header type grammar-unsafe-extensions-insert.md >>..\..\standard\grammar.md echo Extract Unsafe Grammar -publish\GetGrammar ..\..\standard\unsafe-code.md >unsafe-code.antlr -type unsafe-code.antlr >>grammar.antlr -type unsafe-code.antlr >>..\..\standard\grammar.md -del unsafe-code.antlr +publish\GetGrammar ..\..\standard\unsafe-code.md >unsafe-code.g4 +type unsafe-code.g4 >>grammar.g4 +type unsafe-code.g4 >>..\..\standard\grammar.md +del unsafe-code.g4 echo Insert EOF Stuff type grammar-eof-insert.md >>..\..\standard\grammar.md diff --git a/tools/GetGrammar/GetGrammar.sh b/tools/GetGrammar/GetGrammar.sh new file mode 100755 index 000000000..f6ee57605 --- /dev/null +++ b/tools/GetGrammar/GetGrammar.sh @@ -0,0 +1,103 @@ +#!/bin/sh +dotnet build -c Release +dotnet publish -o publish + +rm grammar.g4 +rm ../../standard/grammar.md +echo Insert General/Lexical Headers +cat grammar-general-lexical-insert.md >../../standard/grammar.md +echo Extract Lexical Grammar +dotnet publish/GetGrammar.dll ../../standard/lexical-structure.md >lexical-structure.g4 +cat lexical-structure.g4 >grammar.g4 +cat lexical-structure.g4 >>../../standard/grammar.md +rm lexical-structure.g4 + +echo Insert Syntactic Header +cat grammar-syntactic-insert.md >>../../standard/grammar.md +echo Extract Syntactic Grammar + +dotnet publish/GetGrammar.dll ../../standard/basic-concepts.md >basic-concepts.g4 +cat basic-concepts.g4 >>grammar.g4 +cat basic-concepts.g4 >>../../standard/grammar.md +rm basic-concepts.g4 + +dotnet publish/GetGrammar.dll ../../standard/types.md >types.g4 +cat types.g4 >>grammar.g4 +cat types.g4 >>../../standard/grammar.md +rm types.g4 + +dotnet publish/GetGrammar.dll ../../standard/variables.md >variables.g4 +cat variables.g4 >>grammar.g4 +cat variables.g4 >>../../standard/grammar.md +rm variables.g4 + +dotnet publish/GetGrammar.dll ../../standard/conversions.md >conversions.g4 +cat conversions.g4 >>grammar.g4 +cat conversions.g4 >>../../standard/grammar.md +rm conversions.g4 + +dotnet publish/GetGrammar.dll ../../standard/expressions.md >expressions.g4 +cat expressions.g4 >>grammar.g4 +cat expressions.g4 >>../../standard/grammar.md +rm expressions.g4 + +dotnet publish/GetGrammar.dll ../../standard/statements.md >statements.g4 +cat statements.g4 >>grammar.g4 +cat statements.g4 >>../../standard/grammar.md +rm statements.g4 + +dotnet publish/GetGrammar.dll ../../standard/namespaces.md >namespaces.g4 +cat namespaces.g4 >>grammar.g4 +cat namespaces.g4 >>../../standard/grammar.md +rm namespaces.g4 + +dotnet publish/GetGrammar.dll ../../standard/classes.md >classes.g4 +cat classes.g4 >>grammar.g4 +cat classes.g4 >>../../standard/grammar.md +rm classes.g4 + +dotnet publish/GetGrammar.dll ../../standard/structs.md >structs.g4 +cat structs.g4 >>grammar.g4 +cat structs.g4 >>../../standard/grammar.md +rm structs.g4 + +dotnet publish/GetGrammar.dll ../../standard/arrays.md >arrays.g4 +cat arrays.g4 >>grammar.g4 +cat arrays.g4 >>../../standard/grammar.md +rm arrays.g4 + +dotnet publish/GetGrammar.dll ../../standard/interfaces.md >interfaces.g4 +cat interfaces.g4 >>grammar.g4 +cat interfaces.g4 >>../../standard/grammar.md +rm interfaces.g4 + +dotnet publish/GetGrammar.dll ../../standard/enums.md >enums.g4 +cat enums.g4 >>grammar.g4 +cat enums.g4 >>../../standard/grammar.md +rm enums.g4 + +dotnet publish/GetGrammar.dll ../../standard/delegates.md >delegates.g4 +cat delegates.g4 >>grammar.g4 +cat delegates.g4 >>../../standard/grammar.md +rm delegates.g4 + +dotnet publish/GetGrammar.dll ../../standard/exceptions.md >exceptions.g4 +cat exceptions.g4 >>grammar.g4 +cat exceptions.g4 >>../../standard/grammar.md +rm exceptions.g4 + +dotnet publish/GetGrammar.dll ../../standard/attributes.md >attributes.g4 +cat attributes.g4 >>grammar.g4 +cat attributes.g4 >>../../standard/grammar.md +rm attributes.g4 + +echo Insert Unsafe Header +cat grammar-unsafe-extensions-insert.md >>../../standard/grammar.md +echo Extract Unsafe Grammar +dotnet publish/GetGrammar.dll ../../standard/unsafe-code.md >unsafe-code.g4 +cat unsafe-code.g4 >>grammar.g4 +cat unsafe-code.g4 >>../../standard/grammar.md +rm unsafe-code.g4 + +echo Insert EOF Stuff +cat grammar-eof-insert.md >>../../standard/grammar.md diff --git a/tools/GetGrammar/grammar.antlr b/tools/GetGrammar/grammar.g4 similarity index 87% rename from tools/GetGrammar/grammar.antlr rename to tools/GetGrammar/grammar.g4 index b3ad3a3c2..bed6e4646 100644 --- a/tools/GetGrammar/grammar.antlr +++ b/tools/GetGrammar/grammar.g4 @@ -1,5 +1,5 @@ -// Source: 7.3.1 General +// Source: §7.3.1 General input : input_section? ; @@ -19,7 +19,7 @@ input_element | token ; -// Source: 7.3.2 Line terminators +// Source: §7.3.2 Line terminators new_line : '' | '' @@ -29,7 +29,7 @@ new_line | '' ; -// Source: 7.3.3 Comments +// Source: §7.3.3 Comments comment : single_line_comment | delimited_comment @@ -68,7 +68,7 @@ not_slash_or_asterisk : '' ; -// Source: 7.3.4 White space +// Source: §7.3.4 White space whitespace : '' | '' @@ -76,7 +76,7 @@ whitespace | '' ; -// Source: 7.4.1 General +// Source: §7.4.1 General token : identifier | keyword @@ -87,13 +87,13 @@ token | operator_or_punctuator ; -// Source: 7.4.2 Unicode character escape sequences +// Source: §7.4.2 Unicode character escape sequences unicode_escape_sequence : '\\u' hex_digit hex_digit hex_digit hex_digit | '\\U' hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit ; -// Source: 7.4.3 Identifiers +// Source: §7.4.3 Identifiers identifier : available_identifier | '@' identifier_or_keyword @@ -150,7 +150,7 @@ formatting_character | '' ; -// Source: 7.4.4 Keywords +// Source: §7.4.4 Keywords keyword : 'abstract' | 'as' | 'base' | 'bool' | 'break' | 'byte' | 'case' | 'catch' | 'char' | 'checked' @@ -170,7 +170,7 @@ keyword | 'volatile' | 'while' ; -// Source: 7.4.4 Keywords +// Source: §7.4.4 Keywords contextual_keyword : 'add' 'alias' 'ascending' 'async' 'await' | 'by' 'descending' 'dynamic' 'equals' 'from' @@ -179,7 +179,7 @@ contextual_keyword | 'set' 'value' 'var' 'where' 'yield' ; -// Source: 7.4.5.1 General +// Source: §7.4.5.1 General literal : boolean_literal | integer_literal @@ -189,13 +189,13 @@ literal | null_literal ; -// Source: 7.4.5.2 Boolean literals +// Source: §7.4.5.2 Boolean literals boolean_literal : 'true' | 'false' ; -// Source: 7.4.5.3 Integer literals +// Source: §7.4.5.3 Integer literals integer_literal : decimal_integer_literal | hexadecimal_integer_literal @@ -222,7 +222,7 @@ hex_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'; -// Source: 7.4.5.4 Real literals +// Source: §7.4.5.4 Real literals real_literal : decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? | '.' decimal_digit+ exponent_part? real_type_suffix? @@ -243,7 +243,7 @@ real_type_suffix : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' ; -// Source: 7.4.5.5 Character literals +// Source: §7.4.5.5 Character literals character_literal : '\'' character '\'' ; @@ -267,7 +267,7 @@ hexadecimal_escape_sequence : '\\x' hex_digit hex_digit? hex_digit? hex_digit? ; -// Source: 7.4.5.6 String literals +// Source: §7.4.5.6 String literals string_literal : regular_string_literal | verbatim_string_literal @@ -305,12 +305,12 @@ quote_escape_sequence : '""' ; -// Source: 7.4.5.7 The null literal +// Source: §7.4.5.7 The null literal null_literal : 'null' ; -// Source: 7.4.6 Operators and punctuators +// Source: §7.4.6 Operators and punctuators operator_or_punctuator : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' @@ -327,7 +327,7 @@ right_shift_assignment : '>' '>=' ; -// Source: 7.5.1 General +// Source: §7.5.1 General pp_directive : pp_declaration | pp_conditional @@ -337,12 +337,12 @@ pp_directive | pp_pragma ; -// Source: 7.5.2 Conditional compilation symbols +// Source: §7.5.2 Conditional compilation symbols conditional_symbol : '' ; -// Source: 7.5.3 Pre-processing expressions +// Source: §7.5.3 Pre-processing expressions pp_expression : whitespace? pp_or_expression whitespace? ; @@ -375,7 +375,7 @@ pp_primary_expression | '(' whitespace? pp_expression whitespace? ')' ; -// Source: 7.5.4 Definition directives +// Source: §7.5.4 Definition directives pp_declaration : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line @@ -385,7 +385,7 @@ pp_new_line : whitespace? single_line_comment? new_line ; -// Source: 7.5.5 Conditional compilation directives +// Source: §7.5.5 Conditional compilation directives pp_conditional : pp_if_section pp_elif_section* pp_else_section? pp_endif ; @@ -424,7 +424,7 @@ not_number_sign : '' ; -// Source: 7.5.6 Diagnostic directives +// Source: §7.5.6 Diagnostic directives pp_diagnostic : whitespace? '#' whitespace? 'error' pp_message | whitespace? '#' whitespace? 'warning' pp_message @@ -435,7 +435,7 @@ pp_message | whitespace input_character* new_line ; -// Source: 7.5.7 Region directives +// Source: §7.5.7 Region directives pp_region : pp_start_region conditional_section? pp_end_region ; @@ -448,7 +448,7 @@ pp_end_region : whitespace? '#' whitespace? 'endregion' pp_message ; -// Source: 7.5.8 Line directives +// Source: §7.5.8 Line directives pp_line : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line ; @@ -468,7 +468,7 @@ compilation_unit_name_character : '' ; -// Source: 7.5.9 Pragma directives +// Source: §7.5.9 Pragma directives pp_pragma : whitespace? '#' whitespace? 'pragma' pp_pragma_text ; @@ -478,7 +478,7 @@ pp_pragma_text | whitespace input_character* new_line ; -// Source: 8.8.1 General +// Source: §8.8.1 General namespace_name : namespace_or_type_name ; @@ -493,14 +493,14 @@ namespace_or_type_name | qualified_alias_member ; -// Source: 9.1 General +// Source: §9.1 General type : reference_type | value_type | type_parameter ; -// Source: 9.2.1 General +// Source: §9.2.1 General reference_type : class_type | interface_type @@ -540,7 +540,7 @@ delegate_type : type_name ; -// Source: 9.3.1 General +// Source: §9.3.1 General value_type : struct_type | enum_type @@ -592,7 +592,7 @@ enum_type : type_name ; -// Source: 9.4.2 Type arguments +// Source: §9.4.2 Type arguments type_argument_list : '<' type_arguments '>' ; @@ -605,17 +605,17 @@ type_argument : type ; -// Source: 9.5 Type parameters +// Source: §9.5 Type parameters type_parameter : identifier ; -// Source: 10.5 Variable references +// Source: §10.5 Variable references variable_reference : expression ; -// Source: 12.6.2.1 General +// Source: §12.6.2.1 General argument_list : argument (',' argument)* ; @@ -634,7 +634,7 @@ argument_value | 'out' variable_reference ; -// Source: 12.7.1 General +// Source: §12.7.1 General primary_expression : primary_no_array_creation_expression | array_creation_expression @@ -662,17 +662,17 @@ primary_no_array_creation_expression | anonymous_method_expression ; -// Source: 12.7.3.1 General +// Source: §12.7.3.1 General simple_name : identifier type_argument_list? ; -// Source: 12.7.4 Parenthesized expressions +// Source: §12.7.4 Parenthesized expressions parenthesized_expression : '(' expression ')' ; -// Source: 12.7.5.1 General +// Source: §12.7.5.1 General member_access : primary_expression '.' identifier type_argument_list? | predefined_type '.' identifier type_argument_list? @@ -684,28 +684,28 @@ predefined_type | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' ; -// Source: 12.7.6.1 General +// Source: §12.7.6.1 General invocation_expression : primary_expression '(' argument_list? ')' ; -// Source: 12.7.7.1 General +// Source: §12.7.7.1 General element_access : primary_no_array_creation_expression '[' argument_list ']' ; -// Source: 12.7.8 This access +// Source: §12.7.8 This access this_access : 'this' ; -// Source: 12.7.9 Base access +// Source: §12.7.9 Base access base_access : 'base' '.' identifier type_argument_list? | 'base' '[' argument_list ']' ; -// Source: 12.7.10 Postfix increment and decrement operators +// Source: §12.7.10 Postfix increment and decrement operators post_increment_expression : primary_expression '++' ; @@ -714,7 +714,7 @@ post_decrement_expression : primary_expression '--' ; -// Source: 12.7.11.2 Object creation expressions +// Source: §12.7.11.2 Object creation expressions object_creation_expression : 'new' type '(' argument_list? ')' object_or_collection_initializer? | 'new' type object_or_collection_initializer @@ -725,7 +725,7 @@ object_or_collection_initializer | collection_initializer ; -// Source: 12.7.11.3 Object initializers +// Source: §12.7.11.3 Object initializers object_initializer : '{' member_initializer_list? '}' | '{' member_initializer_list ',' '}' @@ -744,7 +744,7 @@ initializer_value | object_or_collection_initializer ; -// Source: 12.7.11.4 Collection initializers +// Source: §12.7.11.4 Collection initializers collection_initializer : '{' element_initializer_list '}' | '{' element_initializer_list ',' '}' @@ -764,19 +764,19 @@ expression_list | expression_list ',' expression ; -// Source: 12.7.11.5 Array creation expressions +// Source: §12.7.11.5 Array creation expressions array_creation_expression : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? | 'new' array_type array_initializer | 'new' rank_specifier array_initializer ; -// Source: 12.7.11.6 Delegate creation expressions +// Source: §12.7.11.6 Delegate creation expressions delegate_creation_expression : 'new' delegate_type '(' expression ')' ; -// Source: 12.7.11.7 Anonymous object creation expressions +// Source: §12.7.11.7 Anonymous object creation expressions anonymous_object_creation_expression : 'new' anonymous_object_initializer ; @@ -797,7 +797,7 @@ member_declarator | identifier '=' expression ; -// Source: 12.7.12 The typeof operator +// Source: §12.7.12 The typeof operator typeof_expression : 'typeof' '(' type ')' | 'typeof' '(' unbound_type_name ')' @@ -819,12 +819,12 @@ comma ; -// Source: 12.7.13 The sizeof operator +// Source: §12.7.13 The sizeof operator sizeof_expression : 'sizeof' '(' unmanaged_type ')' ; -// Source: 12.7.14 The checked and unchecked operators +// Source: §12.7.14 The checked and unchecked operators checked_expression : 'checked' '(' expression ')' ; @@ -833,12 +833,12 @@ unchecked_expression : 'unchecked' '(' expression ')' ; -// Source: 12.7.15 Default value expressions +// Source: §12.7.15 Default value expressions default_value_expression : 'default' '(' type ')' ; -// Source: 12.8.1 General +// Source: §12.8.1 General unary_expression : primary_expression | '+' unary_expression @@ -851,7 +851,7 @@ unary_expression | await_expression ; -// Source: 12.8.6 Prefix increment and decrement operators +// Source: §12.8.6 Prefix increment and decrement operators pre_increment_expression : '++' unary_expression ; @@ -860,17 +860,17 @@ pre_decrement_expression : '--' unary_expression ; -// Source: 12.8.7 Cast expressions +// Source: §12.8.7 Cast expressions cast_expression : '(' type ')' unary_expression ; -// Source: 12.8.8.1 General +// Source: §12.8.8.1 General await_expression : 'await' unary_expression ; -// Source: 12.9.1 General +// Source: §12.9.1 General multiplicative_expression : unary_expression | multiplicative_expression '*' unary_expression @@ -884,14 +884,14 @@ additive_expression | additive_expression '-' multiplicative_expression ; -// Source: 12.10 Shift operators +// Source: §12.10 Shift operators shift_expression : additive_expression | shift_expression '<<' additive_expression | shift_expression right_shift additive_expression ; -// Source: 12.11.1 General +// Source: §12.11.1 General relational_expression : shift_expression | relational_expression '<' shift_expression @@ -908,7 +908,7 @@ equality_expression | equality_expression '!=' relational_expression ; -// Source: 12.12.1 General +// Source: §12.12.1 General and_expression : equality_expression | and_expression '&' equality_expression @@ -924,7 +924,7 @@ inclusive_or_expression | inclusive_or_expression '|' exclusive_or_expression ; -// Source: 12.13.1 General +// Source: §12.13.1 General conditional_and_expression : inclusive_or_expression | conditional_and_expression '&&' inclusive_or_expression @@ -935,19 +935,19 @@ conditional_or_expression | conditional_or_expression '||' conditional_and_expression ; -// Source: 12.14 The null coalescing operator +// Source: §12.14 The null coalescing operator null_coalescing_expression : conditional_or_expression | conditional_or_expression '??' null_coalescing_expression ; -// Source: 12.15 Conditional operator +// Source: §12.15 Conditional operator conditional_expression : null_coalescing_expression | null_coalescing_expression '?' expression ':' expression ; -// Source: 12.16.1 General +// Source: §12.16.1 General lambda_expression : 'async'? anonymous_function_signature '=>' anonymous_function_body ; @@ -996,7 +996,7 @@ anonymous_function_body | block ; -// Source: 12.17.1 General +// Source: §12.17.1 General query_expression : from_clause query_body ; @@ -1073,7 +1073,7 @@ query_continuation : 'into' identifier query_body ; -// Source: 12.18.1 General +// Source: §12.18.1 General assignment : unary_expression assignment_operator expression ; @@ -1083,7 +1083,7 @@ assignment_operator | right_shift_assignment ; -// Source: 12.19 Expression +// Source: §12.19 Expression expression : non_assignment_expression | assignment @@ -1095,17 +1095,17 @@ non_assignment_expression | query_expression ; -// Source: 12.20 Constant expressions +// Source: §12.20 Constant expressions constant_expression : expression ; -// Source: 12.21 Boolean expressions +// Source: §12.21 Boolean expressions boolean_expression : expression ; -// Source: 13.1 General +// Source: §13.1 General statement : labeled_statement | declaration_statement @@ -1127,33 +1127,33 @@ embedded_statement | yield_statement ; -// Source: 13.3.1 General +// Source: §13.3.1 General block : '{' statement_list? '}' ; -// Source: 13.3.2 Statement lists +// Source: §13.3.2 Statement lists statement_list : statement+ ; -// Source: 13.4 The empty statement +// Source: §13.4 The empty statement empty_statement : ';' ; -// Source: 13.5 Labeled statements +// Source: §13.5 Labeled statements labeled_statement : identifier ':' statement ; -// Source: 13.6.1 General +// Source: §13.6.1 General declaration_statement : local_variable_declaration ';' | local_constant_declaration ';' ; -// Source: 13.6.2 Local variable declarations +// Source: §13.6.2 Local variable declarations local_variable_declaration : local_variable_type local_variable_declarators ; @@ -1178,7 +1178,7 @@ local_variable_initializer | array_initializer ; -// Source: 13.6.3 Local constant declarations +// Source: §13.6.3 Local constant declarations local_constant_declaration : 'const' type constant_declarators ; @@ -1191,7 +1191,7 @@ constant_declarator : identifier '=' constant_expression ; -// Source: 13.7 Expression statements +// Source: §13.7 Expression statements expression_statement : statement_expression ';' ; @@ -1207,19 +1207,19 @@ statement_expression | await_expression ; -// Source: 13.8.1 General +// Source: §13.8.1 General selection_statement : if_statement | switch_statement ; -// Source: 13.8.2 The if statement +// Source: §13.8.2 The if statement if_statement : 'if' '(' boolean_expression ')' embedded_statement | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement ; -// Source: 13.8.3 The switch statement +// Source: §13.8.3 The switch statement switch_statement : 'switch' '(' expression ')' switch_block ; @@ -1237,7 +1237,7 @@ switch_label | 'default' ':' ; -// Source: 13.9.1 General +// Source: §13.9.1 General iteration_statement : while_statement | do_statement @@ -1245,17 +1245,17 @@ iteration_statement | foreach_statement ; -// Source: 13.9.2 The while statement +// Source: §13.9.2 The while statement while_statement : 'while' '(' boolean_expression ')' embedded_statement ; -// Source: 13.9.3 The do statement +// Source: §13.9.3 The do statement do_statement : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' ; -// Source: 13.9.4 The for statement +// Source: §13.9.4 The for statement for_statement : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement ; @@ -1277,12 +1277,12 @@ statement_expression_list : statement_expression (',' statement_expression)* ; -// Source: 13.9.5 The foreach statement +// Source: §13.9.5 The foreach statement foreach_statement : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement ; -// Source: 13.10.1 General +// Source: §13.10.1 General jump_statement : break_statement | continue_statement @@ -1291,34 +1291,34 @@ jump_statement | throw_statement ; -// Source: 13.10.2 The break statement +// Source: §13.10.2 The break statement break_statement : 'break' ';' ; -// Source: 13.10.3 The continue statement +// Source: §13.10.3 The continue statement continue_statement : 'continue' ';' ; -// Source: 13.10.4 The goto statement +// Source: §13.10.4 The goto statement goto_statement : 'goto' identifier ';' | 'goto' 'case' constant_expression ';' | 'goto' 'default' ';' ; -// Source: 13.10.5 The return statement +// Source: §13.10.5 The return statement return_statement : 'return' expression? ';' ; -// Source: 13.10.6 The throw statement +// Source: §13.10.6 The throw statement throw_statement : 'throw' expression? ';' ; -// Source: 13.11 The try statement +// Source: §13.11 The try statement try_statement : 'try' block catch_clause+ | 'try' block finally_clause @@ -1333,7 +1333,7 @@ exception_specifier : '(' type identifier? ')' ; -// Source: 13.12 The checked and unchecked statements +// Source: §13.12 The checked and unchecked statements checked_statement : 'checked' block ; @@ -1342,12 +1342,12 @@ unchecked_statement : 'unchecked' block ; -// Source: 13.13 The lock statement +// Source: §13.13 The lock statement lock_statement : 'lock' '(' expression ')' embedded_statement ; -// Source: 13.14 The using statement +// Source: §13.14 The using statement using_statement : 'using' '(' resource_acquisition ')' embedded_statement ; @@ -1357,18 +1357,18 @@ resource_acquisition | expression ; -// Source: 13.15 The yield statement +// Source: §13.15 The yield statement yield_statement : 'yield' 'return' expression ';' | 'yield' 'break' ';' ; -// Source: 14.2 Compilation units +// Source: §14.2 Compilation units compilation_unit : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* ; -// Source: 14.3 Namespace declarations +// Source: §14.3 Namespace declarations namespace_declaration : 'namespace' qualified_identifier namespace_body ';'? ; @@ -1381,34 +1381,34 @@ namespace_body : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' ; -// Source: 14.4 Extern alias directives +// Source: §14.4 Extern alias directives extern_alias_directive : 'extern' 'alias' identifier ';' ; -// Source: 14.5.1 General +// Source: §14.5.1 General using_directive : using_alias-directive | using_namespace-directive ; -// Source: 14.5.2 Using alias directives +// Source: §14.5.2 Using alias directives using_alias_directive : 'using' identifier '=' namespace_or_type_name ';' ; -// Source: 14.5.3 Using namespace directives +// Source: §14.5.3 Using namespace directives using_namespace_directive : 'using' namespace_name ';' ; -// Source: 14.6 Namespace member declarations +// Source: §14.6 Namespace member declarations namespace_member_declaration : namespace_declaration | type_declaration ; -// Source: 14.7 Type declarations +// Source: §14.7 Type declarations type_declaration : class_declaration | struct_declaration @@ -1417,18 +1417,18 @@ type_declaration | delegate_declaration ; -// Source: 14.8.1 General +// Source: §14.8.1 General qualified_alias_member : identifier '::' identifier type_argument_list? ; -// Source: 15.2.1 General +// Source: §15.2.1 General class_declaration : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? class_base? type_parameter_constraints_clause* class_body ';'? ; -// Source: 15.2.2.1 General +// Source: §15.2.2.1 General class_modifier : 'new' | 'public' @@ -1440,7 +1440,7 @@ class_modifier | 'static' ; -// Source: 15.2.3 Type parameters +// Source: §15.2.3 Type parameters type_parameter_list : '<' type_parameters '>' ; @@ -1450,7 +1450,7 @@ type_parameters | type_parameters ',' attributes? type_parameter ; -// Source: 15.2.4.1 General +// Source: §15.2.4.1 General class_base : ':' class_type | ':' interface_type_list @@ -1461,7 +1461,7 @@ interface_type_list : interface_type (',' interface_type)* ; -// Source: 15.2.5 Type parameter constraints +// Source: §15.2.5 Type parameter constraints type_parameter_constraints_clauses : type_parameter_constraints_clause | type_parameter_constraints_clauses type_parameter_constraints_clause @@ -1498,12 +1498,12 @@ constructor_constraint : 'new' '(' ')' ; -// Source: 15.2.6 Class body +// Source: §15.2.6 Class body class_body : '{' class_member_declaration* '}' ; -// Source: 15.3.1 General +// Source: §15.3.1 General class_member_declaration : constant_declaration | field_declaration @@ -1518,7 +1518,7 @@ class_member_declaration | type_declaration ; -// Source: 15.4 Constants +// Source: §15.4 Constants constant_declaration : attributes? constant_modifier* 'const' type constant_declarators ';' ; @@ -1531,7 +1531,7 @@ constant_modifier | 'private' ; -// Source: 15.5.1 General +// Source: §15.5.1 General field_declaration : attributes? field_modifier* type variable_declarators ';' ; @@ -1555,7 +1555,7 @@ variable_declarator : identifier ('=' variable_initializer)? ; -// Source: 15.6.1 General +// Source: §15.6.1 General method_declaration : method_header method_body ; @@ -1593,7 +1593,7 @@ method_body : block ; -// Source: 15.6.2.1 General +// Source: §15.6.2.1 General formal_parameter_list : fixed_parameters | fixed_parameters ',' parameter_array @@ -1626,7 +1626,7 @@ parameter_array : attributes? 'params' array_type identifier ; -// Source: 15.7.1 General +// Source: §15.7.1 General property_declaration : attributes? property_modifiers? type member_name '{' accessor_declarations '}' ; @@ -1650,7 +1650,7 @@ property_modifier | 'extern' ; -// Source: 15.7.3 Accessors +// Source: §15.7.3 Accessors accessor_declarations : get_accessor_declaration set_accessor_declaration? | set_accessor_declaration get_accessor_declaration? @@ -1677,7 +1677,7 @@ accessor_body | ';' ; -// Source: 15.8.1 General +// Source: §15.8.1 General event_declaration : attributes? event_modifier* 'event' type variable_declarators ';' | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' @@ -1710,7 +1710,7 @@ remove_accessor_declaration : attributes? 'remove' block ; -// Source: 15.9 Indexers +// Source: §15.9 Indexers indexer_declaration : attributes? indexer_modifiers? indexer_declarator '{' accessor_declarations '}' ; @@ -1738,7 +1738,7 @@ indexer_declarator | type interface_type '.' 'this' '[' formal_parameter_list ']' ; -// Source: 15.10.1 General +// Source: §15.10.1 General operator_declaration : attributes? operator_modifier+ operator_declarator operator_body ; @@ -1782,7 +1782,7 @@ operator_body | ';' ; -// Source: 15.11.1 General +// Source: §15.11.1 General constructor_declaration : attributes? constructor_modifier* constructor_declarator constructor_body ; @@ -1809,7 +1809,7 @@ constructor_body | ';' ; -// Source: 15.12 Static constructors +// Source: §15.12 Static constructors static_constructor_declaration : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body ; @@ -1824,7 +1824,7 @@ static_constructor_body | ';' ; -// Source: 15.13 Finalizers +// Source: §15.13 Finalizers finalizer_declaration : attributes? 'extern'? '~' identifier '(' ')' finalizer_body ; @@ -1834,13 +1834,13 @@ finalizer_body | ';' ; -// Source: 16.2.1 General +// Source: §16.2.1 General struct_declaration : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? struct_interfaces? type_parameter_constraints_clause* struct_body ';'? ; -// Source: 16.2.2 Struct modifiers +// Source: §16.2.2 Struct modifiers struct_modifier : 'new' | 'public' @@ -1849,17 +1849,17 @@ struct_modifier | 'private' ; -// Source: 16.2.4 Struct interfaces +// Source: §16.2.4 Struct interfaces struct_interfaces : ':' interface_type_list ; -// Source: 16.2.5 Struct body +// Source: §16.2.5 Struct body struct_body : '{' struct_member_declaration* '}' ; -// Source: 16.3 Struct members +// Source: §16.3 Struct members struct_member_declaration : constant_declaration | field_declaration @@ -1873,7 +1873,7 @@ struct_member_declaration | type_declaration ; -// Source: 17.7 Array initializers +// Source: §17.7 Array initializers array_initializer : '{' variable_initializer_list? '}' | '{' variable_initializer_list ',' '}' @@ -1888,12 +1888,12 @@ variable_initializer | array_initializer ; -// Source: 18.2.1 General +// Source: §18.2.1 General interface_declaration : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? ; -// Source: 18.2.2 Interface modifiers +// Source: §18.2.2 Interface modifiers interface_modifier : 'new' | 'public' @@ -1902,34 +1902,34 @@ interface_modifier | 'private' ; -// Source: 18.2.3.1 General +// Source: §18.2.3.1 General variant_type_parameter_list : '<' variant_type_parameters '>' ; -// Source: 18.2.3.1 General +// Source: §18.2.3.1 General variant_type_parameters : attributes? variance_annotation? type_parameter | variant_type_parameters ',' attributes? variance_annotation? type_parameter ; -// Source: 18.2.3.1 General +// Source: §18.2.3.1 General variance_annotation : 'in' | 'out' ; -// Source: 18.2.4 Base interfaces +// Source: §18.2.4 Base interfaces interface_base : ':' interface_type_list ; -// Source: 18.3 Interface body +// Source: §18.3 Interface body interface_body : '{' interface_member_declaration* '}' ; -// Source: 18.4.1 General +// Source: §18.4.1 General interface_member_declaration : interface_method_declaration | interface_property_declaration @@ -1937,17 +1937,17 @@ interface_member_declaration | interface_indexer_declaration ; -// Source: 18.4.2 Interface methods +// Source: §18.4.2 Interface methods interface_method_declaration : attributes? 'new'? return_type identifier type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; -// Source: 18.4.3 Interface properties +// Source: §18.4.3 Interface properties interface_property_declaration : attributes? 'new'? type identifier '{' interface_accessors '}' ; -// Source: 18.4.3 Interface properties +// Source: §18.4.3 Interface properties interface_accessors : attributes? 'get' ';' | attributes? 'set' ';' @@ -1955,17 +1955,17 @@ interface_accessors | attributes? 'set' ';' attributes? 'get' ';' ; -// Source: 18.4.4 Interface events +// Source: §18.4.4 Interface events interface_event_declaration : attributes? 'new'? 'event' type identifier ';' ; -// Source: 18.4.5 Interface indexers +// Source: §18.4.5 Interface indexers interface_indexer_declaration: attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' ; -// Source: 19.2 Enum declarations +// Source: §19.2 Enum declarations enum_declaration : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? ; @@ -1979,7 +1979,7 @@ enum_body | '{' enum_member_declarations ',' '}' ; -// Source: 19.3 Enum modifiers +// Source: §19.3 Enum modifiers enum_modifier : 'new' | 'public' @@ -1988,17 +1988,17 @@ enum_modifier | 'private' ; -// Source: 19.4 Enum members +// Source: §19.4 Enum members enum_member_declarations : enum_member_declaration (',' enum_member_declaration)* ; -// Source: 19.4 Enum members +// Source: §19.4 Enum members enum_member_declaration : attributes? identifier ('=' constant_expression)? ; -// Source: 20.2 Delegate declarations +// Source: §20.2 Delegate declarations delegate_declaration : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; @@ -2011,7 +2011,7 @@ delegate_modifier | 'private' ; -// Source: 22.3 Attribute specification +// Source: §22.3 Attribute specification global_attributes : global_attribute_section+ ; @@ -2085,7 +2085,7 @@ attribute_argument_expression : expression ; -// Source: 23.2 Unsafe contexts +// Source: §23.2 Unsafe contexts class_modifier : ... | 'unsafe' @@ -2164,7 +2164,7 @@ unsafe_statement : 'unsafe' block ; -// Source: 23.3 Pointer types +// Source: §23.3 Pointer types type : ... | pointer_type @@ -2175,7 +2175,7 @@ non_array_type | pointer_type ; -// Source: 23.3 Pointer types +// Source: §23.3 Pointer types pointer_type : unmanaged_type '*' | 'void' '*' @@ -2185,7 +2185,7 @@ unmanaged_type : type ; -// Source: 23.6.1 General +// Source: §23.6.1 General primary_no_array_creation_expression : ... | pointer_member_access @@ -2198,27 +2198,27 @@ unary_expression | addressof_expression ; -// Source: 23.6.2 Pointer indirection +// Source: §23.6.2 Pointer indirection pointer_indirection_expression : '*' unary_expression ; -// Source: 23.6.3 Pointer member access +// Source: §23.6.3 Pointer member access pointer_member_access : primary_expression '->' identifier type_argument_list? ; -// Source: 23.6.4 Pointer element access +// Source: §23.6.4 Pointer element access pointer_element_access : primary_no_array_creation_expression '[' expression ']' ; -// Source: 23.6.5 The address-of operator +// Source: §23.6.5 The address-of operator addressof_expression : '&' unary_expression ; -// Source: 23.7 The fixed statement +// Source: §23.7 The fixed statement fixed_statement : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ; @@ -2236,7 +2236,7 @@ fixed_pointer_initializer | expression ; -// Source: 23.8.2 Fixed-size buffer declarations +// Source: §23.8.2 Fixed-size buffer declarations struct_member_declaration : ... | fixed_size_buffer_declaration @@ -2263,7 +2263,7 @@ fixed_size_buffer_declarator : identifier '[' constant_expression ']' ; -// Source: 23.9 Stack allocation +// Source: §23.9 Stack allocation local_variable_initializer : ... | stackalloc_initializer From 391bd3ac406404b42c73d3d86a6d9475d6febb73 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 27 Jan 2021 11:24:17 -0500 Subject: [PATCH 4/8] script now runs in the tools folder. --- tools/GetGrammar/GetGrammar.bat | 103 ------------------ .../GetGrammar.sh => update-grammar-annex.sh} | 0 tools/validate-grammar.sh | 24 ++++ 3 files changed, 24 insertions(+), 103 deletions(-) delete mode 100644 tools/GetGrammar/GetGrammar.bat rename tools/{GetGrammar/GetGrammar.sh => update-grammar-annex.sh} (100%) create mode 100755 tools/validate-grammar.sh diff --git a/tools/GetGrammar/GetGrammar.bat b/tools/GetGrammar/GetGrammar.bat deleted file mode 100644 index da9db4f18..000000000 --- a/tools/GetGrammar/GetGrammar.bat +++ /dev/null @@ -1,103 +0,0 @@ -echo off -dotnet build -c Release -dotnet publish -o publish - -del grammar.g4 -del ..\..\standard\grammar.md -echo Insert General/Lexical Headers -type grammar-general-lexical-insert.md >..\..\standard\grammar.md -echo Extract Lexical Grammar -publish\GetGrammar ..\..\standard\lexical-structure.md >lexical-structure.g4 -type lexical-structure.g4 >grammar.g4 -type lexical-structure.g4 >>..\..\standard\grammar.md -del lexical-structure.g4 - -echo Insert Syntactic Header -type grammar-syntactic-insert.md >>..\..\standard\grammar.md -echo Extract Syntactic Grammar - -publish\GetGrammar ..\..\standard\basic-concepts.md >basic-concepts.g4 -type basic-concepts.g4 >>grammar.g4 -type basic-concepts.g4 >>..\..\standard\grammar.md -del basic-concepts.g4 - -publish\GetGrammar ..\..\standard\types.md >types.g4 -type types.g4 >>grammar.g4 -type types.g4 >>..\..\standard\grammar.md -del types.g4 - -publish\GetGrammar ..\..\standard\variables.md >variables.g4 -type variables.g4 >>grammar.g4 -type variables.g4 >>..\..\standard\grammar.md -del variables.g4 - -publish\GetGrammar ..\..\standard\conversions.md >conversions.g4 -type conversions.g4 >>grammar.g4 -type conversions.g4 >>..\..\standard\grammar.md -del conversions.g4 - -publish\GetGrammar ..\..\standard\expressions.md >expressions.g4 -type expressions.g4 >>grammar.g4 -type expressions.g4 >>..\..\standard\grammar.md -del expressions.g4 - -publish\GetGrammar ..\..\standard\statements.md >statements.g4 -type statements.g4 >>grammar.g4 -type statements.g4 >>..\..\standard\grammar.md -del statements.g4 - -publish\GetGrammar ..\..\standard\namespaces.md >namespaces.g4 -type namespaces.g4 >>grammar.g4 -type namespaces.g4 >>..\..\standard\grammar.md -del namespaces.g4 - -publish\GetGrammar ..\..\standard\classes.md >classes.g4 -type classes.g4 >>grammar.g4 -type classes.g4 >>..\..\standard\grammar.md -del classes.g4 - -publish\GetGrammar ..\..\standard\structs.md >structs.g4 -type structs.g4 >>grammar.g4 -type structs.g4 >>..\..\standard\grammar.md -del structs.g4 - -publish\GetGrammar ..\..\standard\arrays.md >arrays.g4 -type arrays.g4 >>grammar.g4 -type arrays.g4 >>..\..\standard\grammar.md -del arrays.g4 - -publish\GetGrammar ..\..\standard\interfaces.md >interfaces.g4 -type interfaces.g4 >>grammar.g4 -type interfaces.g4 >>..\..\standard\grammar.md -del interfaces.g4 - -publish\GetGrammar ..\..\standard\enums.md >enums.g4 -type enums.g4 >>grammar.g4 -type enums.g4 >>..\..\standard\grammar.md -del enums.g4 - -publish\GetGrammar ..\..\standard\delegates.md >delegates.g4 -type delegates.g4 >>grammar.g4 -type delegates.g4 >>..\..\standard\grammar.md -del delegates.g4 - -publish\GetGrammar ..\..\standard\exceptions.md >exceptions.g4 -type exceptions.g4 >>grammar.g4 -type exceptions.g4 >>..\..\standard\grammar.md -del exceptions.g4 - -publish\GetGrammar ..\..\standard\attributes.md >attributes.g4 -type attributes.g4 >>grammar.g4 -type attributes.g4 >>..\..\standard\grammar.md -del attributes.g4 - -echo Insert Unsafe Header -type grammar-unsafe-extensions-insert.md >>..\..\standard\grammar.md -echo Extract Unsafe Grammar -publish\GetGrammar ..\..\standard\unsafe-code.md >unsafe-code.g4 -type unsafe-code.g4 >>grammar.g4 -type unsafe-code.g4 >>..\..\standard\grammar.md -del unsafe-code.g4 - -echo Insert EOF Stuff -type grammar-eof-insert.md >>..\..\standard\grammar.md diff --git a/tools/GetGrammar/GetGrammar.sh b/tools/update-grammar-annex.sh similarity index 100% rename from tools/GetGrammar/GetGrammar.sh rename to tools/update-grammar-annex.sh diff --git a/tools/validate-grammar.sh b/tools/validate-grammar.sh new file mode 100755 index 000000000..877be8ec6 --- /dev/null +++ b/tools/validate-grammar.sh @@ -0,0 +1,24 @@ +#!/bin/sh +dotnet build GetGrammar -c Release +dotnet publish GetGrammar -c Release -o GetGrammar/publish + +rm grammar.g4 +echo Extract Lexical Grammar +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/lexical-structure.md >grammar.g4 + +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/basic-concepts.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/types.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/variables.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/conversions.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/expressions.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/statements.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/namespaces.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/classes.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/structs.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/arrays.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/interfaces.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/enums.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/delegates.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/exceptions.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/attributes.md >>grammar.g4 +dotnet GetGrammar/publish/GetGrammar.dll ../../standard/unsafe-code.md >>grammar.g4 From 866fa7a4ddb7e52f488a747d19cac6900f27fddb Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 27 Jan 2021 12:49:37 -0500 Subject: [PATCH 5/8] run grammar validation --- tools/validate-grammar.sh | 62 +++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/tools/validate-grammar.sh b/tools/validate-grammar.sh index 877be8ec6..d75748d8b 100755 --- a/tools/validate-grammar.sh +++ b/tools/validate-grammar.sh @@ -1,24 +1,42 @@ -#!/bin/sh -dotnet build GetGrammar -c Release -dotnet publish GetGrammar -c Release -o GetGrammar/publish +#!/bin/bash -rm grammar.g4 -echo Extract Lexical Grammar -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/lexical-structure.md >grammar.g4 +declare -r GRAMMAR_PROJECT=GetGrammar +declare -r SPEC_DIRECTORY=../standard +declare -r OUTPUT_FILE=csharp-grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/basic-concepts.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/types.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/variables.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/conversions.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/expressions.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/statements.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/namespaces.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/classes.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/structs.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/arrays.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/interfaces.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/enums.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/delegates.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/exceptions.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/attributes.md >>grammar.g4 -dotnet GetGrammar/publish/GetGrammar.dll ../../standard/unsafe-code.md >>grammar.g4 +declare -a SPEC_FILES=( + "lexical-structure.md" + "basic-concepts.md" + "types.md" + "variables.md" + "conversions.md" + "expressions.md" + "statements.md" + "namespaces.md" + "classes.md" + "structs.md" + "arrays.md" + "interfaces.md" + "enums.md" + "delegates.md" + "exceptions.md" + "attributes.md" + "unsafe-code.md" + ) + +dotnet build $GRAMMAR_PROJECT -c Release +dotnet publish $GRAMMAR_PROJECT -c Release -o $GRAMMAR_PROJECT/publish + +rm $OUTPUT_FILE + +echo "grammar CSGrammar;" > $OUTPUT_FILE + +for file in "${SPEC_FILES[@]}" +do + echo "$file" + dotnet $GRAMMAR_PROJECT/publish/$GRAMMAR_PROJECT.dll $SPEC_DIRECTORY/$file >>$OUTPUT_FILE +done + +# Now, validate it: +curl -H "Accept: application/zip" https://www.antlr.org/download/antlr-4.9.1-complete.jar -o antlr-4.9.1-complete.jar +java -jar antlr-4.9.1-complete.jar -Dlanguage=CSharp $OUTPUT_FILE \ No newline at end of file From 987b9c220c28c7a7659c455980ee2576ce87aca1 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 27 Jan 2021 13:02:49 -0500 Subject: [PATCH 6/8] add github workflow --- .github/workflows/grammar-vlidator.yaml | 29 + tools/GetGrammar/grammar.g4 | 2274 ----------------------- 2 files changed, 29 insertions(+), 2274 deletions(-) create mode 100644 .github/workflows/grammar-vlidator.yaml delete mode 100644 tools/GetGrammar/grammar.g4 diff --git a/.github/workflows/grammar-vlidator.yaml b/.github/workflows/grammar-vlidator.yaml new file mode 100644 index 000000000..1ab7347e1 --- /dev/null +++ b/.github/workflows/grammar-vlidator.yaml @@ -0,0 +1,29 @@ +name: ANTLR Grammar validatior + +# Triggers the workflow on push or pull request events +on: [push, pull_request, workflow_dispatch] + +jobs: + grammar-validator: + runs-on: ubuntu-18.04 + env: + DOTNET_NOLOGO: true + + steps: + - name: Check out our repo + uses: actions/checkout@v2 + + - name: Setup .NET 5.0 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + + - name: Set up JDK 15 + uses: actions/setup-java@v1 + with: + java-version: 15.0 + + - name: run validate + run: | + cd tools + ./validate-grammar.sh diff --git a/tools/GetGrammar/grammar.g4 b/tools/GetGrammar/grammar.g4 deleted file mode 100644 index bed6e4646..000000000 --- a/tools/GetGrammar/grammar.g4 +++ /dev/null @@ -1,2274 +0,0 @@ - -// Source: §7.3.1 General -input - : input_section? - ; - -input_section - : input_section_part+ - ; - -input_section_part - : input_element* new_line - | pp_directive - ; - -input_element - : whitespace - | comment - | token - ; - -// Source: §7.3.2 Line terminators -new_line - : '' - | '' - | '' - | '' - | '' - | '' - ; - -// Source: §7.3.3 Comments -comment - : single_line_comment - | delimited_comment - ; - -single_line_comment - : '//' input_character* - ; - -input_character - : '' - ; - -new_line_character - : '' - | '' - | '' - | '' - | '' - ; - -delimited_comment - : '/*' delimited_comment_section* asterisk+ '/' - ; - -delimited_comment_section - : '/' - | asterisk* not_slash_or_asterisk - ; - -asterisk - : '*' - ; - -not_slash_or_asterisk - : '' - ; - -// Source: §7.3.4 White space -whitespace - : '' - | '' - | '' - | '' - ; - -// Source: §7.4.1 General -token - : identifier - | keyword - | integer_literal - | real_literal - | character_literal - | string_literal - | operator_or_punctuator - ; - -// Source: §7.4.2 Unicode character escape sequences -unicode_escape_sequence - : '\\u' hex_digit hex_digit hex_digit hex_digit - | '\\U' hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit - ; - -// Source: §7.4.3 Identifiers -identifier - : available_identifier - | '@' identifier_or_keyword - ; - -available_identifier - : '' - ; - -identifier_or_keyword - : identifier_start_character identifier_part_character* - ; - -identifier_start_character - : letter_character - | underscore_character - ; - -underscore_character - : '<_ the underscore character (U+005F)>' - | '' - ; - -identifier_part_character - : letter_character - | decimal_digit_character - | connecting_character - | combining_character - | formatting_character - ; - -letter_character - : '' - | '' - ; - -combining_character - : '' - | '' - ; - -decimal_digit_character - : '' - | '' - ; - -connecting_character - : '' - | '' - ; - -formatting_character - : '' - | '' - ; - -// Source: §7.4.4 Keywords -keyword - : 'abstract' | 'as' | 'base' | 'bool' | 'break' - | 'byte' | 'case' | 'catch' | 'char' | 'checked' - | 'class' | 'const' | 'continue' | 'decimal' | 'default' - | 'delegate' | 'do' | 'double' | 'else' | 'enum' - | 'event' | 'explicit' | 'extern' | 'false' | 'finally' - | 'fixed' | 'float' | 'for' | 'foreach' | 'goto' - | 'if' | 'implicit' | 'in' | 'int' | 'interface' - | 'internal' | 'is' | 'lock' | 'long' | 'namespace' - | 'new' | 'null' | 'object' | 'operator' | 'out' - | 'override' | 'params' | 'private' | 'protected' | 'public' - | 'readonly' | 'ref' | 'return' | 'sbyte' | 'sealed' - | 'short' | 'sizeof' | 'stackalloc' | 'static' | 'string' - | 'struct' | 'switch' | 'this' | 'throw' | 'true' - | 'try' | 'typeof' | 'uint' | 'ulong' | 'unchecked' - | 'unsafe' | 'ushort' | 'using' | 'virtual' | 'void' - | 'volatile' | 'while' - ; - -// Source: §7.4.4 Keywords -contextual_keyword - : 'add' 'alias' 'ascending' 'async' 'await' - | 'by' 'descending' 'dynamic' 'equals' 'from' - | 'get' 'global' 'group' 'into' 'join' - | 'let' 'orderby' 'partial' 'remove' 'select' - | 'set' 'value' 'var' 'where' 'yield' - ; - -// Source: §7.4.5.1 General -literal - : boolean_literal - | integer_literal - | real_literal - | character_literal - | string_literal - | null_literal - ; - -// Source: §7.4.5.2 Boolean literals -boolean_literal - : 'true' - | 'false' - ; - -// Source: §7.4.5.3 Integer literals -integer_literal - : decimal_integer_literal - | hexadecimal_integer_literal - ; - -decimal_integer_literal - : decimal_digit+ integer_type_suffix? - ; - -decimal_digit - : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' - ; - -integer_type_suffix - : 'U' | 'u' | 'L' | 'l' | 'UL' | 'Ul' | 'uL' | 'ul' | 'LU' | 'Lu' | 'lU' | 'lu' - ; - -hexadecimal_integer_literal - : '0x' hex_digit+ integer_type_suffix? - | '0X' hex_digit+ integer_type_suffix? - ; - -hex_digit - : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' - | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'; - -// Source: §7.4.5.4 Real literals -real_literal - : decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? - | '.' decimal_digit+ exponent_part? real_type_suffix? - | decimal_digit+ exponent_part real_type_suffix? - | decimal_digit+ real_type_suffix - ; - -exponent_part - : 'e' sign? decimal_digit+ - | 'E' sign? decimal_digit+ - ; - -sign - : '+' | '-' - ; - -real_type_suffix - : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' - ; - -// Source: §7.4.5.5 Character literals -character_literal - : '\'' character '\'' - ; - -character - : single_character - | simple_escape_sequence - | hexadecimal_escape_sequence - | unicode_escape_sequence - ; - -single_character - : '' - ; - -simple_escape_sequence - : '\\\'' | '\\"' | '\\\\' | '\\0' | '\\a' | '\\b' | '\\f' | '\\n' | '\\r' | '\\t' | '\\v' - ; - -hexadecimal_escape_sequence - : '\\x' hex_digit hex_digit? hex_digit? hex_digit? - ; - -// Source: §7.4.5.6 String literals -string_literal - : regular_string_literal - | verbatim_string_literal - ; - -regular_string_literal - : '"' regular_string_literal_character* '"' - ; - -regular_string_literal_character - : single_regular_string_literal_character - | simple_escape_sequence - | hexadecimal_escape_sequence - | unicode_escape_sequence - ; - -single_regular_string_literal_character - : '' - ; - -verbatim_string_literal - : '@"' verbatim_string_literal_character* '"' - ; - -verbatim_string_literal_character - : single_verbatim_string_literal_character - | quote_escape_sequence - ; - -single_verbatim_string_literal_character - : '' - ; - -quote_escape_sequence - : '""' - ; - -// Source: §7.4.5.7 The null literal -null_literal - : 'null' - ; - -// Source: §7.4.6 Operators and punctuators -operator_or_punctuator - : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' - | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' - | '=' | '<' | '>' | '?' | '??' | '::' | '++' | '--' | '&&' | '||' - | '->' | '==' | '!=' | '<=' | '>=' | '+=' | '-=' | '*=' | '/=' | '%=' - | '&=' | '|=' | '^=' | '<<' | '<<=' | '=>' - ; - -right_shift - : '>' '>' - ; - -right_shift_assignment - : '>' '>=' - ; - -// Source: §7.5.1 General -pp_directive - : pp_declaration - | pp_conditional - | pp_line - | pp_diagnostic - | pp_region - | pp_pragma - ; - -// Source: §7.5.2 Conditional compilation symbols -conditional_symbol - : '' - ; - -// Source: §7.5.3 Pre-processing expressions -pp_expression - : whitespace? pp_or_expression whitespace? - ; - -pp_or_expression - : pp_and_expression - | pp_or_expression whitespace? '||' whitespace? pp_and_expression - ; - -pp_and_expression - : pp_equality_expression - | pp_and_expression whitespace? '&&' whitespace? pp_equality_expression - ; - -pp_equality_expression - : pp_unary_expression - | pp_equality_expression whitespace? '==' whitespace? pp_unary_expression - | pp_equality_expression whitespace? '!=' whitespace? pp_unary_expression - ; - -pp_unary_expression - : pp_primary_expression - | '!' whitespace? pp_unary_expression - ; - -pp_primary_expression - : 'true' - | 'false' - | conditional_symbol - | '(' whitespace? pp_expression whitespace? ')' - ; - -// Source: §7.5.4 Definition directives -pp_declaration - : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line - | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line - ; - -pp_new_line - : whitespace? single_line_comment? new_line - ; - -// Source: §7.5.5 Conditional compilation directives -pp_conditional - : pp_if_section pp_elif_section* pp_else_section? pp_endif - ; - -pp_if_section - : whitespace? '#' whitespace? 'if' whitespace pp_expression pp_new_line conditional_section? - ; - -pp_elif_section - : whitespace? '#' whitespace? 'elif' whitespace pp_expression pp_new_line conditional_section? - ; - -pp_else_section - : whitespace? '#' whitespace? 'else' pp_new_line conditional_section? - ; - -pp_endif - : whitespace? '#' whitespace? 'endif' pp_new_line - ; - -conditional_section - : input_section - | skipped_section_part+ - ; - -skipped_section_part - : skipped_characters? new_line - | pp_directive - ; - -skipped_characters - : whitespace? not_number_sign input_character* - ; - -not_number_sign - : '' - ; - -// Source: §7.5.6 Diagnostic directives -pp_diagnostic - : whitespace? '#' whitespace? 'error' pp_message - | whitespace? '#' whitespace? 'warning' pp_message - ; - -pp_message - : new_line - | whitespace input_character* new_line - ; - -// Source: §7.5.7 Region directives -pp_region - : pp_start_region conditional_section? pp_end_region - ; - -pp_start_region - : whitespace? '#' whitespace? 'region' pp_message - ; - -pp_end_region - : whitespace? '#' whitespace? 'endregion' pp_message - ; - -// Source: §7.5.8 Line directives -pp_line - : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line - ; - -line_indicator - : decimal_digit+ whitespace compilation_unit_name - | decimal_digit+ - | 'default' - | 'hidden' - ; - -compilation_unit_name - : '"' compilation_unit_name_character+ '"' - ; - -compilation_unit_name_character - : '' - ; - -// Source: §7.5.9 Pragma directives -pp_pragma - : whitespace? '#' whitespace? 'pragma' pp_pragma_text - ; - -pp_pragma_text - : new_line - | whitespace input_character* new_line - ; - -// Source: §8.8.1 General -namespace_name - : namespace_or_type_name - ; - -type_name - : namespace_or_type_name - ; - -namespace_or_type_name - : identifier type_argument_list? - | namespace_or_type_name '.' identifier type_argument_list? - | qualified_alias_member - ; - -// Source: §9.1 General -type - : reference_type - | value_type - | type_parameter - ; - -// Source: §9.2.1 General -reference_type - : class_type - | interface_type - | array_type - | delegate_type - | 'dynamic' - ; - -class_type - : type_name - | 'object' - | 'string' - ; - -interface_type - : type_name - ; - -array_type - : non_array_type rank_specifier+ - ; - -non_array_type - : value_type - | class_type - | interface_type - | delegate_type - | 'dynamic' - | type_parameter - ; - -rank_specifier - : '[' ','* ']' - ; - -delegate_type - : type_name - ; - -// Source: §9.3.1 General -value_type - : struct_type - | enum_type - ; - -struct_type - : type_name - | simple_type - | nullable_value_type - ; - -simple_type - : numeric_type - | 'bool' - ; - -numeric_type - : integral_type - | floating_point_type - | 'decimal' - ; - -integral_type - : 'sbyte' - | 'byte' - | 'short' - | 'ushort' - | 'int' - | 'uint' - | 'long' - | 'ulong' - | 'char' - ; - -floating_point_type - : 'float' - | 'double' - ; - -nullable_value_type - : non_nullable_value_type '?' - ; - -non_nullable_value_type - : type - ; - -enum_type - : type_name - ; - -// Source: §9.4.2 Type arguments -type_argument_list - : '<' type_arguments '>' - ; - -type_arguments - : type_argument (',' type_argument)* - ; - -type_argument - : type - ; - -// Source: §9.5 Type parameters -type_parameter - : identifier - ; - -// Source: §10.5 Variable references -variable_reference - : expression - ; - -// Source: §12.6.2.1 General -argument_list - : argument (',' argument)* - ; - -argument - : argument_name? argument_value - ; - -argument_name - : identifier ':' - ; - -argument_value - : expression - | 'ref' variable_reference - | 'out' variable_reference - ; - -// Source: §12.7.1 General -primary_expression - : primary_no_array_creation_expression - | array_creation_expression - ; - -primary_no_array_creation_expression - : literal - | simple_name - | parenthesized_expression - | member_access - | invocation_expression - | element_access - | this_access - | base_access - | post_increment_expression - | post_decrement_expression - | object_creation_expression - | delegate_creation_expression - | anonymous_object_creation_expression - | typeof_expression - | sizeof_expression - | checked_expression - | unchecked_expression - | default_value_expression - | anonymous_method_expression - ; - -// Source: §12.7.3.1 General -simple_name - : identifier type_argument_list? - ; - -// Source: §12.7.4 Parenthesized expressions -parenthesized_expression - : '(' expression ')' - ; - -// Source: §12.7.5.1 General -member_access - : primary_expression '.' identifier type_argument_list? - | predefined_type '.' identifier type_argument_list? - | qualified_alias_member '.' identifier type_argument_list? - ; - -predefined_type - : 'bool' | 'byte' | 'char' | 'decimal' | 'double' | 'float' | 'int' | 'long' - | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' - ; - -// Source: §12.7.6.1 General -invocation_expression - : primary_expression '(' argument_list? ')' - ; - -// Source: §12.7.7.1 General -element_access - : primary_no_array_creation_expression '[' argument_list ']' - ; - -// Source: §12.7.8 This access -this_access - : 'this' - ; - -// Source: §12.7.9 Base access -base_access - : 'base' '.' identifier type_argument_list? - | 'base' '[' argument_list ']' - ; - -// Source: §12.7.10 Postfix increment and decrement operators -post_increment_expression - : primary_expression '++' - ; - -post_decrement_expression - : primary_expression '--' - ; - -// Source: §12.7.11.2 Object creation expressions -object_creation_expression - : 'new' type '(' argument_list? ')' object_or_collection_initializer? - | 'new' type object_or_collection_initializer - ; - -object_or_collection_initializer - : object_initializer - | collection_initializer - ; - -// Source: §12.7.11.3 Object initializers -object_initializer - : '{' member_initializer_list? '}' - | '{' member_initializer_list ',' '}' - ; - -member_initializer_list - : member_initializer (',' member_initializer)* - ; - -member_initializer - : identifier '=' initializer_value - ; - -initializer_value - : expression - | object_or_collection_initializer - ; - -// Source: §12.7.11.4 Collection initializers -collection_initializer - : '{' element_initializer_list '}' - | '{' element_initializer_list ',' '}' - ; - -element_initializer_list - : element_initializer (',' element_initializer)* - ; - -element_initializer - : non_assignment_expression - | '{' expression_list '}' - ; - -expression_list - : expression - | expression_list ',' expression - ; - -// Source: §12.7.11.5 Array creation expressions -array_creation_expression - : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? - | 'new' array_type array_initializer - | 'new' rank_specifier array_initializer - ; - -// Source: §12.7.11.6 Delegate creation expressions -delegate_creation_expression - : 'new' delegate_type '(' expression ')' - ; - -// Source: §12.7.11.7 Anonymous object creation expressions -anonymous_object_creation_expression - : 'new' anonymous_object_initializer - ; - -anonymous_object_initializer - : '{' member_declarator_list? '}' - | '{' member_declarator_list ',' '}' - ; - -member_declarator_list - : member_declarator (',' member_declarator)* - ; - -member_declarator - : simple_name - | member_access - | base_access - | identifier '=' expression - ; - -// Source: §12.7.12 The typeof operator -typeof_expression - : 'typeof' '(' type ')' - | 'typeof' '(' unbound_type_name ')' - | 'typeof' '(' 'void' ')' - ; - -unbound_type_name - : identifier generic_dimension_specifier? - | identifier '::' identifier generic_dimension_specifier? - | unbound_type_name '.' identifier generic_dimension_specifier? - ; - -generic_dimension_specifier - : '<' comma* '>' - ; - -comma - : ',' - ; - - -// Source: §12.7.13 The sizeof operator -sizeof_expression - : 'sizeof' '(' unmanaged_type ')' - ; - -// Source: §12.7.14 The checked and unchecked operators -checked_expression - : 'checked' '(' expression ')' - ; - -unchecked_expression - : 'unchecked' '(' expression ')' - ; - -// Source: §12.7.15 Default value expressions -default_value_expression - : 'default' '(' type ')' - ; - -// Source: §12.8.1 General -unary_expression - : primary_expression - | '+' unary_expression - | '-' unary_expression - | '!' unary_expression - | '~' unary_expression - | pre_increment_expression - | pre_decrement_expression - | cast_expression - | await_expression - ; - -// Source: §12.8.6 Prefix increment and decrement operators -pre_increment_expression - : '++' unary_expression - ; - -pre_decrement_expression - : '--' unary_expression - ; - -// Source: §12.8.7 Cast expressions -cast_expression - : '(' type ')' unary_expression - ; - -// Source: §12.8.8.1 General -await_expression - : 'await' unary_expression - ; - -// Source: §12.9.1 General -multiplicative_expression - : unary_expression - | multiplicative_expression '*' unary_expression - | multiplicative_expression '/' unary_expression - | multiplicative_expression '%' unary_expression - ; - -additive_expression - : multiplicative_expression - | additive_expression '+' multiplicative_expression - | additive_expression '-' multiplicative_expression - ; - -// Source: §12.10 Shift operators -shift_expression - : additive_expression - | shift_expression '<<' additive_expression - | shift_expression right_shift additive_expression - ; - -// Source: §12.11.1 General -relational_expression - : shift_expression - | relational_expression '<' shift_expression - | relational_expression '>' shift_expression - | relational_expression '<=' shift_expression - | relational_expression '>=' shift_expression - | relational_expression 'is' type - | relational_expression 'as' type - ; - -equality_expression - : relational_expression - | equality_expression '==' relational_expression - | equality_expression '!=' relational_expression - ; - -// Source: §12.12.1 General -and_expression - : equality_expression - | and_expression '&' equality_expression - ; - -exclusive_or_expression - : and_expression - | exclusive_or_expression '^' and_expression - ; - -inclusive_or_expression - : exclusive_or_expression - | inclusive_or_expression '|' exclusive_or_expression - ; - -// Source: §12.13.1 General -conditional_and_expression - : inclusive_or_expression - | conditional_and_expression '&&' inclusive_or_expression - ; - -conditional_or_expression - : conditional_and_expression - | conditional_or_expression '||' conditional_and_expression - ; - -// Source: §12.14 The null coalescing operator -null_coalescing_expression - : conditional_or_expression - | conditional_or_expression '??' null_coalescing_expression - ; - -// Source: §12.15 Conditional operator -conditional_expression - : null_coalescing_expression - | null_coalescing_expression '?' expression ':' expression - ; - -// Source: §12.16.1 General -lambda_expression - : 'async'? anonymous_function_signature '=>' anonymous_function_body - ; - -anonymous_method_expression - : 'async'? 'delegate' explicit_anonymous_function_signature? block - ; - -anonymous_function_signature - : explicit_anonymous_function_signature - | implicit_anonymous_function_signature - ; - -explicit_anonymous_function_signature - : '(' explicit_anonymous_function_parameter_list? ')' - ; - -explicit_anonymous_function_parameter_list - : explicit_anonymous_function_parameter (',' explicit_anonymous_function_parameter)* - ; - -explicit_anonymous_function_parameter - : anonymous_function_parameter_modifier? type identifier - ; - -anonymous_function_parameter_modifier - : 'ref' - | 'out' - ; - -implicit_anonymous_function_signature - : '(' implicit_anonymous_function_parameter_list? ')' - | implicit_anonymous_function_parameter - ; - -implicit_anonymous_function_parameter_list - : implicit_anonymous_function_parameter (',' implicit_anonymous_function_parameter)* - ; - -implicit_anonymous_function_parameter - : identifier - ; - -anonymous_function_body - : expression - | block - ; - -// Source: §12.17.1 General -query_expression - : from_clause query_body - ; - -from_clause - : 'from' type? identifier 'in' expression - ; - -query_body - : query_body_clauses? select_or_group_clause query_continuation? - ; - -query_body_clauses - : query_body_clause - | query_body_clauses query_body_clause - ; - -query_body_clause - : from_clause - | let_clause - | where_clause - | join_clause - | join_into_clause - | orderby_clause - ; - -let_clause - : 'let' identifier '=' expression - ; - -where_clause - : 'where' boolean_expression - ; - -join_clause - : 'join' type? identifier 'in' expression 'on' expression 'equals' expression - ; - -join_into_clause - : 'join' type? identifier 'in' expression 'on' expression 'equals' expression 'into' identifier - ; - -orderby_clause - : 'orderby' orderings - ; - -orderings - : ordering (',' ordering)* - ; - -ordering - : expression ordering_direction? - ; - -ordering_direction - : 'ascending' - | 'descending' - ; - -select_or_group_clause - : select_clause - | group_clause - ; - -select_clause - : 'select' expression - ; - -group_clause - : 'group' expression 'by' expression - ; - -query_continuation - : 'into' identifier query_body - ; - -// Source: §12.18.1 General -assignment - : unary_expression assignment_operator expression - ; - -assignment_operator - : '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' - | right_shift_assignment - ; - -// Source: §12.19 Expression -expression - : non_assignment_expression - | assignment - ; - -non_assignment_expression - : conditional_expression - | lambda_expression - | query_expression - ; - -// Source: §12.20 Constant expressions -constant_expression - : expression - ; - -// Source: §12.21 Boolean expressions -boolean_expression - : expression - ; - -// Source: §13.1 General -statement - : labeled_statement - | declaration_statement - | embedded_statement - ; - -embedded_statement - : block - | empty_statement - | expression_statement - | selection_statement - | iteration_statement - | jump_statement - | try_statement - | checked_statement - | unchecked_statement - | lock_statement - | using_statement - | yield_statement - ; - -// Source: §13.3.1 General -block - : '{' statement_list? '}' - ; - -// Source: §13.3.2 Statement lists -statement_list - : statement+ - ; - -// Source: §13.4 The empty statement -empty_statement - : ';' - ; - -// Source: §13.5 Labeled statements -labeled_statement - : identifier ':' statement - ; - -// Source: §13.6.1 General -declaration_statement - : local_variable_declaration ';' - | local_constant_declaration ';' - ; - -// Source: §13.6.2 Local variable declarations -local_variable_declaration - : local_variable_type local_variable_declarators - ; - -local_variable_type - : type - | 'var' - ; - -local_variable_declarators - : local_variable_declarator - | local_variable_declarators ',' local_variable_declarator - ; - -local_variable_declarator - : identifier - | identifier '=' local_variable_initializer - ; - -local_variable_initializer - : expression - | array_initializer - ; - -// Source: §13.6.3 Local constant declarations -local_constant_declaration - : 'const' type constant_declarators - ; - -constant_declarators - : constant_declarator (',' constant_declarator)* - ; - -constant_declarator - : identifier '=' constant_expression - ; - -// Source: §13.7 Expression statements -expression_statement - : statement_expression ';' - ; - -statement_expression - : invocation_expression - | object_creation_expression - | assignment - | post_increment_expression - | post_decrement_expression - | pre_increment_expression - | pre_decrement_expression - | await_expression - ; - -// Source: §13.8.1 General -selection_statement - : if_statement - | switch_statement - ; - -// Source: §13.8.2 The if statement -if_statement - : 'if' '(' boolean_expression ')' embedded_statement - | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement - ; - -// Source: §13.8.3 The switch statement -switch_statement - : 'switch' '(' expression ')' switch_block - ; - -switch_block - : '{' switch_section* '}' - ; - -switch_section - : switch_label+ statement_list - ; - -switch_label - : 'case' constant_expression ':' - | 'default' ':' - ; - -// Source: §13.9.1 General -iteration_statement - : while_statement - | do_statement - | for_statement - | foreach_statement - ; - -// Source: §13.9.2 The while statement -while_statement - : 'while' '(' boolean_expression ')' embedded_statement - ; - -// Source: §13.9.3 The do statement -do_statement - : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' - ; - -// Source: §13.9.4 The for statement -for_statement - : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement - ; - -for_initializer - : local_variable_declaration - | statement_expression_list - ; - -for_condition - : boolean_expression - ; - -for_iterator - : statement_expression_list - ; - -statement_expression_list - : statement_expression (',' statement_expression)* - ; - -// Source: §13.9.5 The foreach statement -foreach_statement - : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement - ; - -// Source: §13.10.1 General -jump_statement - : break_statement - | continue_statement - | goto_statement - | return_statement - | throw_statement - ; - -// Source: §13.10.2 The break statement -break_statement - : 'break' ';' - ; - -// Source: §13.10.3 The continue statement -continue_statement - : 'continue' ';' - ; - -// Source: §13.10.4 The goto statement -goto_statement - : 'goto' identifier ';' - | 'goto' 'case' constant_expression ';' - | 'goto' 'default' ';' - ; - -// Source: §13.10.5 The return statement -return_statement - : 'return' expression? ';' - ; - -// Source: §13.10.6 The throw statement -throw_statement - : 'throw' expression? ';' - ; - -// Source: §13.11 The try statement -try_statement - : 'try' block catch_clause+ - | 'try' block finally_clause - | 'try' block catch_clause+ finally_clause - ; - -catch_clauses - : 'catch' exception_specifier? block - ; - -exception_specifier - : '(' type identifier? ')' - ; - -// Source: §13.12 The checked and unchecked statements -checked_statement - : 'checked' block - ; - -unchecked_statement - : 'unchecked' block - ; - -// Source: §13.13 The lock statement -lock_statement - : 'lock' '(' expression ')' embedded_statement - ; - -// Source: §13.14 The using statement -using_statement - : 'using' '(' resource_acquisition ')' embedded_statement - ; - -resource_acquisition - : local_variable_declaration - | expression - ; - -// Source: §13.15 The yield statement -yield_statement - : 'yield' 'return' expression ';' - | 'yield' 'break' ';' - ; - -// Source: §14.2 Compilation units -compilation_unit - : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* - ; - -// Source: §14.3 Namespace declarations -namespace_declaration - : 'namespace' qualified_identifier namespace_body ';'? - ; - -qualified_identifier - : identifier ('.' identifier)* - ; - -namespace_body - : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' - ; - -// Source: §14.4 Extern alias directives -extern_alias_directive - : 'extern' 'alias' identifier ';' - ; - -// Source: §14.5.1 General -using_directive - : using_alias-directive - | using_namespace-directive - ; - -// Source: §14.5.2 Using alias directives -using_alias_directive - : 'using' identifier '=' namespace_or_type_name ';' - ; - -// Source: §14.5.3 Using namespace directives -using_namespace_directive - : 'using' namespace_name ';' - ; - -// Source: §14.6 Namespace member declarations -namespace_member_declaration - : namespace_declaration - | type_declaration - ; - -// Source: §14.7 Type declarations -type_declaration - : class_declaration - | struct_declaration - | interface_declaration - | enum_declaration - | delegate_declaration - ; - -// Source: §14.8.1 General -qualified_alias_member - : identifier '::' identifier type_argument_list? - ; - -// Source: §15.2.1 General -class_declaration - : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? - class_base? type_parameter_constraints_clause* class_body ';'? - ; - -// Source: §15.2.2.1 General -class_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'abstract' - | 'sealed' - | 'static' - ; - -// Source: §15.2.3 Type parameters -type_parameter_list - : '<' type_parameters '>' - ; - -type_parameters - : attributes? type_parameter - | type_parameters ',' attributes? type_parameter - ; - -// Source: §15.2.4.1 General -class_base - : ':' class_type - | ':' interface_type_list - | ':' class_type ',' interface_type_list - ; - -interface_type_list - : interface_type (',' interface_type)* - ; - -// Source: §15.2.5 Type parameter constraints -type_parameter_constraints_clauses - : type_parameter_constraints_clause - | type_parameter_constraints_clauses type_parameter_constraints_clause - ; - -type_parameter_constraints_clause - : 'where' type_parameter ':' type_parameter_constraints - ; - -type_parameter_constraints - : primary_constraint - | secondary_constraints - | constructor_constraint - | primary_constraint ',' secondary_constraints - | primary_constraint ',' constructor_constraint - | secondary_constraints ',' constructor_constraint - | primary_constraint ',' secondary_constraints ',' constructor_constraint - ; - -primary_constraint - : class_type - | 'class' - | 'struct' - ; - -secondary_constraints - : interface_type - | type_parameter - | secondary_constraints ',' interface_type - | secondary_constraints ',' type_parameter - ; - -constructor_constraint - : 'new' '(' ')' - ; - -// Source: §15.2.6 Class body -class_body - : '{' class_member_declaration* '}' - ; - -// Source: §15.3.1 General -class_member_declaration - : constant_declaration - | field_declaration - | method_declaration - | property_declaration - | event_declaration - | indexer_declaration - | operator_declaration - | constructor_declaration - | finalizer_declaration - | static_constructor_declaration - | type_declaration - ; - -// Source: §15.4 Constants -constant_declaration - : attributes? constant_modifier* 'const' type constant_declarators ';' - ; - -constant_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - ; - -// Source: §15.5.1 General -field_declaration - : attributes? field_modifier* type variable_declarators ';' - ; - -field_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'static' - | 'readonly' - | 'volatile' - ; - -variable_declarators - : variable_declarator (',' variable_declarator)* - ; - -variable_declarator - : identifier ('=' variable_initializer)? - ; - -// Source: §15.6.1 General -method_declaration - : method_header method_body - ; - -method_header - : attributes? method_modifier* 'partial'? return_type member_name type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* - ; - -method_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'static' - | 'virtual' - | 'sealed' - | 'override' - | 'abstract' - | 'extern' - | 'async' - ; - -return_type - : type - | 'void' - ; - -member_name - : identifier - | interface_type '.' identifier - ; - -method_body - : block - ; - -// Source: §15.6.2.1 General -formal_parameter_list - : fixed_parameters - | fixed_parameters ',' parameter_array - | parameter_array - ; - -fixed_parameters - : fixed_parameter (',' fixed_parameter)* - ; - -fixed_parameter - : attributes? parameter_modifier? type identifier default_argument? - ; - -default_argument - : '=' expression - ; - -parameter_modifier - : parameter_mode_modifier - | 'this' - ; - -parameter_mode_modifier - : 'ref' - | 'out' - ; - -parameter_array - : attributes? 'params' array_type identifier - ; - -// Source: §15.7.1 General -property_declaration - : attributes? property_modifiers? type member_name '{' accessor_declarations '}' - ; - -property_modifiers - : property_modifier - | property_modifiers property_modifier - ; - -property_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'static' - | 'virtual' - | 'sealed' - | 'override' - | 'abstract' - | 'extern' - ; - -// Source: §15.7.3 Accessors -accessor_declarations - : get_accessor_declaration set_accessor_declaration? - | set_accessor_declaration get_accessor_declaration? - ; - -get_accessor_declaration - : attributes? accessor_modifier? 'get' accessor_body - ; - -set_accessor_declaration - : attributes? accessor_modifier? 'set' accessor_body - ; - -accessor_modifier - : 'protected' - | 'internal' - | 'private' - | 'protected' 'internal' - | 'internal' 'protected' - ; - -accessor_body - : block - | ';' - ; - -// Source: §15.8.1 General -event_declaration - : attributes? event_modifier* 'event' type variable_declarators ';' - | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' - ; - -event_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'static' - | 'virtual' - | 'sealed' - | 'override' - | 'abstract' - | 'extern' - ; - -event_accessor_declarations - : add_accessor_declaration remove_accessor_declaration - | remove_accessor_declaration add_accessor_declaration - ; - -add_accessor_declaration - : attributes? 'add' block - ; - -remove_accessor_declaration - : attributes? 'remove' block - ; - -// Source: §15.9 Indexers -indexer_declaration - : attributes? indexer_modifiers? indexer_declarator '{' accessor_declarations '}' - ; - -indexer_modifiers - : indexer_modifier - | indexer_modifiers indexer_modifier - ; - -indexer_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'virtual' - | 'sealed' - | 'override' - | 'abstract' - | 'extern' - ; - -indexer_declarator - : type 'this' '[' formal_parameter_list ']' - | type interface_type '.' 'this' '[' formal_parameter_list ']' - ; - -// Source: §15.10.1 General -operator_declaration - : attributes? operator_modifier+ operator_declarator operator_body - ; - -operator_modifier - : 'public' - | 'static' - | 'extern' - ; - -operator_declarator - : unary_operator_declarator - | binary_operator_declarator - | conversion_operator_declarator - ; - -unary_operator_declarator - : type 'operator' overloadable_unary_operator '(' fixed_parameter ')' - ; - -overloadable_unary_operator - : '+' | '-' | '!' | '~' | '++' | '--' | 'true' | 'false' - ; - -binary_operator_declarator - : type 'operator' overloadable_binary_operator '(' fixed_parameter ',' fixed_parameter ')' - ; - -overloadable_binary_operator - : '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '<<' - | right_shift | '==' | '!=' | '>' | '<' | '>=' | '<=' - ; - -conversion_operator_declarator - : 'implicit' 'operator' type '(' fixed_parameter ')' - | 'explicit' 'operator' type '(' fixed_parameter ')' - ; - -operator_body - : block - | ';' - ; - -// Source: §15.11.1 General -constructor_declaration - : attributes? constructor_modifier* constructor_declarator constructor_body - ; - -constructor_modifier - : 'public' - | 'protected' - | 'internal' - | 'private' - | 'extern' - ; - -constructor_declarator - : identifier '(' formal_parameter_list? ')' constructor_initializer? - ; - -constructor_initializer - : ':' 'base' '(' argument_list? ')' - | ':' 'this' '(' argument_list? ')' - ; - -constructor_body - : block - | ';' - ; - -// Source: §15.12 Static constructors -static_constructor_declaration - : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body - ; - -static_constructor_modifiers - : 'extern'? 'static' - | 'static' 'extern'? - ; - -static_constructor_body - : block - | ';' - ; - -// Source: §15.13 Finalizers -finalizer_declaration - : attributes? 'extern'? '~' identifier '(' ')' finalizer_body - ; - -finalizer_body - : block - | ';' - ; - -// Source: §16.2.1 General -struct_declaration - : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? - struct_interfaces? type_parameter_constraints_clause* struct_body ';'? - ; - -// Source: §16.2.2 Struct modifiers -struct_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - ; - -// Source: §16.2.4 Struct interfaces -struct_interfaces - : ':' interface_type_list - ; - -// Source: §16.2.5 Struct body -struct_body - : '{' struct_member_declaration* '}' - ; - -// Source: §16.3 Struct members -struct_member_declaration - : constant_declaration - | field_declaration - | method_declaration - | property_declaration - | event_declaration - | indexer_declaration - | operator_declaration - | constructor_declaration - | static_constructor_declaration - | type_declaration - ; - -// Source: §17.7 Array initializers -array_initializer - : '{' variable_initializer_list? '}' - | '{' variable_initializer_list ',' '}' - ; - -variable_initializer_list - : variable_initializer (',' variable_initializer)* - ; - -variable_initializer - : expression - | array_initializer - ; - -// Source: §18.2.1 General -interface_declaration - : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? - ; - -// Source: §18.2.2 Interface modifiers -interface_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - ; - -// Source: §18.2.3.1 General -variant_type_parameter_list - : '<' variant_type_parameters '>' - ; - -// Source: §18.2.3.1 General -variant_type_parameters - : attributes? variance_annotation? type_parameter - | variant_type_parameters ',' attributes? variance_annotation? type_parameter - ; - -// Source: §18.2.3.1 General -variance_annotation - : 'in' - | 'out' - ; - -// Source: §18.2.4 Base interfaces -interface_base - : ':' interface_type_list - ; - -// Source: §18.3 Interface body -interface_body - : '{' interface_member_declaration* '}' - ; - -// Source: §18.4.1 General -interface_member_declaration - : interface_method_declaration - | interface_property_declaration - | interface_event_declaration - | interface_indexer_declaration - ; - -// Source: §18.4.2 Interface methods -interface_method_declaration - : attributes? 'new'? return_type identifier type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' - ; - -// Source: §18.4.3 Interface properties -interface_property_declaration - : attributes? 'new'? type identifier '{' interface_accessors '}' - ; - -// Source: §18.4.3 Interface properties -interface_accessors - : attributes? 'get' ';' - | attributes? 'set' ';' - | attributes? 'get' ';' attributes? 'set' ';' - | attributes? 'set' ';' attributes? 'get' ';' - ; - -// Source: §18.4.4 Interface events -interface_event_declaration - : attributes? 'new'? 'event' type identifier ';' - ; - -// Source: §18.4.5 Interface indexers -interface_indexer_declaration: - attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' - ; - -// Source: §19.2 Enum declarations -enum_declaration - : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? - ; - -enum_base - : ':' struct_type - ; - -enum_body - : '{' enum_member_declarations? '}' - | '{' enum_member_declarations ',' '}' - ; - -// Source: §19.3 Enum modifiers -enum_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - ; - -// Source: §19.4 Enum members -enum_member_declarations - : enum_member_declaration (',' enum_member_declaration)* - ; - -// Source: §19.4 Enum members -enum_member_declaration - : attributes? identifier ('=' constant_expression)? - ; - -// Source: §20.2 Delegate declarations -delegate_declaration - : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' - ; - -delegate_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - ; - -// Source: §22.3 Attribute specification -global_attributes - : global_attribute_section+ - ; - -global_attribute_section - : '[' global_attribute_target_specifier attribute_list ']' - | '[' global_attribute_target_specifier attribute_list ',' ']' - ; - -global_attribute_target_specifier - : global_attribute_target ':' - ; - -global_attribute_target - : identifier - ; - -attributes - : attribute_section+ - ; - -attribute_section - : '[' attribute_target_specifier? attribute_list ']' - | '[' attribute_target_specifier? attribute_list ',' ']' - ; - -attribute_target_specifier - : attribute_target ':' - ; - -attribute_target - : identifier - | keyword - ; - -attribute_list - : attribute (',' attribute)* - ; - -attribute - : attribute_name attribute_arguments? - ; - -attribute_name - : type_name - ; - -attribute_arguments - : '(' positional_argument_list? ')' - | '(' positional_argument_list ',' named_argument_list ')' - | '(' named_argument_list ')' - ; - -positional_argument_list - : positional_argument (',' positional_argument)* - ; - -positional_argument - : argument_name? attribute_argument_expression - ; - -named_argument_list - : named_argument (',' named_argument)* - ; - -named_argument - : identifier '=' attribute_argument_expression - ; - -attribute_argument_expression - : expression - ; - -// Source: §23.2 Unsafe contexts -class_modifier - : ... - | 'unsafe' - ; - -struct_modifier - : ... - | 'unsafe' - ; - -interface_modifier - : ... - | 'unsafe' - ; - -delegate_modifier - : ... - | 'unsafe' - ; - -field_modifier - : ... - | 'unsafe' - ; - -method_modifier - : ... - | 'unsafe' - ; - -property_modifier - : '...' - | 'unsafe' - ; - -event_modifier - : ... - | 'unsafe' - -indexer_modifier - : ... - | 'unsafe' - ; - -operator_modifier - : ... - | 'unsafe' - ; - -constructor_modifier - : ... - | 'unsafe' - ; - -finalizer_declaration - : attributes? 'extern'? 'unsafe'? '~' identifier '(' ')' finalizer_body - | attributes? 'unsafe'? 'extern'? '~' identifier '(' ')' finalizer_body - ; - -static_constructor_modifiers - : 'extern'? 'unsafe'? 'static' - | 'unsafe'? 'extern'? 'static' - | 'extern'? 'static' 'unsafe'? - | 'unsafe'? 'static' 'extern'? - | 'static' 'extern'? 'unsafe'? - | 'static' 'unsafe'? 'extern'? - ; - -embedded_statement - : ... - | unsafe_statement - | fixed_statement - ; - -unsafe_statement - : 'unsafe' block - ; - -// Source: §23.3 Pointer types -type - : ... - | pointer_type - ; - -non_array_type - : ... - | pointer_type - ; - -// Source: §23.3 Pointer types -pointer_type - : unmanaged_type '*' - | 'void' '*' - ; - -unmanaged_type - : type - ; - -// Source: §23.6.1 General -primary_no_array_creation_expression - : ... - | pointer_member_access - | pointer_element_access - ; - -unary_expression - : ... - | pointer_indirection_expression - | addressof_expression - ; - -// Source: §23.6.2 Pointer indirection -pointer_indirection_expression - : '*' unary_expression - ; - -// Source: §23.6.3 Pointer member access -pointer_member_access - : primary_expression '->' identifier type_argument_list? - ; - -// Source: §23.6.4 Pointer element access -pointer_element_access - : primary_no_array_creation_expression '[' expression ']' - ; - -// Source: §23.6.5 The address-of operator -addressof_expression - : '&' unary_expression - ; - -// Source: §23.7 The fixed statement -fixed_statement - : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement - ; - -fixed_pointer_declarators - : fixed_pointer_declarator (',' fixed_pointer_declarator)* - ; - -fixed_pointer_declarator - : identifier '=' fixed_pointer_initializer - ; - -fixed_pointer_initializer - : '&' variable_reference - | expression - ; - -// Source: §23.8.2 Fixed-size buffer declarations -struct_member_declaration - : ... - | fixed_size_buffer_declaration - ; - -fixed_size_buffer_declaration - : attributes? fixed_size_buffer_modifier* 'fixed' buffer_element_type fixed_size_buffer_declarator+ ';' - ; - -fixed_size_buffer_modifier - : 'new' - | 'public' - | 'protected' - | 'internal' - | 'private' - | 'unsafe' - ; - -buffer_element_type - : type - ; - -fixed_size_buffer_declarator - : identifier '[' constant_expression ']' - ; - -// Source: §23.9 Stack allocation -local_variable_initializer - : ... - | stackalloc_initializer - ; - -stackalloc_initializer - : 'stackalloc' unmanaged_type '[' expression ']' - ; From 3d2c28f391091cef438c7028e573fdc720435171 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 27 Jan 2021 15:33:05 -0500 Subject: [PATCH 7/8] update script to generate annex --- tools/update-grammar-annex.sh | 136 +++++++++++----------------------- 1 file changed, 42 insertions(+), 94 deletions(-) diff --git a/tools/update-grammar-annex.sh b/tools/update-grammar-annex.sh index f6ee57605..0b10b2195 100755 --- a/tools/update-grammar-annex.sh +++ b/tools/update-grammar-annex.sh @@ -1,103 +1,51 @@ #!/bin/sh -dotnet build -c Release -dotnet publish -o publish -rm grammar.g4 -rm ../../standard/grammar.md +#!/bin/bash + +declare -r GRAMMAR_PROJECT=GetGrammar +declare -r SPEC_DIRECTORY=../standard +declare -r OUTPUT_FILE=../standard/grammar.md + +# Note that lexical structure and unsafe code are not in the array +# There are headers inserted before them. +declare -a SPEC_FILES=( + "basic-concepts.md" + "types.md" + "variables.md" + "conversions.md" + "expressions.md" + "statements.md" + "namespaces.md" + "classes.md" + "structs.md" + "arrays.md" + "interfaces.md" + "enums.md" + "delegates.md" + "exceptions.md" + "attributes.md" + ) + +dotnet build $GRAMMAR_PROJECT -c Release +dotnet publish $GRAMMAR_PROJECT -c Release -o $GRAMMAR_PROJECT/publish + +rm $OUTPUT_FILE + echo Insert General/Lexical Headers -cat grammar-general-lexical-insert.md >../../standard/grammar.md -echo Extract Lexical Grammar -dotnet publish/GetGrammar.dll ../../standard/lexical-structure.md >lexical-structure.g4 -cat lexical-structure.g4 >grammar.g4 -cat lexical-structure.g4 >>../../standard/grammar.md -rm lexical-structure.g4 +cat $GRAMMAR_PROJECT/grammar-general-lexical-insert.md >$OUTPUT_FILE +dotnet $GRAMMAR_PROJECT/publish/$GRAMMAR_PROJECT.dll $SPEC_DIRECTORY/lexical-structure.md >>$OUTPUT_FILE echo Insert Syntactic Header -cat grammar-syntactic-insert.md >>../../standard/grammar.md -echo Extract Syntactic Grammar - -dotnet publish/GetGrammar.dll ../../standard/basic-concepts.md >basic-concepts.g4 -cat basic-concepts.g4 >>grammar.g4 -cat basic-concepts.g4 >>../../standard/grammar.md -rm basic-concepts.g4 - -dotnet publish/GetGrammar.dll ../../standard/types.md >types.g4 -cat types.g4 >>grammar.g4 -cat types.g4 >>../../standard/grammar.md -rm types.g4 - -dotnet publish/GetGrammar.dll ../../standard/variables.md >variables.g4 -cat variables.g4 >>grammar.g4 -cat variables.g4 >>../../standard/grammar.md -rm variables.g4 - -dotnet publish/GetGrammar.dll ../../standard/conversions.md >conversions.g4 -cat conversions.g4 >>grammar.g4 -cat conversions.g4 >>../../standard/grammar.md -rm conversions.g4 - -dotnet publish/GetGrammar.dll ../../standard/expressions.md >expressions.g4 -cat expressions.g4 >>grammar.g4 -cat expressions.g4 >>../../standard/grammar.md -rm expressions.g4 - -dotnet publish/GetGrammar.dll ../../standard/statements.md >statements.g4 -cat statements.g4 >>grammar.g4 -cat statements.g4 >>../../standard/grammar.md -rm statements.g4 - -dotnet publish/GetGrammar.dll ../../standard/namespaces.md >namespaces.g4 -cat namespaces.g4 >>grammar.g4 -cat namespaces.g4 >>../../standard/grammar.md -rm namespaces.g4 +cat $GRAMMAR_PROJECT/grammar-syntactic-insert.md >>$OUTPUT_FILE -dotnet publish/GetGrammar.dll ../../standard/classes.md >classes.g4 -cat classes.g4 >>grammar.g4 -cat classes.g4 >>../../standard/grammar.md -rm classes.g4 - -dotnet publish/GetGrammar.dll ../../standard/structs.md >structs.g4 -cat structs.g4 >>grammar.g4 -cat structs.g4 >>../../standard/grammar.md -rm structs.g4 - -dotnet publish/GetGrammar.dll ../../standard/arrays.md >arrays.g4 -cat arrays.g4 >>grammar.g4 -cat arrays.g4 >>../../standard/grammar.md -rm arrays.g4 - -dotnet publish/GetGrammar.dll ../../standard/interfaces.md >interfaces.g4 -cat interfaces.g4 >>grammar.g4 -cat interfaces.g4 >>../../standard/grammar.md -rm interfaces.g4 - -dotnet publish/GetGrammar.dll ../../standard/enums.md >enums.g4 -cat enums.g4 >>grammar.g4 -cat enums.g4 >>../../standard/grammar.md -rm enums.g4 - -dotnet publish/GetGrammar.dll ../../standard/delegates.md >delegates.g4 -cat delegates.g4 >>grammar.g4 -cat delegates.g4 >>../../standard/grammar.md -rm delegates.g4 - -dotnet publish/GetGrammar.dll ../../standard/exceptions.md >exceptions.g4 -cat exceptions.g4 >>grammar.g4 -cat exceptions.g4 >>../../standard/grammar.md -rm exceptions.g4 - -dotnet publish/GetGrammar.dll ../../standard/attributes.md >attributes.g4 -cat attributes.g4 >>grammar.g4 -cat attributes.g4 >>../../standard/grammar.md -rm attributes.g4 +for file in "${SPEC_FILES[@]}" +do + echo "$file" + dotnet $GRAMMAR_PROJECT/publish/$GRAMMAR_PROJECT.dll $SPEC_DIRECTORY/$file >>$OUTPUT_FILE +done echo Insert Unsafe Header -cat grammar-unsafe-extensions-insert.md >>../../standard/grammar.md -echo Extract Unsafe Grammar -dotnet publish/GetGrammar.dll ../../standard/unsafe-code.md >unsafe-code.g4 -cat unsafe-code.g4 >>grammar.g4 -cat unsafe-code.g4 >>../../standard/grammar.md -rm unsafe-code.g4 - +cat $GRAMMAR_PROJECT/grammar-unsafe-extensions-insert.md >>$OUTPUT_FILE +dotnet $GRAMMAR_PROJECT/publish/$GRAMMAR_PROJECT.dll $SPEC_DIRECTORY/unsafe-code.md >>$OUTPUT_FILE echo Insert EOF Stuff -cat grammar-eof-insert.md >>../../standard/grammar.md +cat $GRAMMAR_PROJECT/grammar-eof-insert.md >>$OUTPUT_FILE From d7109b5e7c31005ae27dabf2c3e0f32606d6b9e6 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 28 Jan 2021 09:52:01 -0500 Subject: [PATCH 8/8] respond to feedback. --- ...mmar-vlidator.yaml => grammar-validator.yaml} | 2 +- tools/GetGrammar/Program.cs | 16 ++++++++-------- tools/update-grammar-annex.sh | 3 +-- tools/validate-grammar.sh | 1 + 4 files changed, 11 insertions(+), 11 deletions(-) rename .github/workflows/{grammar-vlidator.yaml => grammar-validator.yaml} (94%) diff --git a/.github/workflows/grammar-vlidator.yaml b/.github/workflows/grammar-validator.yaml similarity index 94% rename from .github/workflows/grammar-vlidator.yaml rename to .github/workflows/grammar-validator.yaml index 1ab7347e1..f76c5603f 100644 --- a/.github/workflows/grammar-vlidator.yaml +++ b/.github/workflows/grammar-validator.yaml @@ -1,4 +1,4 @@ -name: ANTLR Grammar validatior +name: ANTLR Grammar validator # Triggers the workflow on push or pull request events on: [push, pull_request, workflow_dispatch] diff --git a/tools/GetGrammar/Program.cs b/tools/GetGrammar/Program.cs index a509de02e..d99ecd534 100644 --- a/tools/GetGrammar/Program.cs +++ b/tools/GetGrammar/Program.cs @@ -38,10 +38,9 @@ public static async Task Main(string[] args) Environment.Exit(1); } using var inputFile = new StreamReader(args[0]); - string? inputLine; string section = ""; - while ((inputLine = await inputFile.ReadLineAsync()) != null) + while (await inputFile.ReadLineAsync() is string inputLine) { if (inputLine.StartsWith("#")) { @@ -56,26 +55,27 @@ public static async Task Main(string[] args) Console.WriteLine(); // write out blank line before each new production Console.WriteLine($"// Source: §{section}"); + // This loop might be a candidate for a bit of refactoring. while (true) { - inputLine = await inputFile.ReadLineAsync(); - if (inputLine == null) + string? nextLine = await inputFile.ReadLineAsync(); + if (nextLine == null) { Console.WriteLine("Unexpected EOF; no closing grammar fence"); Environment.Exit(1); } - if (inputLine.Length < 3) // Is it long enough to contain a closing fence? + if (nextLine.Length < 3) // Is it long enough to contain a closing fence? { - Console.WriteLine(inputLine); + Console.WriteLine(nextLine); } - else if (inputLine.Substring(0, 3) == "```") // If line starts with ``` + else if (nextLine.Substring(0, 3) == "```") // If line starts with ``` { // Console.WriteLine("------ End of a production"); break; } else { - Console.WriteLine(inputLine); + Console.WriteLine(nextLine); } } } diff --git a/tools/update-grammar-annex.sh b/tools/update-grammar-annex.sh index 0b10b2195..e17b56ed9 100755 --- a/tools/update-grammar-annex.sh +++ b/tools/update-grammar-annex.sh @@ -1,6 +1,5 @@ -#!/bin/sh - #!/bin/bash +set -eu -o pipefail declare -r GRAMMAR_PROJECT=GetGrammar declare -r SPEC_DIRECTORY=../standard diff --git a/tools/validate-grammar.sh b/tools/validate-grammar.sh index d75748d8b..d462f541e 100755 --- a/tools/validate-grammar.sh +++ b/tools/validate-grammar.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -eu -o pipefail declare -r GRAMMAR_PROJECT=GetGrammar declare -r SPEC_DIRECTORY=../standard