mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
documented AST overloading and some TR optimizations
This commit is contained in:
13
tests/patterns/thoist.nim
Normal file
13
tests/patterns/thoist.nim
Normal file
@@ -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'")
|
||||
11
tests/patterns/tpartial.nim
Normal file
11
tests/patterns/tpartial.nim
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user