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 = @[
|
const gAtoms = @[
|
||||||
"field_identifier",
|
"field_identifier",
|
||||||
"identifier",
|
"identifier",
|
||||||
|
"shift_expression",
|
||||||
"math_expression",
|
"math_expression",
|
||||||
"number_literal",
|
"number_literal",
|
||||||
"preproc_arg",
|
"preproc_arg",
|
||||||
|
|
@ -26,7 +27,7 @@ proc saveNodeData(node: TSNode): bool =
|
||||||
if name == "primitive_type" and node.tsNodeParent.tsNodeType() == "sized_type_specifier":
|
if name == "primitive_type" and node.tsNodeParent.tsNodeType() == "sized_type_specifier":
|
||||||
return true
|
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
|
return true
|
||||||
|
|
||||||
if name in ["math_expression", "primitive_type", "sized_type_specifier"]:
|
if name in ["math_expression", "primitive_type", "sized_type_specifier"]:
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ proc sanitizePath*(path: string): string =
|
||||||
path.multiReplace([("\\\\", $DirSep), ("\\", $DirSep), ("//", $DirSep)])
|
path.multiReplace([("\\\\", $DirSep), ("\\", $DirSep), ("//", $DirSep)])
|
||||||
|
|
||||||
proc getIdentifier*(str: string): string =
|
proc getIdentifier*(str: string): string =
|
||||||
result = str.strip(chars={'_'})
|
result = str.strip(chars={'_'}).replace(re"_+", "_")
|
||||||
|
|
||||||
if result in gReserved:
|
if result in gReserved:
|
||||||
result = &"`{result}`"
|
result = &"`{result}`"
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,14 @@ proc initGrammar() =
|
||||||
fname = gStateRT.data[i].val.getIdentifier()
|
fname = gStateRT.data[i].val.getIdentifier()
|
||||||
|
|
||||||
if fname notin gStateRT.consts:
|
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"
|
gStateRT.constStr &= &" {fname}* = {gStateRT.data[i+1].val}.{nname}\n"
|
||||||
try:
|
try:
|
||||||
count = gStateRT.data[i+1].val.parseInt() + 1
|
count = gStateRT.data[i+1].val.parseInt() + 1
|
||||||
|
|
@ -251,8 +258,8 @@ proc initGrammar() =
|
||||||
(enumerator+
|
(enumerator+
|
||||||
(identifier)
|
(identifier)
|
||||||
(number_literal?)
|
(number_literal?)
|
||||||
(math_expression?
|
(shift_expression|math_expression?
|
||||||
(number_literal)
|
(number_literal+)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue