Mercurial > repos > tabletprog
annotate modules/parser.tp @ 247:b76f683d076e
Finish moving ast object definitions to a separate ast module
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 Jan 2014 19:27:19 -0800 |
parents | 8c81afd6d2d3 |
children | 004946743678 |
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 <- "" |
245
3590ecca6bc9
Fix handling of unescaped tabs in string literals in new parser
Mike Pavone <pavone@retrodev.com>
parents:
244
diff
changeset
|
288 cur <- 0 |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
289 while: { cur < 256 } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
290 notfound <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
291 idx <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
292 len <- (old length) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
293 while: { notfound && idx < len } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
294 if: cur = (old byte: idx) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
295 notfound <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
296 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
297 idx <- idx + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
298 } |
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 if: notfound { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
301 out <- out . (cur asStringChar) |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
302 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
303 cur <- cur + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
304 } |
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 out |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
307 } else: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
308 "" |
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 _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
|
312 orig <- chars |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
313 chars <- _expandClass: chars |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
314 charmap <- "" |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
315 char <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
316 while: { char < 256 } do: { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
317 mchar <- 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
318 found <- false |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
319 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
|
320 if: (chars byte: mchar) = char { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
321 found <- true |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
322 mchar <- chars byte_length |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
323 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
324 mchar <- mchar + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
325 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
326 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
|
327 char <- char + 1 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
328 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
329 t <- "t" byte: 0 |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
330 quote: :tomatch { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
331 if: (tomatch isString?) { |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
332 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
|
333 #{ |
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
|
334 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
|
335 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 } |
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 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
|
338 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
|
339 } |
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 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
|
341 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
|
342 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
343 matchlen <- { 1 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
344 basicYield? <- { true } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
345 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
|
346 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
347 } 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
|
348 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
|
349 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
350 } 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
|
351 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
|
352 } |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
353 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
354 } |
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
355 #{ |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 charClass <- macro: :rawchars { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 eval: rawchars :chars { |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
358 _charClass: chars |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 } 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
|
360 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
|
361 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
363 |
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
|
364 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
|
365 _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
|
366 } |
a1a80af71b05
Implement 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 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
|
369 _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
|
370 } |
a1a80af71b05
Implement 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 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
372 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
|
373 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
|
374 _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
|
375 } |
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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
381 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
|
382 acc |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
383 } |
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 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
|
386 body |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
387 } |
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 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 mcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
396 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
397 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
398 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
|
399 } |
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 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
402 match:yield <- macro: :matchexpr :ylambda { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
403 mc <- _makeMatchCall: matchexpr |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
404 if: (mc valid?) { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
405 mcall <- mc matchcall |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
406 quote: :tomatch { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
407 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
|
408 if: res { |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
409 #{ |
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
|
410 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
|
411 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 } |
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 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
|
414 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
|
415 } |
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 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
|
417 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
|
418 } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
419 matchlen <- { res matchlen } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
420 basicYield? <- { false } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
421 yield <- ylambda |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
422 } |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
423 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
424 res |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
425 } |
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 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
428 print: "#error Invalid macth:yield macro call: " . (mc message) . "\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
429 } |
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 |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
432 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
|
433 syms <- [] |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
434 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
|
435 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
436 if: (el nodeType) = "assignment" { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
437 valassign <- quote: (val <- false) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
438 valsym <- (valassign) symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
439 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
|
440 valassign <- valassign symbol!: valsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
441 acc addExpression: valassign |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
442 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
443 matchassign <- quote: (hasmatch <- false) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
444 matchsym <- (matchassign) symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
445 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
|
446 matchassign <- matchassign symbol!: matchsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
447 acc addExpression: matchassign |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
448 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
449 mc <- _makeMatchCall: (el expression) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
450 |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
451 if: (mc valid?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
452 mcall <- mc matchcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
453 matchfun <- quote: :tomatch { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
454 if: matchsym { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
455 if: valsym = tomatch { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
456 #{ |
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
|
457 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
|
458 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 } |
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 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
|
461 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
|
462 } |
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 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
|
464 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
|
465 } |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
466 matchlen <- { valsym length } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
467 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
|
468 yield <- { valsym } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
469 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
470 } 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
|
471 false |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
472 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
473 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
474 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
|
475 if: mr { |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
476 matchsym <- true |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
477 valsym <- (mr yield) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
478 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
479 mr |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
480 } |
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 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
|
483 syms <- list node: #{ |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
484 orig <- el symbol |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
485 matchval <- valsym |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
486 } withTail: syms |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
487 acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
488 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
489 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
|
490 } |
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 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
493 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
|
494 acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
495 } |
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 mcMain <- _makeMatchCall: matchexpr |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
498 if: (mcMain valid?) { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
499 mcall <- mcMain matchcall |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
500 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
|
501 successLambda <- quote: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
502 //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
|
503 mlen <- matchres matchlen |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
504 #{ |
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
|
505 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
|
506 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 } |
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 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
|
509 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
|
510 } |
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 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
|
512 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
|
513 } |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
514 matchlen <- { mlen } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
515 basicYield? <- { false } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
516 yield <- ylambda |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
517 } |
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 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
|
520 lsym <- el orig |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
521 rsym <- el matchval |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
522 (quote: (lsym <- rsym)) | acc |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
523 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
524 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
|
525 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
|
526 matchres |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
527 })) |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
528 withwhere |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
529 } else: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
530 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
|
531 } |
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 |
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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 Op <- matchOne: oplist |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
539 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
|
540 } 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
|
541 #{ |
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 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
|
543 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
|
544 } |
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 } 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
|
547 _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
|
548 }) |
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 |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
551 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
|
552 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
|
553 maybecons <- matchOne: [ |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
554 consop |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
555 addsub |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
556 ] |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
557 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
|
558 Left <- match: addsub |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
559 Right <- match: maybecons |
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
560 } yield: { |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
561 ast binaryOp: "|" withArgs: Left Right |
226
6055f56d0e45
Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
562 } |
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
|
563 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
|
564 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
|
565 |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
566 |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
567 _alpha <- charClass: "a-zA-Z" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
568 alpha <- zeroPlus: _alpha |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
569 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
|
570 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
571 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
|
572 |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
573 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
|
574 (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
|
575 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
|
576 ]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
577 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
578 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
|
579 (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
|
580 "//" . (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
|
581 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
|
582 ]) |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
583 |
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
|
584 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
|
585 (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
|
586 (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
|
587 (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
|
588 (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
|
589 (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
|
590 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
591 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 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
|
596 ]) |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
597 } 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
|
598 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
|
599 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
|
600 } |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
601 ast stringLit: (Chars join: "") |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
602 } |
a1a80af71b05
Implement 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 |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
604 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
|
605 (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
|
606 (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
|
607 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
608 |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
609 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
|
610 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
|
611 (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
|
612 (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
|
613 (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
|
614 (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
|
615 (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
|
616 (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
|
617 (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
|
618 (match: "9" yield: {9i64}) |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
619 ] |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 |
220
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
621 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
|
622 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
|
623 (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
|
624 (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
|
625 (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
|
626 (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
|
627 (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
|
628 (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
|
629 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
630 |
a1a80af71b05
Implement 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 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
|
632 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
|
633 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
|
634 (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
|
635 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
636 ] |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
637 } yield: { |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
638 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
|
639 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
|
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 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
647 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
|
648 } |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
649 ast intLit: num withBits: litbits andBase: 2 signed?: signed |
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
|
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 |
a1a80af71b05
Implement 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 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
|
653 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
|
654 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
|
655 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
|
656 (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
|
657 "" |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
658 ] |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
659 } 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
|
660 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
|
661 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
|
662 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
663 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
|
664 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
|
665 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
672 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
|
673 } |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
674 ast intLit: num withBits: litbits andBase: 10 signed?: signed |
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
|
675 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
676 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 (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
|
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 } 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
|
684 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
|
685 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
|
686 } |
a1a80af71b05
Implement 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 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 } |
a1a80af71b05
Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
693 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
|
694 } |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
695 ast intLit: num withBits: litbits andBase: 16 signed?: signed |
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
|
696 } |
a1a80af71b05
Implement 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 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
698 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
|
699 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
|
700 } yield: { |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
701 ast symbol: Name |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
702 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
703 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
704 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
|
705 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
|
706 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
707 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
708 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
|
709 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
|
710 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
711 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
712 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
713 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
|
714 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
|
715 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
|
716 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
|
717 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
718 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
719 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
|
720 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
|
721 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
722 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
723 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
724 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
725 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
|
726 Initial <- match: namepart |
244
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
727 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
|
728 } yield: { |
244
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
729 if: (Parts length) = 0 { |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
730 Parts <- [] |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
731 } |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
732 combined <- Initial | Parts foldr: #{ |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
733 name <- "" |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
734 args <- [] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
735 } 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
|
736 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
|
737 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
|
738 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
|
739 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
|
740 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
741 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
|
742 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
743 #{ |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
744 name <- nextName |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
745 args <- nextArgs |
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 } |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
748 ast funcall: (ast symbol: (combined name)) withArgs: (combined args) hasReceiver?: false |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
749 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
750 |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
751 unarymeth <- match: Receiver . hws . Method where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
752 Receiver <- match: opexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
753 Method <- match: symexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
754 } yield: { |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
755 ast funcall: Method withArgs: [Receiver] hasReceiver?: true |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
756 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
757 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
758 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
|
759 Receiver <- match: opexpr |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
760 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
|
761 } yield: { |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
762 ast funcall: (Rest tocall) withArgs: Receiver | (Rest args) hasReceiver?: true |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
763 } |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
764 _processOpPieces <- :Left Pieces { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
765 if: (Pieces length) > 0 { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
766 Pieces fold: Left with: :acc piece { |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
767 ast binaryOp: (piece op) withArgs: acc (piece right) |
223
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
768 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
769 } else: { |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
770 Left |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
771 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
772 } |
25db1c7c7300
Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents:
222
diff
changeset
|
773 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
774 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
|
775 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
|
776 funcall |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
777 methcall |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
778 unarymeth |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
779 assignment |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
780 opexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
781 ] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
782 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
783 Expr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
784 } |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
785 |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
786 lexpr <- match: (hws . Expr . ws) where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
787 Expr <- matchOne: [ |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
788 funcall |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
789 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
|
790 opexpr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
791 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
792 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
793 Expr |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
794 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
795 |
244
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
796 opsym <- match: Name where: { |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
797 Name <- matchOne: ["&&" "||" "<=" ">=" "<" ">" "=" "!=" "=" "-" "." "*" "/" "%" "|"] |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
798 } yield: { |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
799 #{ |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
800 name <- Name |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
801 string <- { |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
802 name |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
803 } |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
804 } |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
805 } |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
806 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
807 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
|
808 Symbol <- matchOne: [ |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
809 symexpr |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
810 opsym |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
811 ] |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
812 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
|
813 } yield: { |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
814 ast assign: Expr to: Symbol |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
815 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
816 |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
817 object <- match: "#{" . ws . Messages . "}" where: { |
244
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
818 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
|
819 El <- matchOne: [ |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
820 assignment |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
821 funcall |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
822 ] |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
823 } 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
|
824 } yield: { |
244
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
825 if: (Messages length) = 0 { |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
826 Messages <- [] |
ae5188be523e
Improve compatibility of new parser with the old one
Mike Pavone <pavone@retrodev.com>
parents:
243
diff
changeset
|
827 } |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
828 ast object: Messages |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
829 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
830 |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
831 listlit <- match: "[" . ws . Els . "]" where: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
832 Els <- zeroPlus: lexpr |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
833 } yield: { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
834 //Handle limitation of zeroPlus macro |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
835 if: (Els length) = 0 { |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
836 Els <- [] |
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
837 } |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
838 ast seqLit: Els array?: false |
227
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 |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
841 arraylit <- match: "#[" . ws . Els . "]" where: { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
842 Els <- zeroPlus: lexpr |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
843 } yield: { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
844 //Handle limitation of zeroPlus macro |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
845 if: (Els length) = 0 { |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
846 Els <- [] |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
847 } |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
848 ast seqLit: Els array?: true |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
849 } |
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
850 |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
851 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
|
852 Pre <- matchOne: [":" ""] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
853 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
|
854 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
|
855 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
856 Pre . Initial . Rest |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
857 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
858 |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
859 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
|
860 Arglist <- matchOne: [ |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
861 match: ":" . First . Rest where: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
862 First <- match: symexpr |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
863 Rest <- zeroPlus: argname |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
864 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
865 if: (Rest length) = 0 { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
866 Rest <- [] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
867 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
868 ":" . (First name) | Rest |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
869 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
870 match: "" yield: { [] } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
871 ] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
872 Exprs <- zeroPlus: expr |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
873 } yield: { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
874 if: (Exprs length) = 0 { |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
875 Exprs <- [] |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
876 } |
247
b76f683d076e
Finish moving ast object definitions to a separate ast module
Michael Pavone <pavone@retrodev.com>
parents:
246
diff
changeset
|
877 ast lambda: Exprs withArgs: Arglist |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
878 } |
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
879 |
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
|
880 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
|
881 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
|
882 } 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
|
883 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
|
884 } |
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
|
885 |
222
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
886 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
|
887 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
|
888 hexlit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
889 binary |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
890 decimal |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
891 symexpr |
230
195f02ba349b
Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents:
228
diff
changeset
|
892 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
|
893 object |
227
8c16ef123aee
Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents:
226
diff
changeset
|
894 listlit |
228
decdf28a8517
Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents:
227
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 ] |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
899 } yield: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
900 Lit |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
901 } |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
902 |
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
|
903 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
|
904 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
|
905 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
|
906 ] |
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
|
907 |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
908 testmatchintlit <- :tomatch matchfun { |
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
909 res <- matchfun: tomatch |
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
|
910 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
|
911 y <- res yield |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
912 print: tomatch . " matched with litval " . (y val) . ", bits " . (y bits) . " and singned? " . (y signed?) . "\n" |
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
|
913 } else: { |
246
8c81afd6d2d3
Refactor some of the AST node object constructors into a separate AST module
Michael Pavone <pavone@retrodev.com>
parents:
245
diff
changeset
|
914 print: tomatch . " 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
|
915 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
916 } |
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
917 |
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
|
918 main <- :args { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
919 cmatch <- alpha: "czx0123" |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
920 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
|
921 if: cmatch { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
922 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
|
923 } else: { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
924 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
|
925 } |
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
|
926 if: zeromatch { |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
927 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
|
928 } else: { |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
929 print: "0123 didn't match\n" |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
930 } |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
931 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
|
932 if: zeromatchanum { |
209
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
933 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
934 } else: { |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
935 print: "01234 didn't match\n" |
4b3b57f39f10
Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents:
208
diff
changeset
|
936 } |
212
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
937 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
|
938 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
|
939 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
|
940 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
|
941 } else: { |
32080f96c3a0
Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents:
209
diff
changeset
|
942 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
|
943 } |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
944 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
|
945 if: tmatch { |
213
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
946 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
|
947 } else: { |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
948 print: "3 did not match\n" |
e00a8bc6361b
Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents:
212
diff
changeset
|
949 } |
218
b799192e404b
Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
950 |
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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 code <- "" |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
961 chunksize <- 1024 |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
962 readsize <- chunksize |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
963 while: { readsize = chunksize} do: { |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
964 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
|
965 code <- code . seg |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
966 readsize <- seg byte_length |
c463a891ccd3
Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
967 } |
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
|
968 } |
e48c74a7539e
Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents:
230
diff
changeset
|
969 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
|
970 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
|
971 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
|
972 } else: { |
c6e321a538d4
Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents:
220
diff
changeset
|
973 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
|
974 } |
208
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
975 } |
a1b4a2bc8d72
Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
976 } |
239
6aab8a5a2be9
Don't expose internal helper functions in parser module
Mike Pavone <pavone@retrodev.com>
parents:
237
diff
changeset
|
977 } |