diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-27 00:38:29 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-27 00:38:29 -0600 |
| commit | c7a3c7b7d606b00fa1c676e244c39002b8fc1609 (patch) | |
| tree | 7dfd47c1782765ffa158740a3f1bc2d8474e29f1 | |
| parent | 9b93fb6561ff5b170b73979e18626e78c770b78c (diff) | |
| download | nimterop-c7a3c7b7d606b00fa1c676e244c39002b8fc1609.tar.gz nimterop-c7a3c7b7d606b00fa1c676e244c39002b8fc1609.zip | |
Fix typedef struct bug
| -rw-r--r-- | nimterop/grammar.nim | 42 | ||||
| -rw-r--r-- | toast.nim | 13 |
2 files changed, 35 insertions, 20 deletions
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index aa364b1..bb789bc 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -100,27 +100,32 @@ proc initGrammar() = gStateRT.typeStr &= &" {fname}*: {ftyp}\n" i += 2 - let fieldGrammar = """ - (field_identifier?) - (array_declarator? - (field_identifier) - (identifier|number_literal) - ) - """ + let + fieldGrammar = """ + (field_identifier?) + (array_declarator? + (field_identifier) + (identifier|number_literal) + ) + """ + + fieldListGrammar = &""" + (field_declaration_list + (field_declaration+ + {typeGrammar} + {fieldGrammar} + (pointer_declarator? + {fieldGrammar} + ) + ) + ) + """ # struct X {} gStateRT.grammar.add((&""" (struct_specifier|union_specifier (type_identifier) - (field_declaration_list - (field_declaration+ - {typeGrammar} - {fieldGrammar} - (pointer_declarator? - {fieldGrammar} - ) - ) - ) + {fieldListGrammar} ) """, proc (ast: ref Ast, node: TSNode) = @@ -130,7 +135,10 @@ proc initGrammar() = # typedef struct X {} gStateRT.grammar.add((&""" (type_definition - {gStateRT.grammar[^1].grammar} + (struct_specifier|union_specifier + (type_identifier?) + {fieldListGrammar} + ) (type_identifier) ) """, @@ -4,7 +4,7 @@ import treesitter/runtime import treesitter_c/c import treesitter_cpp/cpp -import nimterop/[ast, globals, getters] +import nimterop/[ast, globals, getters, grammar] proc printLisp(root: TSNode) = var @@ -112,6 +112,7 @@ proc main( pnim = false, pretty = true, preprocess = false, + pgrammar = false, defines: seq[string] = @[], includeDirs: seq[string] = @[], source: seq[string], @@ -126,7 +127,11 @@ proc main( defines: defines, includeDirs: includeDirs, ) - if source.len != 0: + + if pgrammar: + parseGrammar() + printGrammar() + elif source.len != 0: process(source[0]) when isMainModule: @@ -138,11 +143,13 @@ when isMainModule: "defines": "definitions to pass to preprocessor", "includeDirs": "include directory to pass to preprocessor", "preprocess": "run preprocessor on header", + "pgrammar": "print grammar", "source" : "C/C++ source/header", }, short = { "past": 'a', "pnim": 'n', "defines": 'D', "includeDirs": 'I', - "preprocess": 'p' + "preprocess": 'p', + "pgrammar": 'g' }) |
