diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-11 13:00:03 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-11 13:00:03 -0600 |
| commit | bc282938125fbb60ce04338d9d276cca18dd2aaa (patch) | |
| tree | dbc90e8235b55589d5ff36ea61fb0a96329cb769 | |
| parent | 88005fa9841ca74c25cc54699ee7b0968dd495ef (diff) | |
| download | nimterop-bc282938125fbb60ce04338d9d276cca18dd2aaa.tar.gz nimterop-bc282938125fbb60ce04338d9d276cca18dd2aaa.zip | |
Shift/math expressions in enum
| -rw-r--r-- | nimterop/ast.nim | 3 | ||||
| -rw-r--r-- | nimterop/getters.nim | 2 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 13 |
3 files changed, 13 insertions, 5 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index 5f6ad8d..df3f626 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -9,6 +9,7 @@ import "."/[getters, globals, grammar] const gAtoms = @[ "field_identifier", "identifier", + "shift_expression", "math_expression", "number_literal", "preproc_arg", @@ -26,7 +27,7 @@ proc saveNodeData(node: TSNode): bool = if name == "primitive_type" and node.tsNodeParent.tsNodeType() == "sized_type_specifier": return true - if name == "number_literal" and node.tsNodeParent.tsNodeType() == "math_expression": + if name == "number_literal" and $node.tsNodeParent.tsNodeType() in ["shift_expression", "math_expression"]: return true if name in ["math_expression", "primitive_type", "sized_type_specifier"]: diff --git a/nimterop/getters.nim b/nimterop/getters.nim index d0fa49c..77243f6 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -51,7 +51,7 @@ proc sanitizePath*(path: string): string = path.multiReplace([("\\\\", $DirSep), ("\\", $DirSep), ("//", $DirSep)]) proc getIdentifier*(str: string): string = - result = str.strip(chars={'_'}) + result = str.strip(chars={'_'}).replace(re"_+", "_") if result in gReserved: result = &"`{result}`" diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index f5c0237..13fab13 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -231,7 +231,14 @@ proc initGrammar() = fname = gStateRT.data[i].val.getIdentifier() if fname notin gStateRT.consts: - if i+1 < gStateRT.data.len-fend and gStateRT.data[i+1].name in ["math_expression", "number_literal"]: + if i+1 < gStateRT.data.len-fend and + gStateRT.data[i+1].name in ["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([ + ("<<", " shl "), (">>", " shr ") + ]) + gStateRT.constStr &= &" {fname}* = {gStateRT.data[i+1].val}.{nname}\n" try: count = gStateRT.data[i+1].val.parseInt() + 1 @@ -251,8 +258,8 @@ proc initGrammar() = (enumerator+ (identifier) (number_literal?) - (math_expression? - (number_literal) + (shift_expression|math_expression? + (number_literal+) ) ) ) |
