Sfoglia il codice sorgente

Merge pull request #156 from amaanq/fixes

Some fixes
pull/158/head
Amaan Qureshi 3 anni fa
committed by GitHub
parent
commit
cc565c46f9
Non sono state trovate chiavi note per questa firma nel database ID Chiave GPG: 4AEE18F83AFDEB23
5 ha cambiato i file con 27464 aggiunte e 27258 eliminazioni
  1. +7
    -7
      grammar.js
  2. +25
    -13
      src/grammar.json
  3. +27412
    -27236
      src/parser.c
  4. +13
    -1
      test/corpus/expressions.txt
  5. +7
    -1
      test/corpus/preprocessor.txt

+ 7
- 7
grammar.js Vedi File

@ -12,8 +12,8 @@
const PREC = { const PREC = {
PAREN_DECLARATOR: -10, PAREN_DECLARATOR: -10,
ASSIGNMENT: -1,
CONDITIONAL: -2,
ASSIGNMENT: -2,
CONDITIONAL: -1,
DEFAULT: 0, DEFAULT: 0,
LOGICAL_OR: 1, LOGICAL_OR: 1,
LOGICAL_AND: 2, LOGICAL_AND: 2,
@ -117,14 +117,14 @@ module.exports = grammar({
$.identifier, $.identifier,
alias($.preproc_call_expression, $.call_expression), alias($.preproc_call_expression, $.call_expression),
)), )),
'\n',
token.immediate(/\r?\n/),
), ),
preproc_def: $ => seq( preproc_def: $ => seq(
preprocessor('define'), preprocessor('define'),
field('name', $.identifier), field('name', $.identifier),
field('value', optional($.preproc_arg)), field('value', optional($.preproc_arg)),
'\n',
token.immediate(/\r?\n/),
), ),
preproc_function_def: $ => seq( preproc_function_def: $ => seq(
@ -132,7 +132,7 @@ module.exports = grammar({
field('name', $.identifier), field('name', $.identifier),
field('parameters', $.preproc_params), field('parameters', $.preproc_params),
field('value', optional($.preproc_arg)), field('value', optional($.preproc_arg)),
'\n',
token.immediate(/\r?\n/),
), ),
preproc_params: $ => seq( preproc_params: $ => seq(
@ -142,13 +142,13 @@ module.exports = grammar({
preproc_call: $ => seq( preproc_call: $ => seq(
field('directive', $.preproc_directive), field('directive', $.preproc_directive),
field('argument', optional($.preproc_arg)), field('argument', optional($.preproc_arg)),
'\n',
token.immediate(/\r?\n/),
), ),
...preprocIf('', $ => $._block_item), ...preprocIf('', $ => $._block_item),
...preprocIf('_in_field_declaration_list', $ => $._field_declaration_list_item), ...preprocIf('_in_field_declaration_list', $ => $._field_declaration_list_item),
preproc_arg: _ => token(prec(-1, /\S(.|\\\r?\n)*/)),
preproc_arg: _ => token(prec(-1, /\S([^/\n]|\\\r?\n)*/)),
preproc_directive: _ => /#[ \t]*[a-zA-Z0-9]\w*/, preproc_directive: _ => /#[ \t]*[a-zA-Z0-9]\w*/,
_preproc_expression: $ => choice( _preproc_expression: $ => choice(

+ 25
- 13
src/grammar.json Vedi File

@ -166,8 +166,11 @@
} }
}, },
{ {
"type": "STRING",
"value": "\n"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
} }
] ]
}, },
@ -208,8 +211,11 @@
} }
}, },
{ {
"type": "STRING",
"value": "\n"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
} }
] ]
}, },
@ -258,8 +264,11 @@
} }
}, },
{ {
"type": "STRING",
"value": "\n"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
} }
] ]
}, },
@ -358,8 +367,11 @@
} }
}, },
{ {
"type": "STRING",
"value": "\n"
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
} }
] ]
}, },
@ -1010,7 +1022,7 @@
"value": -1, "value": -1,
"content": { "content": {
"type": "PATTERN", "type": "PATTERN",
"value": "\\S(.|\\\\\\r?\\n)*"
"value": "\\S([^/\\n]|\\\\\\r?\\n)*"
} }
} }
}, },
@ -4954,7 +4966,7 @@
}, },
"conditional_expression": { "conditional_expression": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": -2,
"value": -1,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -5032,7 +5044,7 @@
}, },
"assignment_expression": { "assignment_expression": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": -1,
"value": -2,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -7779,8 +7791,8 @@
], ],
"PREC": { "PREC": {
"PAREN_DECLARATOR": -10, "PAREN_DECLARATOR": -10,
"ASSIGNMENT": -1,
"CONDITIONAL": -2,
"ASSIGNMENT": -2,
"CONDITIONAL": -1,
"DEFAULT": 0, "DEFAULT": 0,
"LOGICAL_OR": 1, "LOGICAL_OR": 1,
"LOGICAL_AND": 2, "LOGICAL_AND": 2,

+ 27412
- 27236
src/parser.c
File diff soppresso perché troppo grande
Vedi File


+ 13
- 1
test/corpus/expressions.txt Vedi File

@ -504,6 +504,7 @@ int main() {
q /= r; q /= r;
*s++ = 1; *s++ = 1;
(*t) = 1; (*t) = 1;
a *= ((b!=c) ? d : e);
} }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -573,7 +574,18 @@ int main() {
left: (parenthesized_expression left: (parenthesized_expression
(pointer_expression (pointer_expression
argument: (identifier))) argument: (identifier)))
right: (number_literal))))))
right: (number_literal)))
(expression_statement
(assignment_expression
left: (identifier)
right: (parenthesized_expression
(conditional_expression
condition: (parenthesized_expression
(binary_expression
left: (identifier)
right: (identifier)))
consequence: (identifier)
alternative: (identifier))))))))
================================================================================ ================================================================================
Pointer operations Pointer operations

+ 7
- 1
test/corpus/preprocessor.txt Vedi File

@ -40,6 +40,8 @@ Object-like macro definitions
#define SIX(a, \ #define SIX(a, \
b) x \ b) x \
+ y + y
#define SEVEN 7/* seven has an
* annoying comment */
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -66,7 +68,11 @@ Object-like macro definitions
parameters: (preproc_params parameters: (preproc_params
(identifier) (identifier)
(identifier)) (identifier))
value: (preproc_arg)))
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg)
(comment)))
================================================================================ ================================================================================
Function-like macro definitions Function-like macro definitions

Caricamento…
Annulla
Salva