Applied Araq's suggestions for c2nim
This commit is contained in:
parent
5395347582
commit
aec9195c95
2 changed files with 11 additions and 9 deletions
|
|
@ -49,8 +49,8 @@ proc parse(infile: string, options: PParserOptions): PNode =
|
|||
|
||||
proc main(infile, outfile: string, options: PParserOptions, spliceHeader: bool) =
|
||||
var start = getTime()
|
||||
if spliceHeader and infile[infile.len-2 .. infile.len] == ".c" and existsFile(infile[0 .. infile.len-2] & "h"):
|
||||
var header_module = parse(infile[0 .. infile.len-2] & "h", options)
|
||||
if spliceHeader and infile.splitFile.ext == ".c" and existsFile(infile.changeFileExt(".h")):
|
||||
var header_module = parse(infile.changeFileExt(".h"), options)
|
||||
var source_module = parse(infile, options)
|
||||
for n in source_module:
|
||||
addson(header_module, n)
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ type
|
|||
|
||||
TReplaceTuple* = array[0..1, string]
|
||||
|
||||
ERetryParsing = object of ESynch
|
||||
|
||||
proc newParserOptions*(): PParserOptions =
|
||||
new(result)
|
||||
result.prefixes = @[]
|
||||
|
|
@ -1181,7 +1183,7 @@ proc startExpression(p : var TParser, tok : TToken) : PNode =
|
|||
try:
|
||||
addSon(result, expression(p, 139))
|
||||
closeContext(p)
|
||||
except:
|
||||
except ERetryParsing:
|
||||
backtrackContext(p)
|
||||
eat(p, pxParLe)
|
||||
addSon(result, typeName(p))
|
||||
|
|
@ -1226,12 +1228,12 @@ proc startExpression(p : var TParser, tok : TToken) : PNode =
|
|||
result = newNodeP(nkPar, p)
|
||||
addSon(result, expression(p, 0))
|
||||
if p.tok.xkind != pxParRi:
|
||||
raise
|
||||
raise newException(ERetryParsing, "expected a ')'")
|
||||
getTok(p, result)
|
||||
if p.tok.xkind in {pxSymbol, pxIntLit, pxFloatLit, pxStrLit, pxCharLit}:
|
||||
raise
|
||||
raise newException(ERetryParsing, "expected a non literal token")
|
||||
closeContext(p)
|
||||
except:
|
||||
except ERetryParsing:
|
||||
backtrackContext(p)
|
||||
result = newNodeP(nkCast, p)
|
||||
addSon(result, typeName(p))
|
||||
|
|
@ -1269,7 +1271,7 @@ proc startExpression(p : var TParser, tok : TToken) : PNode =
|
|||
addSon(result, expression(p, 139))
|
||||
else:
|
||||
# probably from a failed sub expression attempt, try a type cast
|
||||
raise newException(E_Base, "not " & $tok)
|
||||
raise newException(ERetryParsing, "did not expect " & $tok)
|
||||
|
||||
proc leftBindingPower(p : var TParser, tok : ref TToken) : int =
|
||||
#echo "lbp ", $tok[]
|
||||
|
|
@ -2134,6 +2136,6 @@ proc parseUnit(p: var TParser): PNode =
|
|||
while p.tok.xkind != pxEof:
|
||||
var s = statement(p)
|
||||
if s.kind != nkEmpty: embedStmts(result, s)
|
||||
except:
|
||||
parMessage(p, errGenerated, "Uncaught exception raised during parsing")
|
||||
except ERetryParsing:
|
||||
parMessage(p, errGenerated, "Uncaught parsing exception raised")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue