ast2 ignore parseString warnings, optional getNimExpression, handle override nil, param comments
This commit is contained in:
parent
e1c8ef2775
commit
4c513a50de
2 changed files with 28 additions and 14 deletions
|
|
@ -29,7 +29,7 @@ task bt, "build toast":
|
||||||
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")
|
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")
|
||||||
|
|
||||||
task btd, "build toast":
|
task btd, "build toast":
|
||||||
execCmd("nim c --hints:off nimterop/toast.nim")
|
execCmd("nim c -g --hints:off nimterop/toast.nim")
|
||||||
|
|
||||||
task docs, "Generate docs":
|
task docs, "Generate docs":
|
||||||
buildDocs(@["nimterop/all.nim"], "build/htmldocs")
|
buildDocs(@["nimterop/all.nim"], "build/htmldocs")
|
||||||
|
|
@ -56,6 +56,8 @@ task test, "Test":
|
||||||
execTest "tests/tmath.nim"
|
execTest "tests/tmath.nim"
|
||||||
if defined(OSX) or defined(Windows) or not existsEnv("TRAVIS"):
|
if defined(OSX) or defined(Windows) or not existsEnv("TRAVIS"):
|
||||||
execTest "tests/tsoloud.nim"
|
execTest "tests/tsoloud.nim"
|
||||||
|
execTest "tests/tsoloud.nim", "-d:FLAGS=\"-f:ast2\""
|
||||||
|
execTest "tests/tsoloud.nim", "-d:FLAGS=\"-f:ast2 -H\""
|
||||||
|
|
||||||
# getHeader tests
|
# getHeader tests
|
||||||
withDir("tests"):
|
withDir("tests"):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import macros, os, sequtils, sets, strformat, strutils, tables, times
|
||||||
|
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
import compiler/[ast, idents, lineinfos, modulegraphs, options, parser, renderer]
|
import compiler/[ast, idents, lineinfos, modulegraphs, msgs, options, parser, renderer]
|
||||||
|
|
||||||
import "."/treesitter/api
|
import "."/treesitter/api
|
||||||
|
|
||||||
|
|
@ -18,8 +18,9 @@ proc getPtrType*(str: string): string =
|
||||||
str
|
str
|
||||||
|
|
||||||
proc handleError*(conf: ConfigRef, info: TLineInfo, msg: TMsgKind, arg: string) =
|
proc handleError*(conf: ConfigRef, info: TLineInfo, msg: TMsgKind, arg: string) =
|
||||||
# Raise exception in parseString() instead of exiting
|
# Raise exception in parseString() instead of exiting for errors
|
||||||
raise newException(Exception, "")
|
if msg < warnMin:
|
||||||
|
raise newException(Exception, msgKindToString(msg))
|
||||||
|
|
||||||
proc parseString(nimState: NimState, str: string): PNode =
|
proc parseString(nimState: NimState, str: string): PNode =
|
||||||
# Parse a string into Nim AST - use custom error handler that raises
|
# Parse a string into Nim AST - use custom error handler that raises
|
||||||
|
|
@ -29,11 +30,13 @@ proc parseString(nimState: NimState, str: string): PNode =
|
||||||
str, nimState.identCache, nimState.config, errorHandler = handleError
|
str, nimState.identCache, nimState.config, errorHandler = handleError
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
discard
|
decho getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc getLit*(nimState: NimState, str: string): PNode =
|
proc getLit*(nimState: NimState, str: string, expression = false): PNode =
|
||||||
# Used to convert #define literals into const and expressions
|
# Used to convert #define literals into const and expressions
|
||||||
# in array sizes
|
# in array sizes
|
||||||
|
#
|
||||||
|
# `expression` is true when `str` should be converted into a Nim expression
|
||||||
let
|
let
|
||||||
str = str.replace(re"/[/*].*?(?:\*/)?$", "").strip()
|
str = str.replace(re"/[/*].*?(?:\*/)?$", "").strip()
|
||||||
|
|
||||||
|
|
@ -54,7 +57,11 @@ proc getLit*(nimState: NimState, str: string): PNode =
|
||||||
result = newStrNode(nkStrLit, str[1 .. ^2])
|
result = newStrNode(nkStrLit, str[1 .. ^2])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
result = nimState.parseString(nimState.getNimExpression(str))
|
let
|
||||||
|
str =
|
||||||
|
if expression: nimState.getNimExpression(str)
|
||||||
|
else: str
|
||||||
|
result = nimState.parseString(str)
|
||||||
|
|
||||||
if result.isNil:
|
if result.isNil:
|
||||||
result = newNode(nkNilLit)
|
result = newNode(nkNilLit)
|
||||||
|
|
@ -75,7 +82,10 @@ proc getOverrideOrSkip(nimState: NimState, node: TSNode, origname: string, kind:
|
||||||
if override.nBl:
|
if override.nBl:
|
||||||
if kind == nskProc:
|
if kind == nskProc:
|
||||||
skind = ""
|
skind = ""
|
||||||
result = nimState.parseString(skind & override.replace(origname, name))[0][0]
|
let
|
||||||
|
pnode = nimState.parseString(skind & override.replace(origname, name))
|
||||||
|
if not pnode.isNil:
|
||||||
|
result = pnode[0][0]
|
||||||
else:
|
else:
|
||||||
necho &"\n# $1'{origname}' skipped" % skind
|
necho &"\n# $1'{origname}' skipped" % skind
|
||||||
if nimState.gState.debug:
|
if nimState.gState.debug:
|
||||||
|
|
@ -596,11 +606,12 @@ proc newFormalParams(nimState: NimState, name: string, node: TSNode, rtyp: PNode
|
||||||
|
|
||||||
if not node.isNil:
|
if not node.isNil:
|
||||||
for i in 0 ..< node.len:
|
for i in 0 ..< node.len:
|
||||||
# Add nkIdentDefs for each param
|
if node[i].getName() == "parameter_declaration":
|
||||||
let
|
# Add nkIdentDefs for each param
|
||||||
param = nimState.newIdentDefs(name, node[i], i, exported = false)
|
let
|
||||||
if not param.isNil:
|
param = nimState.newIdentDefs(name, node[i], i, exported = false)
|
||||||
result.add param
|
if not param.isNil:
|
||||||
|
result.add param
|
||||||
|
|
||||||
proc newProcTy(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNode =
|
proc newProcTy(nimState: NimState, name: string, node: TSNode, rtyp: PNode): PNode =
|
||||||
# Create nkProcTy tree for specified proc type
|
# Create nkProcTy tree for specified proc type
|
||||||
|
|
@ -883,7 +894,8 @@ proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
|
||||||
|
|
||||||
for i in 0 ..< acount:
|
for i in 0 ..< acount:
|
||||||
let
|
let
|
||||||
size = nimState.getLit(nimState.getNodeVal(cnode[1]))
|
# Size of array could be a Nim expression
|
||||||
|
size = nimState.getLit(nimState.getNodeVal(cnode[1]), expression = true)
|
||||||
if size.kind != nkNilLit:
|
if size.kind != nkNilLit:
|
||||||
result = nimState.newArrayTree(cnode, result, size)
|
result = nimState.newArrayTree(cnode, result, size)
|
||||||
cnode = cnode[0]
|
cnode = cnode[0]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue