Browse Source

Merge pull request #156 from amaanq/fixes

Some fixes
pull/158/head
Amaan Qureshi 3 years ago
committed by GitHub
parent
commit
cc565c46f9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27464 additions and 27258 deletions
  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 View File

@ -12,8 +12,8 @@
const PREC = {
PAREN_DECLARATOR: -10,
ASSIGNMENT: -1,
CONDITIONAL: -2,
ASSIGNMENT: -2,
CONDITIONAL: -1,
DEFAULT: 0,
LOGICAL_OR: 1,
LOGICAL_AND: 2,
@ -117,14 +117,14 @@ module.exports = grammar({
$.identifier,
alias($.preproc_call_expression, $.call_expression),
)),
'\n',
token.immediate(/\r?\n/),
),
preproc_def: $ => seq(
preprocessor('define'),
field('name', $.identifier),
field('value', optional($.preproc_arg)),
'\n',
token.immediate(/\r?\n/),
),
preproc_function_def: $ => seq(
@ -132,7 +132,7 @@ module.exports = grammar({
field('name', $.identifier),
field('parameters', $.preproc_params),
field('value', optional($.preproc_arg)),
'\n',
token.immediate(/\r?\n/),
),
preproc_params: $ => seq(
@ -142,13 +142,13 @@ module.exports = grammar({
preproc_call: $ => seq(
field('directive', $.preproc_directive),
field('argument', optional($.preproc_arg)),
'\n',
token.immediate(/\r?\n/),
),
...preprocIf('', $ => $._block_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_expression: $ => choice(

+ 25
- 13
src/grammar.json View 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,
"content": {
"type": "PATTERN",
"value": "\\S(.|\\\\\\r?\\n)*"
"value": "\\S([^/\\n]|\\\\\\r?\\n)*"
}
}
},
@ -4954,7 +4966,7 @@
},
"conditional_expression": {
"type": "PREC_RIGHT",
"value": -2,
"value": -1,
"content": {
"type": "SEQ",
"members": [
@ -5032,7 +5044,7 @@
},
"assignment_expression": {
"type": "PREC_RIGHT",
"value": -1,
"value": -2,
"content": {
"type": "SEQ",
"members": [
@ -7779,8 +7791,8 @@
],
"PREC": {
"PAREN_DECLARATOR": -10,
"ASSIGNMENT": -1,
"CONDITIONAL": -2,
"ASSIGNMENT": -2,
"CONDITIONAL": -1,
"DEFAULT": 0,
"LOGICAL_OR": 1,
"LOGICAL_AND": 2,

+ 27412
- 27236
src/parser.c
File diff suppressed because it is too large
View File


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

@ -504,6 +504,7 @@ int main() {
q /= r;
*s++ = 1;
(*t) = 1;
a *= ((b!=c) ? d : e);
}
--------------------------------------------------------------------------------
@ -573,7 +574,18 @@ int main() {
left: (parenthesized_expression
(pointer_expression
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

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

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

Loading…
Cancel
Save