Add missing utils module

This commit is contained in:
Joey Yakimowich-Payne 2020-04-19 19:56:32 -06:00
commit 4ffbc33ab3

18
nimterop/utils.nim Normal file
View 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()