annotate modules/parser.tp @ 225:262f5ae1bb1b

Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 14:39:54 -0800
parents 25db1c7c7300
children 6055f56d0e45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
2 _applyMatch <- :fun tomatch {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
3 fun: tomatch
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
4 }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
5 _matchString <- :str tomatch {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
6 if: (tomatch isString?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
7 if: (tomatch length) < (str length) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
8 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
9 matched? <- { false }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
10 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
11 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
12 if: (tomatch length) > (str length) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
13 tomatch <- tomatch from: 0 withLength: (str length)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
14 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
15 if: str = tomatch {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
16 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
17 matched? <- { true }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
18 matchlen <- { str length }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
19 basicYield? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
20 yield <- { str }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
21 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
22 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
23 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
24 matched? <- { false }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
25 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
26 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
27 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
28 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
29 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
30 matched? <- { false }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
31 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
32 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
33 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
34 ifmatch:else <- :matchres :elseblock {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
35 if: (matchres matched?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
36 matchres
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
37 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
38 elseblock:
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
39 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
40 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
41 _makeMatchCall <- :matchexpr {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
42 if: (matchexpr nodeType) = "lambda" {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
43 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
44 valid? <- { true }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
45 matchcall <- quote: (_applyMatch: matchexpr tomatch)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
46 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
47 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
48 if: (matchexpr nodeType) = "symbol" {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
49 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
50 valid? <- { true }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
51 matchcall <- quote: (matchexpr: tomatch)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
52 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
53 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
54 if: (matchexpr nodeType) = "strlit" {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
55 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
56 valid? <- { true }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
57 matchcall <- quote: (_matchString: matchexpr tomatch)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
58 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
59 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
60 if: (matchexpr nodeType) = "op" {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
61 if: (matchexpr opName) = "." {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
62 left <- (_makeMatchCall: (matchexpr left)) matchcall
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
63 right <- (_makeMatchCall: (matchexpr right)) matchcall
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
64 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
65 valid? <- { true }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
66 matchcall <- quote: (_applyMatch: :tomatch {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
67 lm <- left
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
68 if: (lm matched?) {
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
69 orig <- tomatch
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
70 tomatch <- tomatch from: (lm matchlen)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
71 rm <- right
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
72 if: (rm matched?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
73 total <- (rm matchlen) + (lm matchlen)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
74 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
75 matched? <- { true }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
76 matchlen <- { total }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
77 basicYield? <- { true }
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
78 yield <- { orig from: 0 withLength: total }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
79 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
80 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
81 rm
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
82 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
83 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
84 lm
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
85 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
86 } tomatch)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
87 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
88 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
89 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
90 valid? <- { false }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
91 message <- "Unsupported operator " . (matchexpr opName)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
92 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
93 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
94 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
95 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
96 valid? <- { false }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
97 message <- "Unsupported AST node type " . (matchexpr nodeType)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
98 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
99 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
100 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
101 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
102 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
103 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 expandClass <- :chars {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 if: (chars length) > 0 {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 pos <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 inverted <- false
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 if: (chars byte: 0) = ("^" byte: 0) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 pos <- 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 inverted <- true
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 state_begin <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 state_normal <- 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 state_rangeend <- 2
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 state <- state_begin
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 out <- ""
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 while: { pos < (chars byte_length)} do: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 if: state = state_begin {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 out <- out . (chars from: pos withLength: 1)
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 state <- state_normal
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 if: state = state_normal {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 if: (chars byte: pos) = ("-" byte: 0) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 state <- state_rangeend
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
125 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 out <- out . (chars from: pos withLength: 1)
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 rangestart <- out byte: ((out byte_length) - 1)
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 rangeend <- chars byte: pos
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 if: rangeend < rangestart {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 tmp <- rangeend
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 rangeend <- rangestart
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
134 rangestart <- tmp
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 out <- out from: 0 withLength: ((out length) - 1)
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 while: { rangestart <= rangeend } do: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 out <- out . (rangestart asStringChar)
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 rangestart <- rangestart + 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 state <- state_begin
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 pos <- pos + 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 if: inverted {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147 old <- out
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 out <- ""
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
149 //skip control characters for now
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
150 cur <- 32
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151 while: { cur < 256 } do: {
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
152 notfound <- true
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
153 idx <- 0
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
154 len <- (old length)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
155 while: { notfound && idx < len } do: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
156 if: cur = (old byte: idx) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
157 notfound <- false
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
158 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
159 idx <- idx + 1
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
160 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
161 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
162 if: notfound {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
163 out <- out . (cur asStringChar)
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
164 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
165 cur <- cur + 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
166 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
167 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 out
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 ""
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 charClass <- macro: :rawchars {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 eval: rawchars :chars {
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
175 orig <- chars
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 chars <- expandClass: chars
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 //TODO: Use a more sophisticated approach for large classes
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 quote: :tomatch {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 if: (tomatch isString?) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 check <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 nomatch <- true
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 while: { nomatch && check < (chars byte_length) } do: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 if: (tomatch byte: 0) = (chars byte: check) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 nomatch <- false
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 check <- check + 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 if: nomatch {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191 matched? <- { false }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 matched? <- { true }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 matchlen <- { 1 }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
197 basicYield? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
198 yield <- { tomatch from: 0 withLength: 1 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
200 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
201 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
202 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 matched? <- { false }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
204 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
205 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
206 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207 } else: {
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
208 print: "#error Argument to charClass macro must be a compile-time constant\n"
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
209 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
211
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
212 _nPlus <- :matchexpr min {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
213 funexpr <- false
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
214 valid <- false
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
215 mc <- _makeMatchCall: matchexpr
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
216 if: (mc valid?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
217 mcall <- mc matchcall
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
218 quote: :tomatch {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
219 cur <- 0
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
220 count <- 0
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
221 n <- tomatch byte_length
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
222 orig <- tomatch
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
223 _match <- true
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
224 allBasic? <- true
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
225 yieldvals <- []
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
226 while: { _match && cur < n } do: {
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
227 res <- mcall
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
228 _match <- res matched?
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
229 if: _match {
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
230 count <- count + 1
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
231 //TODO: Use some kind of lightweight substring wrapper here
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
232 tomatch <- tomatch from: (res matchlen)
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
233 if: allBasic? {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
234 ifnot: (res basicYield?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
235 allBasic? <- false
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
236 if: cur > 0 {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
237 yieldvals <- (orig from: 0 withLength: cur) | yieldvals
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
238 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
239 yieldvals <- (res yield) | yieldvals
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
240 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
241 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
242 yieldvals <- (res yield) | yieldvals
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
243 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
244 allBasic? <- allBasic? && (res basicYield?)
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
245 cur <- cur + (res matchlen)
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
246 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
247 }
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
248 if: count >= min {
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
249 if: allBasic? {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
250 #{
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
251 matched? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
252 matchlen <- { cur }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
253 basicYield? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
254 yield <- { orig from: 0 withLength: cur }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
255 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
256 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
257 yieldvals <- yieldvals reverse
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
258 #{
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
259 matched? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
260 matchlen <- { cur }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
261 basicYield? <- { false }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
262 yield <- { yieldvals }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
263 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
264 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
265 } else: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
266 #{
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
267 matched? <- { false }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
268 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
269 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
270 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
271 } else: {
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
272 print: "#error Invalid nPlus macro call: " . (mc message) . "\n"
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
273 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
274 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
275
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
276 zeroPlus <- macro: :matchexpr {
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
277 _nPlus: matchexpr 0
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
278 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
279
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
280 onePlus <- macro: :matchexpr {
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
281 _nPlus: matchexpr 1
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
282 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
283
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
284 matchOne <- macro: :options {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
285 options <- (options value) map: :option {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
286 _makeMatchCall: option
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
287 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
288 body <- options foldr: (quote: #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
289 matched? <- { false }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
290 }) with: :acc el {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
291 if: (el valid?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
292 mcall <- el matchcall
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
293 quote: (ifmatch: mcall else: { acc })
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
294 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
295 print: "#error Invalid matchOne macro call: " . (el message) . "\n"
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
296 acc
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
297 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
298 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
299 quote: :tomatch {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
300 body
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
301 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
302 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
303
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
304 match <- macro: :matchexpr {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
305 mc <- _makeMatchCall: matchexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
306 if: (mc valid?) {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
307 mcall <- mc matchcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
308 quote: :tomatch {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
309 mcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
310 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
311 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
312 print: "#error Invalid macth macro call: " . (mc message) . "\n"
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
313 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
314 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
315
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
316 match:yield <- macro: :matchexpr :ylambda {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
317 mc <- _makeMatchCall: matchexpr
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
318 if: (mc valid?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
319 mcall <- mc matchcall
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
320 quote: :tomatch {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
321 res <- mcall
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
322 if: (res matched?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
323 #{
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
324 matched? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
325 matchlen <- { res matchlen }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
326 basicYield? <- { false }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
327 yield <- ylambda
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
328 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
329 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
330 res
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
331 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
332 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
333 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
334 print: "#error Invalid macth:yield macro call: " . (mc message) . "\n"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
335 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
336 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
337
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
338 match:where:yield <- macro: :matchexpr :whereclause :ylambda {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
339 syms <- []
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
340 withwhere <- (whereclause expressions) fold: (quote: :tomatch {}) with: :acc el {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
341
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
342 if: (el nodeType) = "assignment" {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
343 valassign <- quote: (val <- false)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
344 valsym <- (valassign) symbol
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
345 valsym <- valsym name!: (valsym name) . ((el symbol) name)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
346 valassign <- valassign symbol!: valsym
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
347 acc addExpression: valassign
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
348
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
349 matchassign <- quote: (hasmatch <- false)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
350 matchsym <- (matchassign) symbol
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
351 matchsym <- matchsym name!: (matchsym name) . ((el symbol) name)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
352 matchassign <- matchassign symbol!: matchsym
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
353 acc addExpression: matchassign
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
354
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
355 mc <- _makeMatchCall: (el expression)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
356
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
357 if: (mc valid?) {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
358 mcall <- mc matchcall
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
359 matchfun <- quote: :tomatch {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
360 if: matchsym {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
361 if: valsym = tomatch {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
362 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
363 matched? <- { true }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
364 matchlen <- { valsym length }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
365 basicYield? <- { true } //TODO: Check if this is correct
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
366 yield <- { valsym }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
367 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
368 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
369 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
370 matched? <- { false }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
371 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
372 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
373 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
374 mr <- mcall
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
375 if: (mr matched?) {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
376 matchsym <- true
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
377 valsym <- (mr yield)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
378 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
379 mr
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
380 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
381 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
382 acc <- acc addExpression: (el expression!: matchfun)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
383 syms <- list node: #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
384 orig <- el symbol
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
385 matchval <- valsym
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
386 } withTail: syms
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
387 acc
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
388 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
389 print: "#error " . ((el symbol) name) . " does not have a valid match expression: " . (mc message) . "\n"
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
390 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
391
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
392 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
393 print: "#error Nodes of type " . (el nodeType) . " are not allowed in match where clauses\n"
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
394 acc
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
395 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
396 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
397 mcMain <- _makeMatchCall: matchexpr
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
398 if: (mcMain valid?) {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
399 mcall <- mcMain matchcall
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
400 withwhere addExpression: (quote: (matchres <- mcall))
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
401 successLambda <- quote: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
402 //Extra assignments will be added here
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
403 mlen <- matchres matchlen
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
404 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
405 matched? <- { true }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
406 matchlen <- { mlen }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
407 basicYield? <- { false }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
408 yield <- ylambda
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
409 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
410 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
411 sucexp <- syms fold: (successLambda expressions) with: :acc el {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
412 lsym <- el orig
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
413 rsym <- el matchval
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
414 (quote: (lsym <- rsym)) | acc
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
415 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
416 successLambda <- successLambda expressions!: sucexp
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
417 withwhere addExpression: (quote: (if: (matchres matched?) successLambda else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
418 matchres
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
419 }))
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
420 withwhere
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
421 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
422 print: "#error Error in main match expression of match:where:yield: " . (mcMain message) . "\n"
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
423 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
424 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
425
225
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
426 binaryOps:withHigherPrec <- macro: :oplist :higher {
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
427 quote: (match: Left . Pieces where: {
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
428 Left <- match: higher
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
429 Pieces <- zeroPlus: (match: hws . Op . Right where: {
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
430 Op <- matchOne: oplist
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
431 Right <- 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
432 } yield: {
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
433 #{
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
434 op <- Op
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
435 right <- Right
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
436 }
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
437 })
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
438 } yield: {
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
439 _processOpPieces: Left Pieces
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
440 })
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
441 }
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
442
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
443 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
444 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
445
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
446 //TODO: Implement operator expressions
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
447 opexpr <- match: addsub
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
448
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
449 _alpha <- charClass: "a-zA-Z"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
450 alpha <- zeroPlus: _alpha
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
451 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
452
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
453 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
454
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
455 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
456 (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
457 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
458 ])
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
459
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
460 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
461 (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
462 "//" . (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
463 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
464 ])
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
465
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
466 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
467 (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
468 (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
469 (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
470 (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
471 (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
472 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
473
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
474 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
475 Chars <- zeroPlus: (matchOne: [
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
476 (charClass: "^\"\\")
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
477 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
478 ])
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
479 } 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
480 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
481 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
482
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
483 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
484 (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
485 (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
486 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
487
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
488 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
489 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
490 (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
491 (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
492 (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
493 (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
494 (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
495 (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
496 (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
497 (match: "9" yield: {9i64})
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
498 ]
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
499
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
500 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
501 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
502 (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
503 (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
504 (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
505 (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
506 (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
507 (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
508 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
509
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
510 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
511 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
512 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
513 (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
514 ""
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
515 ]
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
516 } yield: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
517 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
518 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
519 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
520 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
521 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
522 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
523 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
524 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
525 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
526 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
527 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
528 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
529 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
530 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
531 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
532 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
533 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
534 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
535 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
536 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
537 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
538 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
539 "1"
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
540 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
541 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
542 })
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
543 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
544 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
545 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
546 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
547 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
548 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
549 }
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
550 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
551 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
552
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
553 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
554 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
555 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
556 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
557 (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
558 ""
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
559 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
560 } 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
561 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
562 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
563 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
564 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
565 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
566 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
567 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
568 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
569 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
570 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
571 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
572 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
573 print: (Suffix from: 1) . "\n"
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
574 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
575 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
576 #{
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
577 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
578 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
579 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
580 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
581 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
582 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
583 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
584 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
585 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
586 }
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
587 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
588 }
a1a80af71b05 Implement 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
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
590 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
591 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
592 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
593 (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
594 ""
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
595 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
596 } 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
597 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
598 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
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 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
601 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
602 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
603 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
604 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
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 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
607 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
608 #{
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
609 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
610 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
611 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
612 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
613 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
614 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
615 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
616 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
617 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
618 }
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 }
a1a80af71b05 Implement 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 }
a1a80af71b05 Implement 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
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
622 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
623 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
624 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
625 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
626 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
627 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
628 name
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
629 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
630 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
631 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
632
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
633 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
634 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
635 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
636 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
637 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
638 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
639 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
640 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
641
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
642 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
643 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
644 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
645 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
646 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
647 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
648 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
649 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
650 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
651 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
652 ]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
653
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
654 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
655 Initial <- match: namepart
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
656 Parts <- onePlus: argpart
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
657 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
658 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
659 name <- ""
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
660 args <- []
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
661 } 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
662 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
663 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
664 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
665 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
666 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
667 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
668 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
669
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
670 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
671 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
672 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
673 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
674 str <- ""
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
675 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
676 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
677 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
678 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
679 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
680 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
681 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
682 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
683 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
684 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
685 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
686 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
687 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
688 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
689
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
690 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
691 Receiver <- match: opexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
692 Rest <- matchOne: [funcall (
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
693 match: Name where: { Name <- match: symexpr } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
694 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
695 name <- 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
696 args <- []
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
697 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
698 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
699 )]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
700 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
701 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
702 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
703 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
704 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
705 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
706 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
707 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
708 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
709 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
710 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
711 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
712 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
713 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
714 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
715 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
716 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
717 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
718 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
719 }
223
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
720 _processOpPieces <- :Left Pieces {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
721 if: (Pieces length) > 0 {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
722 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
723 #{
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
724 left <- acc
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
725 op <- piece op
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
726 right <- piece right
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
727 string <- {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
728 (string: left) . " " . op . " " . right
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
729 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
730 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
731 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
732 } else: {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
733 Left
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
734 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
735 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
736
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
737 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
738 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
739 funcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
740 methcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
741 opexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
742 ]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
743 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
744 Expr
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
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
747 assignment <- match: ws . Symbol . hws . "<-" . Expr where: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
748 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
749 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
750 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
751 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
752 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
753 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
754 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
755 (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
756 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
757 }
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 object <- match: "#{" . ws . Messages . "}" where: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
761 Messages <- zeroPlus: assignment
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
762 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
763 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
764 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
765 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
766 "#{\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
767 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
768 }) 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
769 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
770 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
771 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
772
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
773 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
774 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
775 hexlit
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
776 binary
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
777 decimal
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
778 symexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
779 object
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 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
782 Lit
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
783 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
784
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
785 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
786 res <- matchfun: val
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
787 if: (res matched?) {
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
788 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
789 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
790 } 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
791 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
792 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
793 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
794
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
795 main <- {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
796 cmatch <- alpha: "czx0123"
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
797 zeromatch <- alpha: "01234"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
798 if: (cmatch matched?) {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
799 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
800 } else: {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
801 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
802 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
803 if: (zeromatch matched?) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
804 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
805 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
806 print: "0123 didn't match\n"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
807 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
808 zeromatchanum <- alphaNum: "01234"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
809 if: (zeromatchanum matched?) {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
810 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
811 } else: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
812 print: "01234 didn't match\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
813 }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
814 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
815 hwsmatch <- hws: stuff
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
816 if: (hwsmatch matched?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
817 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
818 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
819 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
820 }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
821 tmatch <- digit: "3"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
822 if: (tmatch matched?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
823 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
824 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
825 print: "3 did not match\n"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
826 }
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
827
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
828 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
829 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
830 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
831 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
832 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
833 testmatchintlit: "0b10101" :s {binary: s}
223
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
834 code <- "#{ foo <- 123\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}"
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
835 codem <- expr: code
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
836 if: (codem matched?) {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
837 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
838 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
839 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
840 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
841 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
842 }