Procházet zdrojové kódy

Merge pull request #1 from maxbrunsfeld/mb-fix-preprocessor-issues

Fix preprocessor issues
pull/2/head
Max Brunsfeld před 10 roky
rodič
revize
c33aae8d9e
4 změnil soubory, kde provedl 7821 přidání a 9900 odebrání
  1. +19
    -5
      grammar.coffee
  2. +30
    -9
      grammar_test/preprocessor.txt
  3. +1
    -1
      package.json
  4. +7771
    -9885
      src/parser.c

+ 19
- 5
grammar.coffee Zobrazit soubor

@ -52,23 +52,37 @@ module.exports = grammar
_preproc_statement: -> choice(
@preproc_ifdef,
@preproc_include,
@preproc_define,
@preproc_def,
@preproc_function_def,
@preproc_call)
preproc_include: -> seq(
"#include",
choice(@string_literal, @system_lib_string))
preproc_define: -> seq(
preproc_def: -> seq(
"#define",
@identifier,
optional(@_preproc_arg))
optional(@preproc_arg),
'\n')
preproc_function_def: -> seq(
"#define",
@identifier,
@preproc_params,
optional(@preproc_arg),
'\n')
preproc_params: -> seq(
'(',
commaSep(choice(@identifier, '...')),
')')
preproc_call: -> seq(
@preproc_directive,
@_preproc_arg)
@preproc_arg)
_preproc_arg: -> token(prec(-1, repeat(choice(/./, "\\\n"))))
preproc_arg: -> token(prec(-1, repeat1(choice(/./, "\\\n"))))
preproc_ifdef: -> seq(
choice("#ifdef", "#ifndef"),

+ 30
- 9
grammar_test/preprocessor.txt Zobrazit soubor

@ -12,20 +12,41 @@ Include directives
(preproc_include (system_lib_string)))
============================================
Defines
Object-like macro definitions
============================================
#define SIZE 1024
#define ONE
#define TWO int a = b;
#define THREE \
c == d ? \
e : \
f
#define SOMETHING \
x + \
y
---
(translation_unit
(preproc_def (identifier))
(preproc_def (identifier) (preproc_arg))
(preproc_def (identifier) (preproc_arg)))
============================================
Function-like macro definitions
============================================
#define ONE() a
#define TWO(b) c
#define THREE(d, e) f
#define FOUR(...) g
#define FIVE(h, i, ...) j
---
(translation_unit
(preproc_define (identifier))
(preproc_define (identifier)))
(preproc_function_def (identifier) (preproc_params) (preproc_arg))
(preproc_function_def (identifier) (preproc_params (identifier)) (preproc_arg))
(preproc_function_def (identifier) (preproc_params (identifier) (identifier)) (preproc_arg))
(preproc_function_def (identifier) (preproc_params) (preproc_arg))
(preproc_function_def (identifier) (preproc_params (identifier) (identifier)) (preproc_arg)))
============================================
Ifdefs
@ -60,10 +81,10 @@ int b;
(preproc_ifdef
(identifier)
(declaration (identifier) (identifier))
(preproc_define (identifier))
(preproc_def (identifier) (preproc_arg))
(preproc_else
(declaration (identifier) (identifier))
(preproc_define (identifier))))
(preproc_def (identifier) (preproc_arg))))
(preproc_ifdef
(identifier)

+ 1
- 1
package.json Zobrazit soubor

@ -14,7 +14,7 @@
"nan": "2.1.0"
},
"devDependencies": {
"tree-sitter-compiler": ">= 0.0.27"
"tree-sitter-compiler": ">= 0.0.30"
},
"scripts": {
"prepublish": "tree-sitter compile",

+ 7771
- 9885
src/parser.c
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


Načítá se…
Zrušit
Uložit