annotate modules/parser.tp @ 226:6055f56d0e45

Implement all the binary operators except and/or/xor in grammar
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 14:56:46 -0800
parents 262f5ae1bb1b
children 8c16ef123aee
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
226
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
443 opexpr <- binaryOps: ["&&" "||"] withHigherPrec: compare
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
444 compare <- binaryOps: ["<=" ">=" "<" ">" "=" "!="] withHigherPrec: maybecons
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
445 maybecons <- matchOne: [
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
446 consop
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
447 addsub
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
448 ]
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
449 consop <- match: Left . hws . "|" . Right where: {
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
450 Left <- match: addsub
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
451 Right <- match: maybecons
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
452 } yield: {
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
453 #{
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
454 left <- Left
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
455 op <- "|"
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
456 right <- Right
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
457 }
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
458 }
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
459 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
460 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
461
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
462 //TODO: Implement operator expressions
226
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
463
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
464
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
465 _alpha <- charClass: "a-zA-Z"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
466 alpha <- zeroPlus: _alpha
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
467 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
468
a1a80af71b05 Implement 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 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
470
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
471 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
472 (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
473 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
474 ])
a1a80af71b05 Implement 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
a1a80af71b05 Implement 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 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
477 (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
478 "//" . (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
479 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
480 ])
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
481
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
482 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
483 (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
484 (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
485 (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
486 (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
487 (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
488 ]
a1a80af71b05 Implement 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
a1a80af71b05 Implement 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 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
491 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
492 (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
493 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
494 ])
a1a80af71b05 Implement 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 } 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
496 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
497 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
498
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
499 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
500 (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
501 (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
502 ]
a1a80af71b05 Implement 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
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
504 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
505 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
506 (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
507 (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
508 (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
509 (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
510 (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
511 (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
512 (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
513 (match: "9" yield: {9i64})
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
514 ]
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
515
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
516 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
517 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
518 (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
519 (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
520 (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
521 (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
522 (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
523 (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
524 ]
a1a80af71b05 Implement 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 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
527 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
528 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
529 (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
530 ""
a1a80af71b05 Implement 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 ]
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
532 } yield: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
533 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
534 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
535 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
536 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
537 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
538 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
539 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
540 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
541 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
542 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
543 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
544 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
545 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
546 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
547 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
548 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
549 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
550 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
551 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
552 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
553 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
554 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
555 "1"
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
556 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
557 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
558 })
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
559 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
560 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
561 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
562 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
563 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
564 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
565 }
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
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 }
a1a80af71b05 Implement 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
a1a80af71b05 Implement 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 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
570 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
571 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
572 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
573 (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
574 ""
a1a80af71b05 Implement 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 } 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
577 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
578 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
579 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
580 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
581 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
582 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
583 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
584 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
585 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
586 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
587 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
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 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
590 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
591 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
592 #{
a1a80af71b05 Implement 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 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
594 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
595 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
596 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
597 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
598 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
599 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
600 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
601 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
602 }
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
603 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
604 }
a1a80af71b05 Implement 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
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
606 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
607 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
608 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
609 (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
610 ""
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
611 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
612 } 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
613 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
614 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
615 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
616 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
617 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
618 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
619 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
620 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
621 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
622 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
623 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
624 #{
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
625 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
626 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
627 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
628 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
629 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
630 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
631 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
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 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
634 }
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
635 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
636 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
637
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
638 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
639 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
640 } yield: {
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 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
643 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
644 name
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
645 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
646 }
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
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
649 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
650 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
651 } yield: {
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 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
654 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
655 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
656 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
657
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
658 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
659 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
660 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
661 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
662 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
663 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
664 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
665 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
666 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
667 }
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 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
671 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
672 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
673 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
674 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
675 name <- ""
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
676 args <- []
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
677 } 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
678 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
679 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
680 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
681 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
682 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
683 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
684 }
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 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
688 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
689 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
690 str <- ""
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
691 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
692 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
693 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
694 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
695 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
696 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
697 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
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 str
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 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
703 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
704 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
705
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
706 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
707 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
708 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
709 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
710 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
711 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
712 args <- []
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
713 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
714 }
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 } yield: {
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 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
719 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
720 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
721 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
722 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
723 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
724 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
725 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
726 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
727 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
728 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
729 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
730 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
731 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
732 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
733 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
734 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
735 }
223
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
736 _processOpPieces <- :Left Pieces {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
737 if: (Pieces length) > 0 {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
738 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
739 #{
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
740 left <- acc
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
741 op <- piece op
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
742 right <- piece right
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
743 string <- {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
744 (string: left) . " " . op . " " . right
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
745 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
746 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
747 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
748 } else: {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
749 Left
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
750 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
751 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
752
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
753 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
754 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
755 funcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
756 methcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
757 opexpr
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 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
760 Expr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
761 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
762
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
763 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
764 Symbol <- match: symexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
765 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
766 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
767 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
768 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
769 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
770 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
771 (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
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 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
774 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
775
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
776 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
777 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
778 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
779 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
780 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
781 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
782 "#{\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
783 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
784 }) 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
785 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
786 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
787 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
788
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
789 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
790 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
791 hexlit
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
792 binary
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
793 decimal
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
794 symexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
795 object
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
796 ]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
797 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
798 Lit
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
799 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
800
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
801 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
802 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
803 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
804 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
805 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
806 } 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
807 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
808 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
809 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
810
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
811 main <- {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
812 cmatch <- alpha: "czx0123"
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
813 zeromatch <- alpha: "01234"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
814 if: (cmatch matched?) {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
815 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
816 } else: {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
817 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
818 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
819 if: (zeromatch matched?) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
820 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
821 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
822 print: "0123 didn't match\n"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
823 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
824 zeromatchanum <- alphaNum: "01234"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
825 if: (zeromatchanum matched?) {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
826 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
827 } else: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
828 print: "01234 didn't match\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
829 }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
830 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
831 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
832 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
833 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
834 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
835 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
836 }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
837 tmatch <- digit: "3"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
838 if: (tmatch matched?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
839 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
840 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
841 print: "3 did not match\n"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
842 }
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
843
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
844 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
845 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
846 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
847 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
848 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
849 testmatchintlit: "0b10101" :s {binary: s}
226
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
850 code <- "#{ foo <- 123 > 0x42 && 42 < 104\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
851 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
852 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
853 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
854 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
855 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
856 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
857 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
858 }