1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
(# This is just a comment #)
(# Nested comments (# like this #) work fine #)
run file "core.nom"
say "foo"
say (4)
(# "rule" is just a function that takes a function call spec and a block of code to run,
and stores the function definition #)
rule "fart": say "poot"
fart
(# multi-line strings: #)
say ".."
| Once upon a time
|there was a very
|long string
|
| with
| rather
| silly
| indentation
| and "quotes"
|.." (even fakeouts like that) "
|(done)
|
rule "doublefart": (# this farts twice #)
say "poot"
say "poot"
doublefart
rule "subex work": return "subexpressions work"
say (subex work)
say (..)
subex work
say ["lists", "work"]
say []
say [..]
1, 2
3
rule "say both %one and %two":
say %one
say %two
say both [..]
1,2
..and [..]
3,4
say both..
"hello"
and "world"
rule "three": return 3
say both ..
"a list:"
and [..]
1,2,(three),(4)
if 1: yes
..else: no
if 1: yes ..else: no
say (do: return 5)
rule "do %one also %two":
do %one
do %two
do: say "one liner"
..also: say "another one liner"
say (do: return "wow")
say (1 + (-(2 * 3)))
say (2 + (..)
3 * 4
..)
if %x:
say "one"
..else: if %y:
say "two"
..else:
say "three"
printf [..]
".."
|this is a longstring
|
.., "with", ".."
| multiple lines
rule "%n bottles":
lua block [..]
".."
|do
| print("running raw lua code...")
| local n =
.., %n, ".."
|
| for i=n,1,-1 do
| print(tostring(i).." bottles of beer on the wall. Take one down, pass it around,")
| end
| print("no more bottles of beer on the wall.")
|end
nil
9 bottles
rule "dumsum %nums":
let "sum" = 0
for "n" in %nums:
let "sum" = (%sum + %n)
return %sum
say (dumsum [1,2,3])
|