diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-12 00:46:44 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-12 00:46:44 -0600 |
| commit | 75dc6dc56e787daf55363c2ef4f8195c0c5fae9a (patch) | |
| tree | 03945b57eb7ee8ef40c79178b6690468dc0d0496 | |
| parent | 8c644e814ca676ce2e126bc85497eba7877cc94f (diff) | |
| download | nimterop-75dc6dc56e787daf55363c2ef4f8195c0c5fae9a.tar.gz nimterop-75dc6dc56e787daf55363c2ef4f8195c0c5fae9a.zip | |
Identifiers in enums
| -rw-r--r-- | nimterop/ast.nim | 9 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 17 |
2 files changed, 16 insertions, 10 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index 73c602c..8f880da 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -40,13 +40,12 @@ proc saveNodeData(node: TSNode): bool = gStateRT.data.add((name, val)) - if node.isPName("pointer_declarator") and node.isPPName("function_declarator"): + if node.tsNodeType() == "field_identifier" and node.isPName("pointer_declarator") and + node.isPPName("function_declarator"): gStateRT.data.add(("function_declarator", "")) - elif name in ["abstract_pointer_declarator"]: - gStateRT.data.add(("pointer_declarator", "")) - elif name in ["field_declaration", "function_declarator"]: - gStateRT.data.add((name, "")) + elif name in ["abstract_pointer_declarator", "enumerator", "field_declaration", "function_declarator"]: + gStateRT.data.add((name.replace("abstract_", ""), "")) return true diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index 7b12477..693b365 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -51,7 +51,10 @@ proc initGrammar() = funcGrammar = &""" (function_declarator* - (identifier|type_identifier) + (identifier|type_identifier!) + (pointer_declarator + (type_identifier) + ) {paramListGrammar} ) """ @@ -123,7 +126,7 @@ proc initGrammar() = if typ != "object": gStateRT.typeStr &= &" {name}* = proc({pout}): {tptr}{typ} {{.nimcall.}}\n" else: - gStateRT.typeStr &= &" {name}*: proc({pout}) {{.nimcall.}}\n" + gStateRT.typeStr &= &" {name}* = proc({pout}) {{.nimcall.}}\n" else: gStateRT.types.add(name) if name == typ or typ == "object": @@ -169,7 +172,7 @@ proc initGrammar() = continue if gStateRT.data[i].name notin ["field_identifier", "pointer_declarator"]: - ftyp = gStateRT.data[i].val.getIdentifier() + ftyp = gStateRT.data[i].val.getType() i += 1 if gStateRT.data[i].name == "pointer_declarator": @@ -289,9 +292,13 @@ proc initGrammar() = let fname = gStateRT.data[i].val.getIdentifier() + if gStateRT.data[i].name == "enumerator": + i += 1 + continue + if fname notin gStateRT.consts: if i+1 < gStateRT.data.len-fend and - gStateRT.data[i+1].name in ["shift_expression", "math_expression", "number_literal"]: + gStateRT.data[i+1].name in ["identifier", "shift_expression", "math_expression", "number_literal"]: if " " in gStateRT.data[i+1].val: gStateRT.data[i+1].val = "(" & gStateRT.data[i+1].val.replace(" ", "") & ")" gStateRT.data[i+1].val = gStateRT.data[i+1].val.multiReplace([ @@ -315,7 +322,7 @@ proc initGrammar() = (type_identifier?) (enumerator_list (enumerator+ - (identifier) + (identifier+) (number_literal?) (shift_expression|math_expression? (number_literal+) |
