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