annotate modules/parser.tp @ 245:3590ecca6bc9

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