Mercurial > repos > tabletprog
annotate modules/parser.tp @ 241:c50f77de41d1
Small fix to call to method implemented on current object check
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 05 Jan 2014 20:54:22 -0800 |
parents | 6aab8a5a2be9 |
children | 0e7982adc76b |
rev | line source |
---|---|
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
1 { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
2 _applyMatch <- :fun tomatch { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
3 fun: tomatch |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
4 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
5 _matchString <- :str tomatch { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
6 if: (tomatch isString?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
7 if: (tomatch length) < (str length) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
8 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
9 matched? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
10 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
11 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
12 if: (tomatch length) > (str length) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
13 tomatch <- tomatch from: 0 withLength: (str length) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
14 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
15 if: str = tomatch { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
16 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
17 matched? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
18 matchlen <- { str length } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
19 basicYield? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
20 yield <- { str } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
21 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
22 } else: { |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
23 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
24 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
25 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
26 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
27 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
28 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
29 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
30 matched? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
31 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
32 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
33 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
34 _makeMatchCall <- :matchexpr { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
35 if: (matchexpr nodeType) = "lambda" { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
36 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
37 valid? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
38 matchcall <- quote: (_applyMatch: matchexpr tomatch) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
39 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
40 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
41 if: (matchexpr nodeType) = "symbol" { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
42 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
43 valid? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
44 matchcall <- quote: (matchexpr: tomatch) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
45 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
46 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
47 if: (matchexpr nodeType) = "strlit" { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
48 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
49 valid? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
50 matchcall <- quote: (_matchString: matchexpr tomatch) |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
51 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
52 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
53 if: (matchexpr nodeType) = "op" { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
54 if: (matchexpr opName) = "." { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
55 left <- (_makeMatchCall: (matchexpr left)) matchcall |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
56 right <- (_makeMatchCall: (matchexpr right)) matchcall |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
57 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
58 valid? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
59 matchcall <- quote: (_applyMatch: :tomatch { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
60 lm <- left |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
61 if: (lm matched?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
62 orig <- tomatch |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
63 tomatch <- tomatch from: (lm matchlen) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
64 rm <- right |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
65 if: (rm matched?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
66 total <- (rm matchlen) + (lm matchlen) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
67 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
68 matched? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
69 matchlen <- { total } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
70 basicYield? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
71 yield <- { orig from: 0 withLength: total } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
72 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
73 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
74 rm |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
75 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
76 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
77 lm |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
78 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
79 } tomatch) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
80 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
81 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
82 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
83 valid? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
84 message <- "Unsupported operator " . (matchexpr opName) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
85 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
86 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
87 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
88 #{ |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
89 valid? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
90 message <- "Unsupported AST node type " . (matchexpr nodeType) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
91 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
92 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
93 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
94 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
95 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
96 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
97 _nPlus <- :matchexpr min { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
98 funexpr <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
99 valid <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
100 mc <- _makeMatchCall: matchexpr |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
101 if: (mc valid?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
102 mcall <- mc matchcall |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
103 quote: :tomatch { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
104 cur <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
105 count <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
106 n <- tomatch byte_length |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
107 orig <- tomatch |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
108 _match <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
109 allBasic? <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
110 yieldvals <- [] |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
111 while: { _match && cur < n } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
112 res <- mcall |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
113 _match <- res matched? |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
114 if: _match { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
115 count <- count + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
116 //TODO: Use some kind of lightweight substring wrapper here |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
117 tomatch <- tomatch from: (res matchlen) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
118 if: allBasic? { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
119 ifnot: (res basicYield?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
120 allBasic? <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
121 if: cur > 0 { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
122 yieldvals <- (orig from: 0 withLength: cur) | yieldvals |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
123 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
124 yieldvals <- (res yield) | yieldvals |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
125 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
126 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
127 yieldvals <- (res yield) | yieldvals |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
128 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
129 allBasic? <- allBasic? && (res basicYield?) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
130 cur <- cur + (res matchlen) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
131 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
132 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
133 if: count >= min { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
134 if: allBasic? { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
135 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
136 matched? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
137 matchlen <- { cur } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
138 basicYield? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
139 yield <- { orig from: 0 withLength: cur } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
140 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
141 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
142 yieldvals <- yieldvals reverse |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
143 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
144 matched? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
145 matchlen <- { cur } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
146 basicYield? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
147 yield <- { yieldvals } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
148 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
149 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
150 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
151 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
152 matched? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
153 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
154 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
155 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
156 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
157 print: "#error Invalid nPlus macro call: " . (mc message) . "\n" |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
158 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
159 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
160 _expandClass <- :chars { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
161 if: (chars length) > 0 { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
162 pos <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
163 inverted <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
164 if: (chars byte: 0) = ("^" byte: 0) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
165 pos <- 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
166 inverted <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
167 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
168 state_begin <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
169 state_normal <- 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
170 state_rangeend <- 2 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
171 state <- state_begin |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
172 out <- "" |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
173 while: { pos < (chars byte_length)} do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
174 if: state = state_begin { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
175 out <- out . (chars from: pos withLength: 1) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
176 state <- state_normal |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
177 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
178 if: state = state_normal { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
179 if: (chars byte: pos) = ("-" byte: 0) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
180 state <- state_rangeend |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
181 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
182 out <- out . (chars from: pos withLength: 1) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
183 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
184 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
185 rangestart <- out byte: ((out byte_length) - 1) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
186 rangeend <- chars byte: pos |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
187 if: rangeend < rangestart { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
188 tmp <- rangeend |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
189 rangeend <- rangestart |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
190 rangestart <- tmp |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
191 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
192 out <- out from: 0 withLength: ((out length) - 1) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
193 while: { rangestart <= rangeend } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
194 out <- out . (rangestart asStringChar) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
195 rangestart <- rangestart + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
196 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
197 state <- state_begin |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
198 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
199 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
200 pos <- pos + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
201 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
202 if: inverted { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
203 old <- out |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
204 out <- "" |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
205 //skip control characters for now |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
206 cur <- 32 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
207 while: { cur < 256 } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
208 notfound <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
209 idx <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
210 len <- (old length) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
211 while: { notfound && idx < len } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
212 if: cur = (old byte: idx) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
213 notfound <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
214 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
215 idx <- idx + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
216 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
217 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
218 if: notfound { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
219 out <- out . (cur asStringChar) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
220 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
221 cur <- cur + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
222 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
223 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
224 out |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
225 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
226 "" |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
227 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
228 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
229 _charClass <- :chars { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
230 chars <- _expandClass: chars |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
231 charmap <- "" |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
232 char <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
233 while: { char < 256 } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
234 mchar <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
235 found <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
236 while: { mchar < (chars byte_length)} do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
237 if: (chars byte: mchar) = char { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
238 found <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
239 mchar <- chars byte_length |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
240 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
241 mchar <- mchar + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
242 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
243 charmap <- charmap . (if: found { "t" } else: { "f" }) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
244 char <- char + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
245 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
246 t <- "t" byte: 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
247 quote: :tomatch { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
248 if: (tomatch isString?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
249 if: (charmap byte: (tomatch byte: 0)) = t { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
250 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
251 matched? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
252 matchlen <- { 1 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
253 basicYield? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
254 yield <- { tomatch from: 0 withLength: 1 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
255 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
256 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
257 #{ |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
258 matched? <- { false } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
259 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
260 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
261 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
262 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
263 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
264 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
265 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
266 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
267 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
268 #{ |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
269 ifmatch:else <- :matchres :elseblock { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
270 if: (matchres matched?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
271 matchres |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
272 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
273 elseblock: |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
274 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
275 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 charClass <- macro: :rawchars { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 eval: rawchars :chars { |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
278 _charClass: chars |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 } else: { |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
280 print: "#error Argument to charClass macro must be a compile-time constant\n" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
283 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
284 zeroPlus <- macro: :matchexpr { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
285 _nPlus: matchexpr 0 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
286 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
287 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
288 onePlus <- macro: :matchexpr { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
289 _nPlus: matchexpr 1 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
290 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
291 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
292 matchOne <- macro: :options { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
293 options <- (options value) map: :option { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
294 _makeMatchCall: option |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
295 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
296 body <- options foldr: (quote: #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
297 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
298 }) with: :acc el { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
299 if: (el valid?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
300 mcall <- el matchcall |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
301 quote: (ifmatch: mcall else: { acc }) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
302 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
303 print: "#error Invalid matchOne macro call: " . (el message) . "\n" |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
304 acc |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
305 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
306 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
307 quote: :tomatch { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
308 body |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
309 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
310 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
311 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
312 match <- macro: :matchexpr { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
313 mc <- _makeMatchCall: matchexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
314 if: (mc valid?) { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
315 mcall <- mc matchcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
316 quote: :tomatch { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
317 mcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
318 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
319 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
320 print: "#error Invalid macth macro call: " . (mc message) . "\n" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
321 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
322 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
323 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
324 match:yield <- macro: :matchexpr :ylambda { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
325 mc <- _makeMatchCall: matchexpr |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
326 if: (mc valid?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
327 mcall <- mc matchcall |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
328 quote: :tomatch { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
329 res <- mcall |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
330 if: (res matched?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
331 #{ |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
332 matched? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
333 matchlen <- { res matchlen } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
334 basicYield? <- { false } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
335 yield <- ylambda |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
336 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
337 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
338 res |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
339 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
340 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
341 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
342 print: "#error Invalid macth:yield macro call: " . (mc message) . "\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
343 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
344 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
345 |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
346 match:where:yield <- macro: :matchexpr :whereclause :ylambda { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
347 syms <- [] |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
348 withwhere <- (whereclause expressions) fold: (quote: :tomatch {}) with: :acc el { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
349 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
350 if: (el nodeType) = "assignment" { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
351 valassign <- quote: (val <- false) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
352 valsym <- (valassign) symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
353 valsym <- valsym name!: (valsym name) . ((el symbol) name) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
354 valassign <- valassign symbol!: valsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
355 acc addExpression: valassign |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
356 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
357 matchassign <- quote: (hasmatch <- false) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
358 matchsym <- (matchassign) symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
359 matchsym <- matchsym name!: (matchsym name) . ((el symbol) name) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
360 matchassign <- matchassign symbol!: matchsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
361 acc addExpression: matchassign |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
362 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
363 mc <- _makeMatchCall: (el expression) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
364 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
365 if: (mc valid?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
366 mcall <- mc matchcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
367 matchfun <- quote: :tomatch { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
368 if: matchsym { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
369 if: valsym = tomatch { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
370 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
371 matched? <- { true } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
372 matchlen <- { valsym length } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
373 basicYield? <- { true } //TODO: Check if this is correct |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
374 yield <- { valsym } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
375 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
376 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
377 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
378 matched? <- { false } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
379 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
380 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
381 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
382 mr <- mcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
383 if: (mr matched?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
384 matchsym <- true |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
385 valsym <- (mr yield) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
386 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
387 mr |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
388 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
389 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
390 acc <- acc addExpression: (el expression!: matchfun) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
391 syms <- list node: #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
392 orig <- el symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
393 matchval <- valsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
394 } withTail: syms |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
395 acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
396 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
397 print: "#error " . ((el symbol) name) . " does not have a valid match expression: " . (mc message) . "\n" |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
398 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
399 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
400 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
401 print: "#error Nodes of type " . (el nodeType) . " are not allowed in match where clauses\n" |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
402 acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
403 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
404 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
405 mcMain <- _makeMatchCall: matchexpr |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
406 if: (mcMain valid?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
407 mcall <- mcMain matchcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
408 withwhere addExpression: (quote: (matchres <- mcall)) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
409 successLambda <- quote: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
410 //Extra assignments will be added here |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
411 mlen <- matchres matchlen |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
412 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
413 matched? <- { true } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
414 matchlen <- { mlen } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
415 basicYield? <- { false } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
416 yield <- ylambda |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
417 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
418 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
419 sucexp <- syms fold: (successLambda expressions) with: :acc el { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
420 lsym <- el orig |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
421 rsym <- el matchval |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
422 (quote: (lsym <- rsym)) | acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
423 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
424 successLambda <- successLambda expressions!: sucexp |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
425 withwhere addExpression: (quote: (if: (matchres matched?) successLambda else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
426 matchres |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
427 })) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
428 withwhere |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
429 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
430 print: "#error Error in main match expression of match:where:yield: " . (mcMain message) . "\n" |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
431 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
432 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
433 |
225
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
434 binaryOps:withHigherPrec <- macro: :oplist :higher { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
435 quote: (match: Left . Pieces where: { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
436 Left <- match: higher |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
437 Pieces <- zeroPlus: (match: hws . Op . Right where: { |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
438 Op <- matchOne: oplist |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
439 Right <- match: higher |
225
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
440 } yield: { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
441 #{ |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
442 op <- Op |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
443 right <- Right |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
444 } |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
445 }) |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
446 } yield: { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
447 _processOpPieces: Left Pieces |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
448 }) |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
449 } |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
450 |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
451 opexpr <- binaryOps: ["&&" "||"] withHigherPrec: compare |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
452 compare <- binaryOps: ["<=" ">=" "<" ">" "=" "!="] withHigherPrec: maybecons |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
453 maybecons <- matchOne: [ |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
454 consop |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
455 addsub |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
456 ] |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
457 consop <- match: Left . hws . "|" . Right where: { |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
458 Left <- match: addsub |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
459 Right <- match: maybecons |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
460 } yield: { |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
461 #{ |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
462 left <- Left |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
463 op <- "|" |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
464 right <- Right |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
465 string <- { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
466 (string: left) . " " . op . " " . right |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
467 } |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
468 } |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
469 } |
225
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
470 addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
471 muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
472 |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
473 //TODO: Implement operator expressions |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
474 |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
475 |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
476 _alpha <- charClass: "a-zA-Z" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
477 alpha <- zeroPlus: _alpha |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
478 alphaNum <- zeroPlus: (charClass: "a-zA-Z0-9") |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
479 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
480 blockComment <- match: "/*" . (zeroPlus: (matchOne: [(charClass: "^*") "*" . (charClass: "^/")])) . "*/" yield: { false } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
481 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
482 hws <- zeroPlus: (matchOne: [ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
483 (charClass: " \t") |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
484 blockComment |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
485 ]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
486 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
487 ws <- zeroPlus: (matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
488 (charClass: " \n\t\r") |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
489 "//" . (zeroPlus: (charClass: "^\n")) . "\n" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
490 blockComment |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
491 ]) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
492 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
493 escape <- matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
494 (match: "\\n" yield: {"\n"}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
495 (match: "\\r" yield: {"\n"}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
496 (match: "\\t" yield: {"\n"}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
497 (match: "\\\\" yield: {"\\"}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
498 (match: "\\\"" yield: {"\""}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
499 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
500 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
501 string <- match: "\"" . Chars . "\"" where: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
502 Chars <- zeroPlus: (matchOne: [ |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
503 match: Reg where: { Reg <- charClass: "^\"\\" } yield: { Reg } |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
504 escape |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
505 ]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
506 } yield: { |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
507 if: (Chars length) = 0 { |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
508 Chars <- [] |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
509 } |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
510 Chars join: "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
511 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
512 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
513 bdigit <- matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
514 (match: "0" yield: {0i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
515 (match: "1" yield: {1i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
516 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
517 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
518 digit <- matchOne: [ |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
519 bdigit |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
520 (match: "2" yield: {2i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
521 (match: "3" yield: {3i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
522 (match: "4" yield: {4i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
523 (match: "5" yield: {5i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
524 (match: "6" yield: {6i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
525 (match: "7" yield: {7i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
526 (match: "8" yield: {8i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
527 (match: "9" yield: {9i64}) |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
528 ] |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
530 hdigit <- matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
531 digit |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
532 (match: (charClass: "aA") yield: {10i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
533 (match: (charClass: "bB") yield: {11i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
534 (match: (charClass: "cC") yield: {12i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
535 (match: (charClass: "dD") yield: {13i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
536 (match: (charClass: "eE") yield: {14i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
537 (match: (charClass: "fF") yield: {15i64}) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
538 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
539 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
540 binary <- match: "0b" . Digits . Suffix where: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
541 Digits <- onePlus: bdigit |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
542 Suffix <- matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
543 (charClass: "ui") . (matchOne: ["8" "16" "32" "64"]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
544 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
545 ] |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
546 } yield: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
547 num <- Digits fold: 0 with: :acc el { |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
548 acc * 2i64 + el |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
549 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
550 signed <- true |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
551 litbits <- 32 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
552 if: (Suffix length) > 0 { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
553 if: (Suffix from: 0 withLength: 1) = "u" { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
554 signed <- false |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
555 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
556 litbits <- (Suffix from: 1) int32 |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
557 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
558 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
559 litval <- num |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
560 signed? <- signed |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
561 bits <- litbits |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
562 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
563 str <- "0b" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
564 i <- bits - 1 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
565 printzero <- false |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
566 while: { i >= 0 } do: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
567 str <- str . (if: (lshift: 1 by: i) and num > 0 { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
568 printzero <- true |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
569 "1" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
570 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
571 if: printzero {"0"} else: {""} |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
572 }) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
573 i <- i - 1 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
574 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
575 if: (not: signed?) || bits != 32 { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
576 str <- str . (if: signed { "i" } else: { "u" }) . bits |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
577 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
578 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
579 } |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
580 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
581 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
582 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
583 decimal <- match: Sign . Digits . Suffix where: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
584 Sign <- matchOne: ["-" ""] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
585 Digits <- onePlus: digit |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
586 Suffix <- matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
587 (charClass: "ui") . (matchOne: ["8" "16" "32" "64"]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
588 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
589 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
590 } yield: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
591 num <- Digits fold: 0 with: :acc el { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
592 acc * 10i64 + el |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
593 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
594 if: Sign = "-" { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
595 num <- 0i64 - num |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
596 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
597 signed <- true |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
598 litbits <- 32 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
599 if: (Suffix length) > 0 { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
600 if: (Suffix from: 0 withLength: 1) = "u" { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
601 signed <- false |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
602 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
603 print: (Suffix from: 1) . "\n" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
604 litbits <- (Suffix from: 1) int32 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
605 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
606 #{ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
607 litval <- num |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
608 signed? <- signed |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
609 bits <- litbits |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
610 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
611 str <- string: litval |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
612 if: (not: signed?) || bits != 32 { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
613 str <- str . (if: signed? {"i"} else: {"u"}) . bits |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
614 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
615 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
616 } |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
617 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
618 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
619 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
620 hexlit <- match: "0x" . Digits . Suffix where: { |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
621 Digits <- onePlus: hdigit |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
622 Suffix <- matchOne: [ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
623 (charClass: "ui") . (matchOne: ["8" "16" "32" "64"]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
624 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
625 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
626 } yield: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
627 num <- Digits fold: 0 with: :acc el { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
628 acc * 16i64 + el |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
629 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
630 signed <- true |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
631 litbits <- 32 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
632 if: (Suffix length) > 0 { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
633 if: (Suffix from: 0 withLength: 1) = "u" { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
634 signed <- false |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
635 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
636 litbits <- (Suffix from: 1) int32 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
637 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
638 #{ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
639 litval <- num |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
640 signed? <- signed |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
641 bits <- litbits |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
642 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
643 str <- "0x" . (hex: litval) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
644 if: (not: signed?) || bits != 32 { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
645 str <- str . (if: signed? {"i"} else: {"u"}) . bits |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
646 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
647 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
648 } |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
649 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
650 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
651 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
652 symexpr <- match: Name where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
653 Name <- match: (onePlus: (charClass: "a-zA-Z_@!?")) . (zeroPlus: ((matchOne: [":" ""]) . (charClass: "a-zA-Z_@!?0-9"))) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
654 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
655 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
656 name <- Name |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
657 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
658 name |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
659 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
660 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
661 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
662 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
663 namepart <- match: hws . Symbol . ":" where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
664 Symbol <- match: symexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
665 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
666 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
667 isNamePart? <- { true } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
668 val <- Symbol name |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
669 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
670 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
671 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
672 argpart <- matchOne: [ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
673 match: namepart |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
674 match: Arg where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
675 Arg <- opexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
676 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
677 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
678 isNamePart? <- { false } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
679 val <- Arg |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
680 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
681 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
682 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
683 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
684 funcall <- match: hws . Initial . Parts where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
685 Initial <- match: namepart |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
686 Parts <- onePlus: argpart |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
687 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
688 Initial | Parts foldr: #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
689 name <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
690 args <- [] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
691 } with: :acc el { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
692 nextName <- acc name |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
693 nextArgs <- acc args |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
694 if: (el isNamePart?) { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
695 nextName <- if: ((acc name) length) > 0 { (el val) . ":" . (acc name) } else: { el val } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
696 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
697 nextArgs <- (el val) | nextArgs |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
698 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
699 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
700 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
701 name <- nextName |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
702 args <- nextArgs |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
703 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
704 str <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
705 curArgs <- args |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
706 nameParts <- name splitOn: ":" |
232
25b800094623
Fix string method of funcall nodes
Michael Pavone <pavone@retrodev.com>
parents:
231
diff
changeset
|
707 foreach: nameParts :idx part { |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
708 str <- str . part . ":" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
709 if: (not: (curArgs empty?)) { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
710 str <- str . " " . (curArgs value) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
711 curArgs <- curArgs tail |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
712 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
713 } |
235
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
714 while: { not: (curArgs empty?) } do: { |
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
715 str <- str . " " . (curArgs value) |
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
716 curArgs <- curArgs tail |
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
717 } |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
718 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
719 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
720 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
721 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
722 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
723 |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
724 unarymeth <- match: Receiver . hws . Method where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
725 Receiver <- match: opexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
726 Method <- match: symexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
727 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
728 #{ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
729 receiver <- Receiver |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
730 name <- Method name |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
731 args <- [] |
234
370e03964239
Add string method to unarymeth AST node object
Michael Pavone <pavone@retrodev.com>
parents:
232
diff
changeset
|
732 string <- { |
370e03964239
Add string method to unarymeth AST node object
Michael Pavone <pavone@retrodev.com>
parents:
232
diff
changeset
|
733 (string: receiver) . " " . name |
370e03964239
Add string method to unarymeth AST node object
Michael Pavone <pavone@retrodev.com>
parents:
232
diff
changeset
|
734 } |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
735 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
736 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
737 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
738 methcall <- match: Receiver . hws . Rest where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
739 Receiver <- match: opexpr |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
740 Rest <- match: funcall |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
741 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
742 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
743 receiver <- Receiver |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
744 name <- Rest name |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
745 args <- Rest args |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
746 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
747 nameParts <- name splitOn: ":" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
748 curArgs <- args |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
749 str <- (string: receiver) . " " |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
750 foreach: nameParts :part { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
751 str <- str . part . ":" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
752 if: (not: (curArgs empty?)) { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
753 str <- str . " " . (curArgs value) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
754 curArgs <- curArgs tail |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
755 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
756 } |
235
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
757 while: { not: (curArgs empty?) } do: { |
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
758 str <- str . " " . (curArgs value) |
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
759 curArgs <- curArgs tail |
cc1260872322
Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents:
234
diff
changeset
|
760 } |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
761 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
762 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
763 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
764 } |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
765 _processOpPieces <- :Left Pieces { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
766 if: (Pieces length) > 0 { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
767 Pieces fold: Left with: :acc piece { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
768 #{ |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
769 left <- acc |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
770 op <- piece op |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
771 right <- piece right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
772 string <- { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
773 (string: left) . " " . op . " " . right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
774 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
775 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
776 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
777 } else: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
778 Left |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
779 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
780 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
781 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
782 expr <- match: (hws . Expr . ws) where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
783 Expr <- matchOne: [ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
784 funcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
785 methcall |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
786 unarymeth |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
787 assignment |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
788 opexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
789 ] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
790 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
791 Expr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
792 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
793 |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
794 lexpr <- match: (hws . Expr . ws) where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
795 Expr <- matchOne: [ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
796 funcall |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
797 methcall |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
798 opexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
799 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
800 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
801 Expr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
802 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
803 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
804 assignment <- match: ws . Symbol . hws . "<-" . Expr where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
805 Symbol <- match: symexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
806 Expr <- match: expr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
807 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
808 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
809 assign <- Expr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
810 to <- Symbol |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
811 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
812 (string: to) . " <- " . assign |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
813 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
814 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
815 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
816 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
817 object <- match: "#{" . ws . Messages . "}" where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
818 Messages <- zeroPlus: assignment |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
819 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
820 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
821 messages <- Messages |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
822 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
823 "#{\n\t". ((messages map: :el { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
824 string: el |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
825 }) join: "\n\t") . "\n}" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
826 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
827 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
828 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
829 |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
830 listlit <- match: "[" . ws . Els . "]" where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
831 Els <- zeroPlus: lexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
832 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
833 //Handle limitation of zeroPlus macro |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
834 if: (Els length) = 0 { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
835 Els <- [] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
836 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
837 #{ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
838 litval <- Els |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
839 string <- { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
840 "[\n\t". ((litval map: :el { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
841 string: el |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
842 }) join: "\n\t") . "\n]" |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
843 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
844 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
845 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
846 |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
847 arraylit <- match: "#[" . ws . Els . "]" where: { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
848 Els <- zeroPlus: lexpr |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
849 } yield: { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
850 //Handle limitation of zeroPlus macro |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
851 if: (Els length) = 0 { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
852 Els <- [] |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
853 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
854 #{ |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
855 litval <- Els |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
856 string <- { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
857 "#[\n\t". ((litval map: :el { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
858 string: el |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
859 }) join: "\n\t") . "\n]" |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
860 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
861 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
862 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
863 |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
864 argname <- match: hws . Pre . Initial . Rest where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
865 Pre <- matchOne: [":" ""] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
866 Initial <- onePlus: (charClass: "a-zA-Z_!?@") |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
867 Rest <- zeroPlus: (charClass: "a-zA-Z_!?@0-9") |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
868 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
869 Pre . Initial . Rest |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
870 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
871 |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
872 lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
873 Arglist <- matchOne: [ |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
874 match: ":" . First . Rest where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
875 First <- match: symexpr |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
876 Rest <- zeroPlus: argname |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
877 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
878 if: (Rest length) = 0 { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
879 Rest <- [] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
880 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
881 ":" . (First name) | Rest |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
882 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
883 match: "" yield: { [] } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
884 ] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
885 Exprs <- zeroPlus: expr |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
886 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
887 if: (Exprs length) = 0 { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
888 Exprs <- [] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
889 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
890 #{ |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
891 args <- Arglist |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
892 expressions <- Exprs |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
893 string <- { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
894 (args join: " ") . "{\n\t" . |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
895 ((expressions map: :el { string: el }) join: "\n\t") . |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
896 "}" |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
897 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
898 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
899 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
900 |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
901 parenexp <- match: "(" . ws . Expr . ws . ")" where: { |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
902 Expr <- match: expr |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
903 } yield: { |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
904 Expr |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
905 } |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
906 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
907 primlitsym <- match: hws . Lit where: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
908 Lit <- matchOne: [ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
909 hexlit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
910 binary |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
911 decimal |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
912 symexpr |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
913 lambda |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
914 object |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
915 listlit |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
916 arraylit |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
917 string |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
918 parenexp |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
919 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
920 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
921 Lit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
922 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
923 |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
924 top <- matchOne: [ |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
925 object |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
926 lambda |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
927 ] |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
928 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
929 testmatchintlit <- :val matchfun { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
930 res <- matchfun: val |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
931 if: (res matched?) { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
932 y <- res yield |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
933 print: val . " matched with litval " . (y litval) . ", bits " . (y bits) . " and singned? " . (y signed?) . "\n" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
934 } else: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
935 print: val . " did not match\n" |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
936 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
937 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
938 |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
939 main <- :args { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
940 cmatch <- alpha: "czx0123" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
941 zeromatch <- alpha: "01234" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
942 if: (cmatch matched?) { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
943 print: "czx0123 matched with length " . (cmatch matchlen) . "\n" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
944 } else: { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
945 print: "czx0123 didn't match\n" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
946 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
947 if: (zeromatch matched?) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
948 print: "0123 matched with length " . (zeromatch matchlen) . "\n" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
949 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
950 print: "0123 didn't match\n" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
951 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
952 zeromatchanum <- alphaNum: "01234" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
953 if: (zeromatchanum matched?) { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
954 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
955 } else: { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
956 print: "01234 didn't match\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
957 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
958 stuff <- " \t/* blah blah blah * blah */ foo" |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
959 hwsmatch <- hws: stuff |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
960 if: (hwsmatch matched?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
961 print: "'" . (stuff from: (hwsmatch matchlen)) . "' found after hws\n" |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
962 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
963 print: stuff . " did not match hws rule\n" |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
964 } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
965 tmatch <- digit: "3" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
966 if: (tmatch matched?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
967 print: "3 matched with yield " . (tmatch yield) . ", yield + 1 = " . ((tmatch yield) + 1) . "\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
968 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
969 print: "3 did not match\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
970 } |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
971 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
972 testmatchintlit: "345" :s {decimal: s} |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
973 testmatchintlit: "-567" :s {decimal: s} |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
974 testmatchintlit: "123u16" :s {decimal: s} |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
975 testmatchintlit: "0x20" :s {hexlit: s} |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
976 testmatchintlit: "0x42u64" :s {hexlit: s} |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
977 testmatchintlit: "0b10101" :s {binary: s} |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
978 code <- "#{ foo <- 123 > 0x42 && 42 < 104\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n quine <- 123 | [4 5 6 fiddle sticks]\n quizzle <- #[receiver meth: arg]\n blah <- :arg arg2 :arg3 { arg + arg2 + arg3 }}" |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
979 if: (args length) > 1 { |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
980 file <- os open: (args get: 1) (os O_RDONLY) |
236
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
981 code <- "" |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
982 chunksize <- 1024 |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
983 readsize <- chunksize |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
984 while: { readsize = chunksize} do: { |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
985 seg <- os read: file chunksize |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
986 code <- code . seg |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
987 readsize <- seg byte_length |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
988 } |
231
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
989 } |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
990 codem <- top: code |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
991 if: (codem matched?) { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
992 print: code . "\nmatched with yield:\n" . (codem yield) . "\n" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
993 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
994 print: code . "\ndid not match\n" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
995 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
996 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
997 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
998 } |