Fix typedef struct bug
This commit is contained in:
parent
9b93fb6561
commit
c7a3c7b7d6
2 changed files with 35 additions and 20 deletions
|
|
@ -100,7 +100,8 @@ proc initGrammar() =
|
||||||
gStateRT.typeStr &= &" {fname}*: {ftyp}\n"
|
gStateRT.typeStr &= &" {fname}*: {ftyp}\n"
|
||||||
i += 2
|
i += 2
|
||||||
|
|
||||||
let fieldGrammar = """
|
let
|
||||||
|
fieldGrammar = """
|
||||||
(field_identifier?)
|
(field_identifier?)
|
||||||
(array_declarator?
|
(array_declarator?
|
||||||
(field_identifier)
|
(field_identifier)
|
||||||
|
|
@ -108,10 +109,7 @@ proc initGrammar() =
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# struct X {}
|
fieldListGrammar = &"""
|
||||||
gStateRT.grammar.add((&"""
|
|
||||||
(struct_specifier|union_specifier
|
|
||||||
(type_identifier)
|
|
||||||
(field_declaration_list
|
(field_declaration_list
|
||||||
(field_declaration+
|
(field_declaration+
|
||||||
{typeGrammar}
|
{typeGrammar}
|
||||||
|
|
@ -121,6 +119,13 @@ proc initGrammar() =
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# struct X {}
|
||||||
|
gStateRT.grammar.add((&"""
|
||||||
|
(struct_specifier|union_specifier
|
||||||
|
(type_identifier)
|
||||||
|
{fieldListGrammar}
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode) =
|
proc (ast: ref Ast, node: TSNode) =
|
||||||
|
|
@ -130,7 +135,10 @@ proc initGrammar() =
|
||||||
# typedef struct X {}
|
# typedef struct X {}
|
||||||
gStateRT.grammar.add((&"""
|
gStateRT.grammar.add((&"""
|
||||||
(type_definition
|
(type_definition
|
||||||
{gStateRT.grammar[^1].grammar}
|
(struct_specifier|union_specifier
|
||||||
|
(type_identifier?)
|
||||||
|
{fieldListGrammar}
|
||||||
|
)
|
||||||
(type_identifier)
|
(type_identifier)
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
|
|
|
||||||
13
toast.nim
13
toast.nim
|
|
@ -4,7 +4,7 @@ import treesitter/runtime
|
||||||
import treesitter_c/c
|
import treesitter_c/c
|
||||||
import treesitter_cpp/cpp
|
import treesitter_cpp/cpp
|
||||||
|
|
||||||
import nimterop/[ast, globals, getters]
|
import nimterop/[ast, globals, getters, grammar]
|
||||||
|
|
||||||
proc printLisp(root: TSNode) =
|
proc printLisp(root: TSNode) =
|
||||||
var
|
var
|
||||||
|
|
@ -112,6 +112,7 @@ proc main(
|
||||||
pnim = false,
|
pnim = false,
|
||||||
pretty = true,
|
pretty = true,
|
||||||
preprocess = false,
|
preprocess = false,
|
||||||
|
pgrammar = false,
|
||||||
defines: seq[string] = @[],
|
defines: seq[string] = @[],
|
||||||
includeDirs: seq[string] = @[],
|
includeDirs: seq[string] = @[],
|
||||||
source: seq[string],
|
source: seq[string],
|
||||||
|
|
@ -126,7 +127,11 @@ proc main(
|
||||||
defines: defines,
|
defines: defines,
|
||||||
includeDirs: includeDirs,
|
includeDirs: includeDirs,
|
||||||
)
|
)
|
||||||
if source.len != 0:
|
|
||||||
|
if pgrammar:
|
||||||
|
parseGrammar()
|
||||||
|
printGrammar()
|
||||||
|
elif source.len != 0:
|
||||||
process(source[0])
|
process(source[0])
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
@ -138,11 +143,13 @@ when isMainModule:
|
||||||
"defines": "definitions to pass to preprocessor",
|
"defines": "definitions to pass to preprocessor",
|
||||||
"includeDirs": "include directory to pass to preprocessor",
|
"includeDirs": "include directory to pass to preprocessor",
|
||||||
"preprocess": "run preprocessor on header",
|
"preprocess": "run preprocessor on header",
|
||||||
|
"pgrammar": "print grammar",
|
||||||
"source" : "C/C++ source/header",
|
"source" : "C/C++ source/header",
|
||||||
}, short = {
|
}, short = {
|
||||||
"past": 'a',
|
"past": 'a',
|
||||||
"pnim": 'n',
|
"pnim": 'n',
|
||||||
"defines": 'D',
|
"defines": 'D',
|
||||||
"includeDirs": 'I',
|
"includeDirs": 'I',
|
||||||
"preprocess": 'p'
|
"preprocess": 'p',
|
||||||
|
"pgrammar": 'g'
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue