Add missing utils module
This commit is contained in:
parent
6ff4e1d459
commit
4ffbc33ab3
1 changed files with 18 additions and 0 deletions
18
nimterop/utils.nim
Normal file
18
nimterop/utils.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import compiler/[ast, lineinfos, msgs, options, parser, renderer]
|
||||||
|
|
||||||
|
import "."/[globals, getters]
|
||||||
|
|
||||||
|
proc handleError*(conf: ConfigRef, info: TLineInfo, msg: TMsgKind, arg: string) =
|
||||||
|
# Raise exception in parseString() instead of exiting for errors
|
||||||
|
if msg < warnMin:
|
||||||
|
raise newException(Exception, msgKindToString(msg))
|
||||||
|
|
||||||
|
proc parseString*(nimState: NimState, str: string): PNode =
|
||||||
|
# Parse a string into Nim AST - use custom error handler that raises
|
||||||
|
# an exception rather than exiting on failure
|
||||||
|
try:
|
||||||
|
result = parseString(
|
||||||
|
str, nimState.identCache, nimState.config, errorHandler = handleError
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
decho getCurrentExceptionMsg()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue