Shift/math expressions in enum
This commit is contained in:
parent
88005fa984
commit
bc28293812
3 changed files with 13 additions and 5 deletions
|
|
@ -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"]:
|
||||
|
|
|
|||
|
|
@ -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}`"
|
||||
|
|
|
|||
|
|
@ -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+)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue