-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.rb
52 lines (35 loc) · 798 Bytes
/
example.rb
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
require 'rasta'
include Rasta
def list1
number = t(/[0-9]+/)
word = t(/[A-Za-z]+/)
atom = number | word
l = t("[")
r = t("]")
sep = t(",")
list = l >> atom >> (sep >> atom).star >> r
end
def list2
number = t(/[0-9]+/)
word = t(/[A-Za-z]+/)
atom = number | word
l = t("[")
r = t("]")
sep = t(",")
list = l >> ref{list} >> (sep >> ref{list}).star >> r
end
def listx
list = nil
number = t(/[0-9]+/).mk_i
word = t(/[A-Za-z]+/).mk_s
atom = number | word
l = t("[").drop
r = t("]").drop
sep = t(",").drop
lref = ref{list}
list = l >> lref << (sep >> lref).star.flat >> r | atom
atom.name = "atom"
number.name = "number"
list.name = "list"
list
end