Просмотр исходного кода

Support attribute statements under case statements (#83)

pull/53/merge
jdrouhard 4 лет назад
committed by GitHub
Родитель
Сommit
9bee34500c
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
5 измененных файлов: 40030 добавлений и 39328 удалений
  1. +7
    -0
      grammar.js
  2. +29
    -0
      src/grammar.json
  3. +4
    -0
      src/node-types.json
  4. +39966
    -39315
      src/parser.c
  5. +24
    -13
      test/corpus/statements.txt

+ 7
- 0
grammar.js Просмотреть файл

@ -47,6 +47,7 @@ module.exports = grammar({
[$._type_specifier, $.macro_type_specifier], [$._type_specifier, $.macro_type_specifier],
[$.sized_type_specifier], [$.sized_type_specifier],
[$._declaration_modifiers, $.attributed_statement], [$._declaration_modifiers, $.attributed_statement],
[$._declaration_modifiers, $.attributed_non_case_statement],
], ],
word: $ => $.identifier, word: $ => $.identifier,
@ -596,6 +597,11 @@ module.exports = grammar({
$._statement $._statement
), ),
attributed_non_case_statement: $ => seq(
repeat1($.attribute_declaration),
$._non_case_statement
),
_statement: $ => choice( _statement: $ => choice(
$.case_statement, $.case_statement,
$._non_case_statement $._non_case_statement
@ -653,6 +659,7 @@ module.exports = grammar({
), ),
':', ':',
repeat(choice( repeat(choice(
alias($.attributed_non_case_statement, $.attributed_statement),
$._non_case_statement, $._non_case_statement,
$.declaration, $.declaration,
$.type_definition $.type_definition

+ 29
- 0
src/grammar.json Просмотреть файл

@ -3786,6 +3786,22 @@
} }
] ]
}, },
"attributed_non_case_statement": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "attribute_declaration"
}
},
{
"type": "SYMBOL",
"name": "_non_case_statement"
}
]
},
"_statement": { "_statement": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -4023,6 +4039,15 @@
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "attributed_non_case_statement"
},
"named": true,
"value": "attributed_statement"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_non_case_statement" "name": "_non_case_statement"
@ -6552,6 +6577,10 @@
[ [
"_declaration_modifiers", "_declaration_modifiers",
"attributed_statement" "attributed_statement"
],
[
"_declaration_modifiers",
"attributed_non_case_statement"
] ]
], ],
"precedences": [], "precedences": [],

+ 4
- 0
src/node-types.json Просмотреть файл

@ -852,6 +852,10 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "attributed_statement",
"named": true
},
{ {
"type": "break_statement", "type": "break_statement",
"named": true "named": true

+ 39966
- 39315
src/parser.c
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 24
- 13
test/corpus/statements.txt Просмотреть файл

@ -267,6 +267,9 @@ Attributes
void f() { void f() {
[[a]] switch (b) { [[a]] switch (b) {
[[c]] case 1: {} [[c]] case 1: {}
case 2:
[[fallthrough]];
default:
} }
[[a]] while (true) {} [[a]] while (true) {}
[[a]] if (true) {} [[a]] if (true) {}
@ -284,17 +287,25 @@ void f() {
(function_definition (primitive_type) (function_definition (primitive_type)
(function_declarator (identifier) (parameter_list)) (function_declarator (identifier) (parameter_list))
(compound_statement (compound_statement
(attributed_statement (attribute_declaration (attribute (identifier)))
(switch_statement
(parenthesized_expression (identifier))
(compound_statement
(attributed_statement (attribute_declaration (attribute (identifier))) (case_statement (number_literal) (compound_statement))))))
(attributed_statement (attribute_declaration (attribute (identifier))) (while_statement (parenthesized_expression (true)) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (if_statement (parenthesized_expression (true)) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (for_statement (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (return_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (expression_statement (identifier)))
(attributed_statement (attribute_declaration (attribute (identifier))) (expression_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (labeled_statement (statement_identifier) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (goto_statement (statement_identifier))))))
(attributed_statement
(attribute_declaration (attribute (identifier)))
(switch_statement
(parenthesized_expression (identifier))
(compound_statement
(attributed_statement
(attribute_declaration (attribute (identifier)))
(case_statement (number_literal) (compound_statement)))
(case_statement (number_literal)
(attributed_statement
(attribute_declaration (attribute (identifier)))
(expression_statement)))
(case_statement))))
(attributed_statement (attribute_declaration (attribute (identifier))) (while_statement (parenthesized_expression (true)) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (if_statement (parenthesized_expression (true)) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (for_statement (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (return_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (expression_statement (identifier)))
(attributed_statement (attribute_declaration (attribute (identifier))) (expression_statement))
(attributed_statement (attribute_declaration (attribute (identifier))) (labeled_statement (statement_identifier) (compound_statement)))
(attributed_statement (attribute_declaration (attribute (identifier))) (goto_statement (statement_identifier))))))

Загрузка…
Отмена
Сохранить