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