summary refs log tree commit diff stats
path: root/lib/pure/pegs.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-03-23 01:09:52 +0100
committerAraq <rumpf_a@web.de>2011-03-23 01:09:52 +0100
commit5b789f2da8e57ea2adf0c088f5e41fd7a71fe89b (patch)
tree81f2f23d48d56ef7b106d24982231d99809a6def /lib/pure/pegs.nim
parent8d734244b14e09c97267432468ac20fcf8ff82eb (diff)
downloadNim-5b789f2da8e57ea2adf0c088f5e41fd7a71fe89b.tar.gz
bugfixes; field discriminant checks; linearScanEnd, unroll, shallow pragmas
Diffstat (limited to 'lib/pure/pegs.nim')
-rwxr-xr-xlib/pure/pegs.nim15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim
index 334f5dcd3..6ad52c9a1 100755
--- a/lib/pure/pegs.nim
+++ b/lib/pure/pegs.nim
@@ -75,7 +75,7 @@ type
     col: int                      ## column the symbol has been declared/used in
     flags: set[TNonTerminalFlag]  ## the nonterminal's flags
     rule: TNode                   ## the rule that the symbol refers to
-  TNode {.final.} = object
+  TNode {.final, shallow.} = object
     case kind: TPegKind
     of pkEmpty..pkWhitespace: nil
     of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: term: string
@@ -128,10 +128,12 @@ proc add(d: var TPeg, s: TPeg) {.inline.} = add(d.sons, s)
 proc addChoice(dest: var TPeg, elem: TPeg) =
   var L = dest.len-1
   if L >= 0 and dest.sons[L].kind == pkCharChoice: 
+    # caution! Do not introduce false aliasing here!
     case elem.kind
     of pkCharChoice:
-      dest.sons[L].charChoice^ = dest.sons[L].charChoice^ + elem.charChoice^
-    of pkChar: incl(dest.sons[L].charChoice^, elem.ch)
+      dest.sons[L] = charSet(dest.sons[L].charChoice^ + elem.charChoice^)
+    of pkChar: 
+      dest.sons[L] = charSet(dest.sons[L].charChoice^ + {elem.ch})
     else: add(dest, elem)
   else: add(dest, elem)
 
@@ -155,9 +157,12 @@ proc `/`*(a: openArray[TPeg]): TPeg {.
 proc addSequence(dest: var TPeg, elem: TPeg) =
   var L = dest.len-1
   if L >= 0 and dest.sons[L].kind == pkTerminal: 
+    # caution! Do not introduce false aliasing here!
     case elem.kind
-    of pkTerminal: add(dest.sons[L].term, elem.term)
-    of pkChar: add(dest.sons[L].term, elem.ch)
+    of pkTerminal: 
+      dest.sons[L] = term(dest.sons[L].term & elem.term)
+    of pkChar: 
+      dest.sons[L] = term(dest.sons[L].term & elem.ch)
     else: add(dest, elem)
   else: add(dest, elem)