summary refs log tree commit diff stats
path: root/tests/stdlib/tpegs.nim
diff options
context:
space:
mode:
authorgemath <33119724+gemath@users.noreply.github.com>2021-06-28 12:33:20 +0200
committerGitHub <noreply@github.com>2021-06-28 12:33:20 +0200
commite720bbdd76303e2cc0a3a169e870859470a1da84 (patch)
treeb8cad0c1c8b90ebafb0e74c134ec303d026078b5 /tests/stdlib/tpegs.nim
parent908b2cc2e44bededdcb943778f44b908a4f3c1df (diff)
downloadNim-e720bbdd76303e2cc0a3a169e870859470a1da84.tar.gz
Peg captures get stack-like behavior (#18369)
* Implements reverse capture indexing.
* Now works for modified backrefs too.
* Changed reverse indexing syntax prefix for back-references to '$^'.
Diffstat (limited to 'tests/stdlib/tpegs.nim')
-rw-r--r--tests/stdlib/tpegs.nim28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim
index f2c93c2e5..1261d55b8 100644
--- a/tests/stdlib/tpegs.nim
+++ b/tests/stdlib/tpegs.nim
@@ -293,6 +293,34 @@ block:
 
     doAssert "test1".match(peg"""{@}$""")
     doAssert "test2".match(peg"""{(!$ .)*} $""")
+
+    doAssert "abbb".match(peg"{a} {b} $2 $^1")
+    doAssert "abBA".match(peg"{a} {b} i$2 i$^2")
+
+    doAssert "abba".match(peg"{a} {b} $^1 {} $^1")
+
+    block:
+      let grammar = peg"""
+program <- {''} stmt* $
+stmt <- call / block
+call <- 'call()' EOL
+EOL <- \n / $
+block <- 'block:' \n indBody
+indBody <- {$^1 ' '+} stmt ($^1 stmt)* {}
+"""
+      let program = """
+call()
+block:
+  block:
+    call()
+    call()
+  call()
+call()
+"""
+      var c: Captures
+      doAssert program.len == program.rawMatch(grammar, 0, c)
+      doAssert c.ml == 1
+
   pegsTest()
   static:
     pegsTest()