summary refs log tree commit diff stats
path: root/tests/patterns
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-12-09 03:02:52 +0100
committerAraq <rumpf_a@web.de>2012-12-09 03:02:52 +0100
commit92f8f2e7766d6c5475f643a17df88aa680a4e5dc (patch)
tree197e8e6af6f3be022389c38a864ac2607b7f8f07 /tests/patterns
parent40b611cc2f7d5cf4972dfb92fc63f0bb350adf89 (diff)
downloadNim-92f8f2e7766d6c5475f643a17df88aa680a4e5dc.tar.gz
documented AST overloading and some TR optimizations
Diffstat (limited to 'tests/patterns')
-rw-r--r--tests/patterns/thoist.nim13
-rw-r--r--tests/patterns/tpartial.nim11
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/patterns/thoist.nim b/tests/patterns/thoist.nim
new file mode 100644
index 000000000..7d14c0abf
--- /dev/null
+++ b/tests/patterns/thoist.nim
@@ -0,0 +1,13 @@
+discard """
+  output: '''true
+true'''
+"""
+
+import pegs
+
+template optPeg{peg(pattern)}(pattern: string{lit}): TPeg =
+  var gl {.global, gensym.} = peg(pattern)
+  gl
+
+echo match("(a b c)", peg"'(' @ ')'")
+echo match("W_HI_Le", peg"\y 'while'")
diff --git a/tests/patterns/tpartial.nim b/tests/patterns/tpartial.nim
new file mode 100644
index 000000000..1a5b1a953
--- /dev/null
+++ b/tests/patterns/tpartial.nim
@@ -0,0 +1,11 @@
+discard """
+  output: '''-1'''
+"""
+
+proc p(x, y: int; cond: bool): int =
+  result = if cond: x + y else: x - y
+
+template optP{p(x, y, true)}(x, y: expr): expr = x - y
+template optP{p(x, y, false)}(x, y: expr): expr = x + y
+
+echo p(2, 4, true)