Mercurial > repos > tabletprog
annotate modules/parser.tp @ 230:195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 02 Jan 2014 21:04:10 -0800 |
parents | decdf28a8517 |
children | e48c74a7539e |
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 |
225
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
426 binaryOps:withHigherPrec <- macro: :oplist :higher { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
427 quote: (match: Left . Pieces where: { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
428 Left <- match: higher |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
429 Pieces <- zeroPlus: (match: hws . Op . Right where: { |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
430 Op <- matchOne: oplist |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
431 Right <- match: higher |
225
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
432 } yield: { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
433 #{ |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
434 op <- Op |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
435 right <- Right |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
436 } |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
437 }) |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
438 } yield: { |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
439 _processOpPieces: Left Pieces |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
440 }) |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
441 } |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
442 |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
443 opexpr <- binaryOps: ["&&" "||"] withHigherPrec: compare |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
444 compare <- binaryOps: ["<=" ">=" "<" ">" "=" "!="] withHigherPrec: maybecons |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
445 maybecons <- matchOne: [ |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
446 consop |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
447 addsub |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
448 ] |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
449 consop <- match: Left . hws . "|" . Right where: { |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
450 Left <- match: addsub |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
451 Right <- match: maybecons |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
452 } yield: { |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
453 #{ |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
454 left <- Left |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
455 op <- "|" |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
456 right <- Right |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
457 string <- { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
458 (string: left) . " " . op . " " . right |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
459 } |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
460 } |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
461 } |
225
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
462 addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
463 muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
464 |
262f5ae1bb1b
Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents:
223
diff
changeset
|
465 //TODO: Implement operator expressions |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
466 |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
467 |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
468 _alpha <- charClass: "a-zA-Z" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
469 alpha <- zeroPlus: _alpha |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
470 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
|
471 |
a1a80af71b05
Implement 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 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
|
473 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
474 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
|
475 (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
|
476 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
|
477 ]) |
a1a80af71b05
Implement 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 |
a1a80af71b05
Implement 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 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
|
480 (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
|
481 "//" . (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
|
482 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
|
483 ]) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
484 |
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
|
485 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
|
486 (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
|
487 (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
|
488 (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
|
489 (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
|
490 (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
|
491 ] |
a1a80af71b05
Implement 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 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
|
494 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
|
495 (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
|
496 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
|
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 } yield: { |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
499 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
|
500 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
501 |
a1a80af71b05
Implement 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 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
|
503 (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
|
504 (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
|
505 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
506 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
507 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
|
508 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
|
509 (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
|
510 (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
|
511 (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
|
512 (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
|
513 (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
|
514 (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
|
515 (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
|
516 (match: "9" yield: {9i64}) |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
517 ] |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
519 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
|
520 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
|
521 (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
|
522 (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
|
523 (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
|
524 (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
|
525 (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
|
526 (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
|
527 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
528 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
529 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
|
530 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
|
531 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
|
532 (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
|
533 "" |
a1a80af71b05
Implement 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 ] |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
535 } yield: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
536 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
|
537 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
|
538 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
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 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
|
546 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
547 #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 "1" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
559 } else: { |
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: 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
|
561 }) |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
562 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
|
563 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
564 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
|
565 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
|
566 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
567 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
568 } |
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 } |
a1a80af71b05
Implement 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 } |
a1a80af71b05
Implement 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 |
a1a80af71b05
Implement 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 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
|
573 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
|
574 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
|
575 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
|
576 (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
|
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 ] |
a1a80af71b05
Implement 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 } 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
|
580 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
|
581 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
|
582 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
583 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
|
584 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
|
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 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
592 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
|
593 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
|
594 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
595 #{ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
596 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
|
597 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
|
598 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
|
599 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
600 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
|
601 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
|
602 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
|
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 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
605 } |
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
|
606 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
607 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
608 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
609 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
|
610 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
|
611 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
|
612 (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
|
613 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
614 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
615 } 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
|
616 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
|
617 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
|
618 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
619 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
|
620 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
|
621 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
|
622 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
|
623 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
|
624 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
625 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
|
626 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
627 #{ |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
628 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
|
629 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
|
630 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
|
631 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
632 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
|
633 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
|
634 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
|
635 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
636 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
637 } |
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
|
638 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
639 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
640 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
641 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
|
642 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
|
643 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
644 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
645 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
|
646 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
647 name |
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 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
650 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
651 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
652 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
|
653 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
|
654 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
655 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
656 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
|
657 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
|
658 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
659 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
660 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
661 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
|
662 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
|
663 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
|
664 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
|
665 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
666 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
667 isNamePart? <- { false } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
668 val <- Arg |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
669 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
670 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
671 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
672 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
673 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
|
674 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
|
675 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
|
676 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
677 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
|
678 name <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
679 args <- [] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
680 } 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
686 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
|
687 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
688 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
689 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
690 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
|
691 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
|
692 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
693 str <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 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
|
701 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
702 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
703 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
704 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
705 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
706 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
707 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
708 |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
709 unarymeth <- match: Receiver . hws . Method where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
710 Receiver <- match: opexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
711 Method <- match: symexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
712 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
713 #{ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
714 receiver <- Receiver |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
715 name <- Method name |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
716 args <- [] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
717 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
718 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
719 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
720 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
|
721 Receiver <- match: opexpr |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
722 Rest <- match: funcall |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
723 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
724 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
725 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
|
726 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
|
727 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
|
728 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
729 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
|
730 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
|
731 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
|
732 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
738 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
739 str |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
740 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
741 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
742 } |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
743 _processOpPieces <- :Left Pieces { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
744 if: (Pieces length) > 0 { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
745 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
|
746 #{ |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
747 left <- acc |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
748 op <- piece op |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
749 right <- piece right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
750 string <- { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
751 (string: left) . " " . op . " " . right |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
752 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
753 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
754 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
755 } else: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
756 Left |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
757 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
758 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
759 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
760 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
|
761 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
|
762 funcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
763 methcall |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
764 unarymeth |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
765 assignment |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
766 opexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
767 ] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
768 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
769 Expr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
770 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
771 |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
772 lexpr <- match: (hws . Expr . ws) where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
773 Expr <- matchOne: [ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
774 funcall |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
775 methcall |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
776 opexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
777 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
778 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
779 Expr |
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 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
|
783 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
|
784 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
|
785 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
786 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
787 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
|
788 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
|
789 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
790 (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
|
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 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
793 } |
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 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
|
796 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
|
797 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
798 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
799 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
|
800 string <- { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
801 "#{\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
|
802 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
|
803 }) 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
|
804 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
805 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
806 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
807 |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
808 listlit <- match: "[" . ws . Els . "]" where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
809 Els <- zeroPlus: lexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
810 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
811 //Handle limitation of zeroPlus macro |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
812 if: (Els length) = 0 { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
813 Els <- [] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
814 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
815 #{ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
816 litval <- Els |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
817 string <- { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
818 "[\n\t". ((litval map: :el { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
819 string: el |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
820 }) join: "\n\t") . "\n]" |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
821 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
822 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
823 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
824 |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
825 arraylit <- match: "#[" . ws . Els . "]" where: { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
826 Els <- zeroPlus: lexpr |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
827 } yield: { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
828 //Handle limitation of zeroPlus macro |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
829 if: (Els length) = 0 { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
830 Els <- [] |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
831 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
832 #{ |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
833 litval <- Els |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
834 string <- { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
835 "#[\n\t". ((litval map: :el { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
836 string: el |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
837 }) join: "\n\t") . "\n]" |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
838 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
839 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
840 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
841 |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
842 argname <- match: hws . Pre . Initial . Rest where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
843 Pre <- matchOne: [":" ""] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
844 Initial <- onePlus: (charClass: "a-zA-Z_!?@") |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
845 Rest <- zeroPlus: (charClass: "a-zA-Z_!?@0-9") |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
846 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
847 Pre . Initial . Rest |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
848 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
849 |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
850 lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
851 Arglist <- matchOne: [ |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
852 match: ":" . First . Rest where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
853 First <- match: symexpr |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
854 Rest <- zeroPlus: argname |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
855 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
856 if: (Rest length) = 0 { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
857 Rest <- [] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
858 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
859 ":" . (First name) | Rest |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
860 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
861 match: "" yield: { [] } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
862 ] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
863 Exprs <- zeroPlus: expr |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
864 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
865 if: (Exprs length) = 0 { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
866 Exprs <- [] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
867 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
868 #{ |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
869 args <- Arglist |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
870 expressions <- Exprs |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
871 string <- { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
872 (args join: " ") . "{\n\t" . |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
873 ((expressions map: :el { string: el }) join: "\n\t") . |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
874 "}" |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
875 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
876 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
877 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
878 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
879 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
|
880 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
|
881 hexlit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
882 binary |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
883 decimal |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
884 symexpr |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
885 lambda |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
886 object |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
887 listlit |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
888 arraylit |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
889 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
890 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
891 Lit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
892 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
893 |
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
|
894 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
|
895 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
|
896 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
|
897 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
|
898 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
|
899 } 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
|
900 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
|
901 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
902 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
903 |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
904 main <- { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
905 cmatch <- alpha: "czx0123" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
906 zeromatch <- alpha: "01234" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
907 if: (cmatch matched?) { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
908 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
|
909 } else: { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
910 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
|
911 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
912 if: (zeromatch matched?) { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
913 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
|
914 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
915 print: "0123 didn't match\n" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
916 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
917 zeromatchanum <- alphaNum: "01234" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
918 if: (zeromatchanum matched?) { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
919 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
920 } else: { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
921 print: "01234 didn't match\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
922 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
923 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
|
924 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
|
925 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
|
926 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
|
927 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
928 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
|
929 } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
930 tmatch <- digit: "3" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
931 if: (tmatch matched?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
932 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
|
933 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
934 print: "3 did not match\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
935 } |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
936 |
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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 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
|
942 testmatchintlit: "0b10101" :s {binary: s} |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
943 code <- "#{ foo <- 123 > 0x42 && 42 < 104\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n quine <- 123 | [4 5 6 fiddle sticks]\n quizzle <- #[receiver meth: arg]\n blah <- :arg arg2 :arg3 { arg + arg2 + arg3 }}" |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
944 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
|
945 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
|
946 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
|
947 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
948 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
|
949 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
950 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
951 } |