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