Mercurial > repos > tabletprog
annotate modules/parser.tp @ 223:25db1c7c7300
Added addition and multiplication precedence level operators to grammar
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 29 Dec 2013 14:25:38 -0800 |
parents | c6e321a538d4 |
children | 262f5ae1bb1b |
rev | line source |
---|---|
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
2 _applyMatch <- :fun tomatch { |
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 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
5 _matchString <- :str tomatch { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
6 if: (tomatch isString?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
7 if: (tomatch length) < (str length) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
8 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
9 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
10 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
11 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
12 if: (tomatch length) > (str length) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
13 tomatch <- tomatch from: 0 withLength: (str length) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
14 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
15 if: str = tomatch { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
16 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
17 matched? <- { true } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
18 matchlen <- { str length } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
19 basicYield? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
20 yield <- { str } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
21 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
22 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
23 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
24 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
25 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
26 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
27 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
28 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
29 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
30 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
31 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
32 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
33 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
34 ifmatch:else <- :matchres :elseblock { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
35 if: (matchres matched?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
36 matchres |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
37 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
38 elseblock: |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
39 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
40 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
41 _makeMatchCall <- :matchexpr { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
42 if: (matchexpr nodeType) = "lambda" { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
43 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
44 valid? <- { true } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
45 matchcall <- quote: (_applyMatch: matchexpr tomatch) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
46 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
47 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
48 if: (matchexpr nodeType) = "symbol" { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
49 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
50 valid? <- { true } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
51 matchcall <- quote: (matchexpr: tomatch) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
52 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
53 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
54 if: (matchexpr nodeType) = "strlit" { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
55 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
56 valid? <- { true } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
57 matchcall <- quote: (_matchString: matchexpr tomatch) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
58 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
59 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
60 if: (matchexpr nodeType) = "op" { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
61 if: (matchexpr opName) = "." { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
62 left <- (_makeMatchCall: (matchexpr left)) matchcall |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
63 right <- (_makeMatchCall: (matchexpr right)) matchcall |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
64 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
65 valid? <- { true } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
66 matchcall <- quote: (_applyMatch: :tomatch { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
67 lm <- left |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
68 if: (lm matched?) { |
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
|
69 orig <- 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
|
70 tomatch <- tomatch from: (lm matchlen) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
71 rm <- right |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
72 if: (rm matched?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
73 total <- (rm matchlen) + (lm matchlen) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
74 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
75 matched? <- { true } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
76 matchlen <- { total } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
77 basicYield? <- { true } |
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
|
78 yield <- { orig from: 0 withLength: total } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
79 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
80 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
81 rm |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
82 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
83 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
84 lm |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
85 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
86 } tomatch) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
87 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
88 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
89 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
90 valid? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
91 message <- "Unsupported operator " . (matchexpr opName) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
92 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
93 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
94 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
95 #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
96 valid? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
97 message <- "Unsupported AST node type " . (matchexpr nodeType) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
98 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
99 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
100 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
101 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
102 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
103 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 expandClass <- :chars { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 if: (chars length) > 0 { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 pos <- 0 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 inverted <- false |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 if: (chars byte: 0) = ("^" byte: 0) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 pos <- 1 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 inverted <- true |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 state_begin <- 0 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 state_normal <- 1 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 state_rangeend <- 2 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 state <- state_begin |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 out <- "" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 while: { pos < (chars byte_length)} do: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 if: state = state_begin { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 out <- out . (chars from: pos withLength: 1) |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 state <- state_normal |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 if: state = state_normal { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 if: (chars byte: pos) = ("-" byte: 0) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 state <- state_rangeend |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 out <- out . (chars from: pos withLength: 1) |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 rangestart <- out byte: ((out byte_length) - 1) |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 rangeend <- chars byte: pos |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 if: rangeend < rangestart { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 tmp <- rangeend |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 rangeend <- rangestart |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 rangestart <- tmp |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 out <- out from: 0 withLength: ((out length) - 1) |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 while: { rangestart <= rangeend } do: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 out <- out . (rangestart asStringChar) |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 rangestart <- rangestart + 1 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 state <- state_begin |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 pos <- pos + 1 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 if: inverted { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 old <- out |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 out <- "" |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
149 //skip control characters for now |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
150 cur <- 32 |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 while: { cur < 256 } do: { |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
152 notfound <- true |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
153 idx <- 0 |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
154 len <- (old length) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
155 while: { notfound && idx < len } do: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
156 if: cur = (old byte: idx) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
157 notfound <- false |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
158 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
159 idx <- idx + 1 |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
160 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
161 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
162 if: notfound { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
163 out <- out . (cur asStringChar) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
164 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 cur <- cur + 1 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 out |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 "" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 charClass <- macro: :rawchars { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 eval: rawchars :chars { |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
175 orig <- chars |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 chars <- expandClass: chars |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 //TODO: Use a more sophisticated approach for large classes |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 quote: :tomatch { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 if: (tomatch isString?) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 check <- 0 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 nomatch <- true |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 while: { nomatch && check < (chars byte_length) } do: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 if: (tomatch byte: 0) = (chars byte: check) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 nomatch <- false |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 check <- check + 1 |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 if: nomatch { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 #{ |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 matched? <- { false } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 #{ |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 matched? <- { true } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 matchlen <- { 1 } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
197 basicYield? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
198 yield <- { tomatch from: 0 withLength: 1 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 #{ |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 matched? <- { false } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 } 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
|
208 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
|
209 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
211 |
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
|
212 _nPlus <- :matchexpr min { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
213 funexpr <- false |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
214 valid <- 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
|
215 mc <- _makeMatchCall: matchexpr |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
216 if: (mc valid?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
217 mcall <- mc matchcall |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
218 quote: :tomatch { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
219 cur <- 0 |
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
|
220 count <- 0 |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
221 n <- tomatch byte_length |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
222 orig <- tomatch |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
223 _match <- true |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
224 allBasic? <- true |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
225 yieldvals <- [] |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
226 while: { _match && cur < n } do: { |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
227 res <- mcall |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
228 _match <- res matched? |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
229 if: _match { |
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
|
230 count <- count + 1 |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
231 //TODO: Use some kind of lightweight substring wrapper here |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
232 tomatch <- tomatch from: (res matchlen) |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
233 if: allBasic? { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
234 ifnot: (res basicYield?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
235 allBasic? <- false |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
236 if: cur > 0 { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
237 yieldvals <- (orig from: 0 withLength: cur) | yieldvals |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
238 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
239 yieldvals <- (res yield) | yieldvals |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
240 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
241 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
242 yieldvals <- (res yield) | yieldvals |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
243 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
244 allBasic? <- allBasic? && (res basicYield?) |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
245 cur <- cur + (res matchlen) |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
246 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
247 } |
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
|
248 if: count >= min { |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
249 if: allBasic? { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
250 #{ |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
251 matched? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
252 matchlen <- { cur } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
253 basicYield? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
254 yield <- { orig from: 0 withLength: cur } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
255 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
256 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
257 yieldvals <- yieldvals reverse |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
258 #{ |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
259 matched? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
260 matchlen <- { cur } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
261 basicYield? <- { false } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
262 yield <- { yieldvals } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
263 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
264 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
265 } else: { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
266 #{ |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
267 matched? <- { false } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
268 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
269 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
270 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
271 } else: { |
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
|
272 print: "#error Invalid nPlus macro call: " . (mc message) . "\n" |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
273 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
274 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
275 |
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
|
276 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
|
277 _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
|
278 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
279 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
280 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
|
281 _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
|
282 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
283 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
284 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
|
285 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
|
286 _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
|
287 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
288 body <- options foldr: (quote: #{ |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
289 matched? <- { false } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
290 }) with: :acc el { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
291 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
|
292 mcall <- el matchcall |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
293 quote: (ifmatch: mcall else: { acc }) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
294 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
295 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
|
296 acc |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
297 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
298 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
299 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
|
300 body |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
301 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
302 } |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
303 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 mcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
310 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
311 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
312 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
|
313 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
314 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
315 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
316 match:yield <- macro: :matchexpr :ylambda { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
317 mc <- _makeMatchCall: matchexpr |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
318 if: (mc valid?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
319 mcall <- mc matchcall |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
320 quote: :tomatch { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
321 res <- mcall |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
322 if: (res matched?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
323 #{ |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
324 matched? <- { true } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
325 matchlen <- { res matchlen } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
326 basicYield? <- { false } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
327 yield <- ylambda |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
328 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
329 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
330 res |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
331 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
332 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
333 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
334 print: "#error Invalid macth:yield macro call: " . (mc message) . "\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
335 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
336 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
337 |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
338 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
|
339 syms <- [] |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
340 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
|
341 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
342 if: (el nodeType) = "assignment" { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
343 valassign <- quote: (val <- false) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
344 valsym <- (valassign) symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
345 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
|
346 valassign <- valassign symbol!: valsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
347 acc addExpression: valassign |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
348 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
349 matchassign <- quote: (hasmatch <- false) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
350 matchsym <- (matchassign) symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
351 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
|
352 matchassign <- matchassign symbol!: matchsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
353 acc addExpression: matchassign |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
354 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
355 mc <- _makeMatchCall: (el expression) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
356 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
357 if: (mc valid?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
358 mcall <- mc matchcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
359 matchfun <- quote: :tomatch { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
360 if: matchsym { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
361 if: valsym = tomatch { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
362 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
363 matched? <- { true } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
364 matchlen <- { valsym length } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
365 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
|
366 yield <- { valsym } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
367 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
368 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
369 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
370 matched? <- { false } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
371 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
372 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
373 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
374 mr <- mcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
375 if: (mr matched?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
376 matchsym <- true |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
377 valsym <- (mr yield) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
378 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
379 mr |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
380 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
381 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
382 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
|
383 syms <- list node: #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
384 orig <- el symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
385 matchval <- valsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
386 } withTail: syms |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
387 acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
388 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
389 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
|
390 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
391 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
392 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
393 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
|
394 acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
395 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
396 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
397 mcMain <- _makeMatchCall: matchexpr |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
398 if: (mcMain valid?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
399 mcall <- mcMain matchcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
400 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
|
401 successLambda <- quote: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
402 //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
|
403 mlen <- matchres matchlen |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
404 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
405 matched? <- { true } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
406 matchlen <- { mlen } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
407 basicYield? <- { false } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
408 yield <- ylambda |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
409 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
410 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
411 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
|
412 lsym <- el orig |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
413 rsym <- el matchval |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
414 (quote: (lsym <- rsym)) | acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
415 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
416 successLambda <- successLambda expressions!: sucexp |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
417 withwhere addExpression: (quote: (if: (matchres matched?) successLambda else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
418 matchres |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
419 })) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
420 withwhere |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
421 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
422 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
|
423 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
424 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
425 |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
426 |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
427 _alpha <- charClass: "a-zA-Z" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
428 alpha <- zeroPlus: _alpha |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
429 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
|
430 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
431 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
|
432 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
433 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
|
434 (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
|
435 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
|
436 ]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
437 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
438 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
|
439 (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
|
440 "//" . (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
|
441 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
|
442 ]) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
443 |
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
|
444 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
|
445 (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
|
446 (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
|
447 (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
|
448 (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
|
449 (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
|
450 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
451 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
452 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
|
453 Chars <- 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
|
454 (charClass: "^\"\\") |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
455 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
|
456 ]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
457 } 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
|
458 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
|
459 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
460 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
461 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
|
462 (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
|
463 (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
|
464 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
465 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
466 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
|
467 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
|
468 (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
|
469 (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
|
470 (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
|
471 (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
|
472 (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
|
473 (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
|
474 (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
|
475 (match: "9" yield: {9i64}) |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
476 ] |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 |
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
|
478 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
|
479 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
|
480 (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
|
481 (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
|
482 (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
|
483 (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
|
484 (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
|
485 (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
|
486 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
487 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
488 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
|
489 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
|
490 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
|
491 (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
|
492 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
493 ] |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
494 } yield: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
495 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
|
496 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
|
497 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
504 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
|
505 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
506 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
507 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
|
508 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
|
509 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
|
510 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 "1" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
518 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
519 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
|
520 }) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
521 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
|
522 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
523 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
|
524 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
|
525 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
526 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
527 } |
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
|
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 } |
a1a80af71b05
Implement 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 |
a1a80af71b05
Implement 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 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
|
532 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
|
533 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
|
534 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
|
535 (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
|
536 "" |
a1a80af71b05
Implement 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 ] |
a1a80af71b05
Implement 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 } 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
|
539 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
|
540 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
|
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 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
|
543 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
|
544 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 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
|
549 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
|
550 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
551 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
|
552 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
|
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 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
|
556 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
|
557 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
|
558 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
563 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
564 } |
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
|
565 } |
a1a80af71b05
Implement 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 } |
a1a80af71b05
Implement 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 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
568 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
|
569 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
|
570 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
|
571 (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
|
572 "" |
a1a80af71b05
Implement 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 ] |
a1a80af71b05
Implement 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 } 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
|
575 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
|
576 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
|
577 } |
a1a80af71b05
Implement 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 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 } |
a1a80af71b05
Implement 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 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
|
585 } |
a1a80af71b05
Implement 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 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
|
588 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
|
589 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
|
590 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
591 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
|
592 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
|
593 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
|
594 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
595 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
596 } |
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
|
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 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
599 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
600 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
|
601 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
|
602 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
603 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
604 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
|
605 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
606 name |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
607 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
608 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
609 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
610 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
611 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
|
612 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
|
613 } yield: { |
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 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
|
616 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
|
617 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
618 } |
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 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
|
621 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
|
622 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
|
623 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
|
624 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
625 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
626 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
|
627 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
|
628 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
629 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
630 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
631 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
632 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
|
633 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
|
634 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
|
635 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
636 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
|
637 name <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
638 args <- [] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
639 } 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
645 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
|
646 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
647 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
648 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
649 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
|
650 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
|
651 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
652 str <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
661 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
662 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
663 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
664 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
665 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
666 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
667 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
668 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
|
669 Receiver <- match: opexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
670 Rest <- matchOne: [funcall ( |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
671 match: Name where: { Name <- match: symexpr } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
672 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
673 name <- 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
|
674 args <- [] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
675 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
676 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
677 )] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
678 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
679 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
693 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
694 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
695 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
696 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
697 } |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
698 _processOpPieces <- :Left Pieces { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
699 if: (Pieces length) > 0 { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
700 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
|
701 #{ |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
702 left <- acc |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
703 op <- piece op |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
704 right <- piece right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
705 string <- { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
706 (string: left) . " " . op . " " . right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
707 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
708 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
709 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
710 } else: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
711 Left |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
712 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
713 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
714 |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
715 addsub <- match: Left . Pieces where: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
716 Left <- match: muldiv |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
717 Pieces <- zeroPlus: (match: hws . Op . Right where: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
718 Op <- matchOne: ["+" "-" "."] |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
719 Right <- match: muldiv |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
720 } yield: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
721 #{ |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
722 op <- Op |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
723 right <- Right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
724 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
725 }) |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
726 } yield: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
727 _processOpPieces: Left Pieces |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
728 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
729 |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
730 muldiv <- match: Left . Pieces where: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
731 Left <- match: primlitsym |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
732 Pieces <- zeroPlus: (match: hws . Op . Right where: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
733 Op <- matchOne: ["*" "/" "%"] |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
734 Right <- match: primlitsym |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
735 } yield: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
736 #{ |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
737 op <- Op |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
738 right <- Right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
739 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
740 }) |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
741 } yield: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
742 _processOpPieces: Left Pieces |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
743 } |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
744 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
745 //TODO: Implement operator expressions |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
746 opexpr <- match: addsub |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
747 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
748 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
|
749 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
|
750 funcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
751 methcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
752 opexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
753 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
754 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
755 Expr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
756 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
757 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
758 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
|
759 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
|
760 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
|
761 } yield: { |
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 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
|
764 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
|
765 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
766 (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
|
767 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
768 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
769 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
770 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
771 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
|
772 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
|
773 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
774 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
775 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
|
776 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
777 "#{\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
|
778 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
|
779 }) 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
|
780 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
781 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
782 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
783 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
784 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
|
785 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
|
786 hexlit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
787 binary |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
788 decimal |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
789 symexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
790 object |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
791 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
792 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
793 Lit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
794 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
795 |
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
|
796 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
|
797 res <- matchfun: val |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
798 if: (res matched?) { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
799 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
|
800 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
|
801 } 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
|
802 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
|
803 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
804 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
805 |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 main <- { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
807 cmatch <- alpha: "czx0123" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 zeromatch <- alpha: "01234" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 if: (cmatch matched?) { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
810 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
|
811 } else: { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
812 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
|
813 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 if: (zeromatch matched?) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 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
|
816 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
817 print: "0123 didn't match\n" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
818 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
819 zeromatchanum <- alphaNum: "01234" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
820 if: (zeromatchanum matched?) { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
821 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
822 } else: { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
823 print: "01234 didn't match\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
824 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
825 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
|
826 hwsmatch <- hws: stuff |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
827 if: (hwsmatch matched?) { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
828 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
|
829 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
830 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
|
831 } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
832 tmatch <- digit: "3" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
833 if: (tmatch matched?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
834 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
|
835 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
836 print: "3 did not match\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
837 } |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
838 |
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
|
839 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
|
840 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
|
841 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
|
842 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
|
843 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
|
844 testmatchintlit: "0b10101" :s {binary: s} |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
845 code <- "#{ foo <- 123\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}" |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
846 codem <- expr: code |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
847 if: (codem matched?) { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
848 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
|
849 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
850 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
|
851 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
852 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
853 } |