Explorar el Código

Support attribute statements under case statements (#83)

pull/53/merge
jdrouhard hace 4 años
cometido por GitHub
padre
commit
9bee34500c
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 5 ficheros con 40030 adiciones y 39328 borrados
  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 Ver fichero

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

+ 29
- 0
src/grammar.json Ver fichero

@ -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": {
"type": "CHOICE",
"members": [
@ -4023,6 +4039,15 @@
"content": {
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "attributed_non_case_statement"
},
"named": true,
"value": "attributed_statement"
},
{
"type": "SYMBOL",
"name": "_non_case_statement"
@ -6552,6 +6577,10 @@
[
"_declaration_modifiers",
"attributed_statement"
],
[
"_declaration_modifiers",
"attributed_non_case_statement"
]
],
"precedences": [],

+ 4
- 0
src/node-types.json Ver fichero

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

+ 39966
- 39315
src/parser.c
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


+ 24
- 13
test/corpus/statements.txt Ver fichero

@ -267,6 +267,9 @@ Attributes
void f() {
[[a]] switch (b) {
[[c]] case 1: {}
case 2:
[[fallthrough]];
default:
}
[[a]] while (true) {}
[[a]] if (true) {}
@ -284,17 +287,25 @@ void f() {
(function_definition (primitive_type)
(function_declarator (identifier) (parameter_list))
(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))))))

Cargando…
Cancelar
Guardar