summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorVincent Burns <discoloda@gmail.com>2014-01-14 16:35:00 -0500
committerVincent Burns <discoloda@gmail.com>2014-01-14 16:35:00 -0500
commitaec9195c95b62a5f496c878cc3e40c03b0c7104f (patch)
treee8bf7f08b85b10cdcdfb9b8328d16d574a69f161 /compiler
parent53953475825e1ab743a8d02ca0fca6b4eeee3ff4 (diff)
downloadNim-aec9195c95b62a5f496c878cc3e40c03b0c7104f.tar.gz
Applied Araq's suggestions for c2nim
Diffstat (limited to 'compiler')
-rw-r--r--compiler/c2nim/c2nim.nim4
-rw-r--r--compiler/c2nim/cparse.nim16
2 files changed, 11 insertions, 9 deletions
diff --git a/compiler/c2nim/c2nim.nim b/compiler/c2nim/c2nim.nim
index c4fc8ad67..9b12b9e47 100644
--- a/compiler/c2nim/c2nim.nim
+++ b/compiler/c2nim/c2nim.nim
@@ -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)
diff --git a/compiler/c2nim/cparse.nim b/compiler/c2nim/cparse.nim
index 8a8eeeb05..ffab05788 100644
--- a/compiler/c2nim/cparse.nim
+++ b/compiler/c2nim/cparse.nim
@@ -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")