annotate modules/parser.tp @ 237:dae093baf36c

Optimized implementation of character classes
author Mike Pavone <pavone@retrodev.com>
date Sun, 05 Jan 2014 17:00:33 -0800
parents c463a891ccd3
children 6aab8a5a2be9
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
237
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
177 charmap <- ""
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
178 char <- 0
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
179 while: { char < 256 } do: {
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
180 mchar <- 0
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
181 found <- false
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
182 while: { mchar < (chars byte_length)} do: {
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
183 if: (chars byte: mchar) = char {
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
184 found <- true
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
185 mchar <- chars byte_length
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
186 }
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
187 mchar <- mchar + 1
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
188 }
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
189 charmap <- charmap . (if: found { "t" } else: { "f" })
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
190 char <- char + 1
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
191 }
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
192 t <- "t" byte: 0
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 quote: :tomatch {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 if: (tomatch isString?) {
237
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
195 if: (charmap byte: (tomatch byte: 0)) = t {
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 matched? <- { true }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 matchlen <- { 1 }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
199 basicYield? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
200 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
201 }
237
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
202 } else: {
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
203 #{
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
204 matched? <- { false }
dae093baf36c Optimized implementation of character classes
Mike Pavone <pavone@retrodev.com>
parents: 236
diff changeset
205 }
208
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: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
208 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
209 matched? <- { false }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
211 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 } 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
214 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
215 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
217
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
218 _nPlus <- :matchexpr min {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
219 funexpr <- false
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
220 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
221 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
222 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
223 mcall <- mc matchcall
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
224 quote: :tomatch {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
225 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
226 count <- 0
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
227 n <- tomatch byte_length
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
228 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
229 _match <- true
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
230 allBasic? <- true
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
231 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
232 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
233 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
234 _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
235 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
236 count <- count + 1
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
237 //TODO: Use some kind of lightweight substring wrapper here
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
238 tomatch <- tomatch from: (res matchlen)
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
239 if: allBasic? {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
240 ifnot: (res basicYield?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
241 allBasic? <- false
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
242 if: cur > 0 {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
243 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
244 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
245 yieldvals <- (res yield) | yieldvals
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
246 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
247 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
248 yieldvals <- (res yield) | yieldvals
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
249 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
250 allBasic? <- allBasic? && (res basicYield?)
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
251 cur <- cur + (res matchlen)
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
252 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
253 }
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
254 if: count >= min {
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
255 if: allBasic? {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
256 #{
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
257 matched? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
258 matchlen <- { cur }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
259 basicYield? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
260 yield <- { orig from: 0 withLength: cur }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
261 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
262 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
263 yieldvals <- yieldvals reverse
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
264 #{
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
265 matched? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
266 matchlen <- { cur }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
267 basicYield? <- { false }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
268 yield <- { yieldvals }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
269 }
209
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: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
272 #{
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
273 matched? <- { false }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
274 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
275 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
276 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
277 } 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
278 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
279 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
280 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
281
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
282 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
283 _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
284 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
285
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
286 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
287 _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
288 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
289
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
290 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
291 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
292 _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
293 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
294 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
295 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
296 }) 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
297 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
298 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
299 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
300 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
301 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
302 acc
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
303 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
304 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
305 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
306 body
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
307 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
308 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
309
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
310 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
311 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
312 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
313 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
314 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
315 mcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
316 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
317 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
318 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
319 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
320 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
321
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
322 match:yield <- macro: :matchexpr :ylambda {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
323 mc <- _makeMatchCall: matchexpr
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
324 if: (mc valid?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
325 mcall <- mc matchcall
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
326 quote: :tomatch {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
327 res <- mcall
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
328 if: (res matched?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
329 #{
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
330 matched? <- { true }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
331 matchlen <- { res matchlen }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
332 basicYield? <- { false }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
333 yield <- ylambda
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
334 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
335 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
336 res
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
337 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
338 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
339 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
340 print: "#error Invalid macth:yield macro call: " . (mc message) . "\n"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
341 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
342 }
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
343
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
344 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
345 syms <- []
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
346 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
347
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
348 if: (el nodeType) = "assignment" {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
349 valassign <- quote: (val <- false)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
350 valsym <- (valassign) symbol
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
351 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
352 valassign <- valassign symbol!: valsym
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
353 acc addExpression: valassign
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 matchassign <- quote: (hasmatch <- false)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
356 matchsym <- (matchassign) symbol
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
357 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
358 matchassign <- matchassign symbol!: matchsym
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
359 acc addExpression: matchassign
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
360
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
361 mc <- _makeMatchCall: (el expression)
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 if: (mc valid?) {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
364 mcall <- mc matchcall
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
365 matchfun <- quote: :tomatch {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
366 if: matchsym {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
367 if: valsym = tomatch {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
368 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
369 matched? <- { true }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
370 matchlen <- { valsym length }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
371 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
372 yield <- { valsym }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
373 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
374 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
375 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
376 matched? <- { false }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
377 }
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 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
380 mr <- mcall
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
381 if: (mr matched?) {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
382 matchsym <- true
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
383 valsym <- (mr yield)
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
384 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
385 mr
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
386 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
387 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
388 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
389 syms <- list node: #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
390 orig <- el symbol
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
391 matchval <- valsym
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
392 } withTail: syms
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
393 acc
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
394 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
395 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
396 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
397
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
398 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
399 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
400 acc
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
401 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
402 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
403 mcMain <- _makeMatchCall: matchexpr
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
404 if: (mcMain valid?) {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
405 mcall <- mcMain matchcall
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
406 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
407 successLambda <- quote: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
408 //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
409 mlen <- matchres matchlen
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 matched? <- { true }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
412 matchlen <- { mlen }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
413 basicYield? <- { false }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
414 yield <- ylambda
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 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
417 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
418 lsym <- el orig
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
419 rsym <- el matchval
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
420 (quote: (lsym <- rsym)) | acc
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
421 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
422 successLambda <- successLambda expressions!: sucexp
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
423 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
424 matchres
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
425 }))
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
426 withwhere
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
427 } else: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
428 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
429 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
430 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
431
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
432 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
433 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
434 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
435 Pieces <- zeroPlus: (match: hws . Op . Right where: {
230
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
436 Op <- matchOne: oplist
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
437 Right <- match: higher
225
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
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 #{
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 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
441 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
442 }
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
443 })
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
444 } 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
445 _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
446 })
262f5ae1bb1b Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
Michael Pavone <pavone@retrodev.com>
parents: 223
diff changeset
447 }
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
448
226
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
449 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
450 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
451 maybecons <- matchOne: [
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
452 consop
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
453 addsub
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
454 ]
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
455 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
456 Left <- match: addsub
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
457 Right <- match: maybecons
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
458 } yield: {
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
459 #{
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
460 left <- Left
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
461 op <- "|"
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
462 right <- Right
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
463 string <- {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
464 (string: left) . " " . op . " " . right
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
465 }
226
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
466 }
6055f56d0e45 Implement all the binary operators except and/or/xor in grammar
Michael Pavone <pavone@retrodev.com>
parents: 225
diff changeset
467 }
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
468 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
469 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
470
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
471 //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
472
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
473
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
474 _alpha <- charClass: "a-zA-Z"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
475 alpha <- zeroPlus: _alpha
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
476 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
477
a1a80af71b05 Implement 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 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
479
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 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
481 (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
482 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
483 ])
a1a80af71b05 Implement 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
a1a80af71b05 Implement 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 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
486 (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
487 "//" . (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
488 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
489 ])
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
490
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
491 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
492 (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
493 (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
494 (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
495 (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
496 (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
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 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
500 Chars <- zeroPlus: (matchOne: [
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
501 match: Reg where: { Reg <- charClass: "^\"\\" } yield: { Reg }
220
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
502 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
503 ])
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
504 } yield: {
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
505 if: (Chars length) = 0 {
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
506 Chars <- []
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
507 }
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
508 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
509 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
510
a1a80af71b05 Implement 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 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
512 (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
513 (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
514 ]
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
515
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
516 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
517 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
518 (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
519 (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
520 (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
521 (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
522 (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
523 (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
524 (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
525 (match: "9" yield: {9i64})
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
526 ]
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
527
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
528 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
529 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
530 (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
531 (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
532 (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
533 (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
534 (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
535 (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
536 ]
a1a80af71b05 Implement 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
a1a80af71b05 Implement 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 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
539 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
540 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
541 (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
542 ""
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
543 ]
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
544 } yield: {
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
545 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
546 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
547 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
548 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
549 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
550 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
551 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
552 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
553 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
554 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
555 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
556 #{
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
557 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
558 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
559 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
560 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
561 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
562 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
563 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
564 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
565 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
566 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
567 "1"
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
568 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
569 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
570 })
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
571 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
572 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
573 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
574 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
575 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
576 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
577 }
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
578 }
a1a80af71b05 Implement 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
a1a80af71b05 Implement 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 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
582 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
583 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
584 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
585 (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
586 ""
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
587 ]
a1a80af71b05 Implement 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 } yield: {
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
589 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
590 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
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 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
593 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
594 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
595 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
596 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
597 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
598 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
599 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
600 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
601 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
602 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
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 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
606 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
607 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
608 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
609 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
610 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
611 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
612 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
613 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
614 }
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
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 }
a1a80af71b05 Implement 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
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
618 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
619 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
620 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
621 (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
622 ""
a1a80af71b05 Implement 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 } 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
625 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
626 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
627 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
628 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
629 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
630 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
631 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
632 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
633 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
634 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
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 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
638 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
639 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
640 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
641 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
642 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
643 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
644 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
645 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
646 }
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
647 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
648 }
a1a80af71b05 Implement onePlus macro. Fix some bugs in the other matching macros. Implement integer literal parsing rules.
Michael Pavone <pavone@retrodev.com>
parents: 218
diff changeset
649
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
650 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
651 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
652 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
653 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
654 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
655 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
656 name
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 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
659 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
660
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
661 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
662 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
663 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
664 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
665 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
666 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
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 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
671 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 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
673 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
674 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
675 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
676 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
677 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
678 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
679 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
680 ]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
681
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
682 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
683 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
684 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
685 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
686 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
687 name <- ""
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 <- []
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
689 } 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
690 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
691 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
692 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
693 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
694 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
695 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
696 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
697
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
698 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
699 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
700 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
701 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
702 str <- ""
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
703 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
704 nameParts <- name splitOn: ":"
232
25b800094623 Fix string method of funcall nodes
Michael Pavone <pavone@retrodev.com>
parents: 231
diff changeset
705 foreach: nameParts :idx part {
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
706 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
707 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
708 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
709 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
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 }
235
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
712 while: { not: (curArgs empty?) } do: {
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
713 str <- str . " " . (curArgs value)
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
714 curArgs <- curArgs tail
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
715 }
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
716 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
717 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
718 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
719 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
720 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
721
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
722 unarymeth <- match: Receiver . hws . Method where: {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
723 Receiver <- match: opexpr
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
724 Method <- match: symexpr
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
725 } yield: {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
726 #{
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
727 receiver <- Receiver
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
728 name <- Method name
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
729 args <- []
234
370e03964239 Add string method to unarymeth AST node object
Michael Pavone <pavone@retrodev.com>
parents: 232
diff changeset
730 string <- {
370e03964239 Add string method to unarymeth AST node object
Michael Pavone <pavone@retrodev.com>
parents: 232
diff changeset
731 (string: receiver) . " " . name
370e03964239 Add string method to unarymeth AST node object
Michael Pavone <pavone@retrodev.com>
parents: 232
diff changeset
732 }
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
733 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
734 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
735
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
736 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
737 Receiver <- match: opexpr
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
738 Rest <- match: funcall
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
739 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
740 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
741 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
742 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
743 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
744 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
754 }
235
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
755 while: { not: (curArgs empty?) } do: {
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
756 str <- str . " " . (curArgs value)
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
757 curArgs <- curArgs tail
cc1260872322 Fix printing of function/method calls in parser module
Michael Pavone <pavone@retrodev.com>
parents: 234
diff changeset
758 }
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
759 str
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
760 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
761 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
762 }
223
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
763 _processOpPieces <- :Left Pieces {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
764 if: (Pieces length) > 0 {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
765 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
766 #{
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
767 left <- acc
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
768 op <- piece op
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
769 right <- piece right
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
770 string <- {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
771 (string: left) . " " . op . " " . right
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
772 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
773 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
774 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
775 } else: {
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
776 Left
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
777 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
778 }
25db1c7c7300 Added addition and multiplication precedence level operators to grammar
Michael Pavone <pavone@retrodev.com>
parents: 222
diff changeset
779
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
780 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
781 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
782 funcall
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
783 methcall
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
784 unarymeth
230
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
785 assignment
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
786 opexpr
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
787 ]
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
788 } yield: {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
789 Expr
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
790 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
791
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
792 lexpr <- match: (hws . Expr . ws) where: {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
793 Expr <- matchOne: [
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
794 funcall
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
795 methcall
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
796 opexpr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
797 ]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
798 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
799 Expr
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
800 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
801
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
802 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
803 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
804 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
805 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
806 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
807 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
808 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
809 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
810 (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
811 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
812 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
813 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
814
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
815 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
816 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
817 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
818 #{
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
819 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
820 string <- {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
821 "#{\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
822 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
823 }) 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
824 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
825 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
826 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
827
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
828 listlit <- match: "[" . ws . Els . "]" where: {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
829 Els <- zeroPlus: lexpr
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
830 } yield: {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
831 //Handle limitation of zeroPlus macro
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
832 if: (Els length) = 0 {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
833 Els <- []
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
834 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
835 #{
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
836 litval <- Els
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
837 string <- {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
838 "[\n\t". ((litval map: :el {
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
839 string: el
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
840 }) join: "\n\t") . "\n]"
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
841 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
842 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
843 }
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
844
228
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
845 arraylit <- match: "#[" . ws . Els . "]" where: {
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
846 Els <- zeroPlus: lexpr
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
847 } yield: {
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
848 //Handle limitation of zeroPlus macro
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
849 if: (Els length) = 0 {
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
850 Els <- []
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
851 }
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
852 #{
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
853 litval <- Els
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
854 string <- {
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
855 "#[\n\t". ((litval map: :el {
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
856 string: el
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
857 }) join: "\n\t") . "\n]"
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
858 }
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
859 }
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
860 }
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
861
230
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
862 argname <- match: hws . Pre . Initial . Rest where: {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
863 Pre <- matchOne: [":" ""]
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
864 Initial <- onePlus: (charClass: "a-zA-Z_!?@")
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
865 Rest <- zeroPlus: (charClass: "a-zA-Z_!?@0-9")
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
866 } yield: {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
867 Pre . Initial . Rest
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
868 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
869
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
870 lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
871 Arglist <- matchOne: [
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
872 match: ":" . First . Rest where: {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
873 First <- match: symexpr
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
874 Rest <- zeroPlus: argname
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
875 } yield: {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
876 if: (Rest length) = 0 {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
877 Rest <- []
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
878 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
879 ":" . (First name) | Rest
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
880 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
881 match: "" yield: { [] }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
882 ]
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
883 Exprs <- zeroPlus: expr
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
884 } yield: {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
885 if: (Exprs length) = 0 {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
886 Exprs <- []
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
887 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
888 #{
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
889 args <- Arglist
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
890 expressions <- Exprs
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
891 string <- {
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
892 (args join: " ") . "{\n\t" .
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
893 ((expressions map: :el { string: el }) join: "\n\t") .
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
894 "}"
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
895 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
896 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
897 }
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
898
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
899 parenexp <- match: "(" . ws . Expr . ws . ")" where: {
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
900 Expr <- match: expr
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
901 } yield: {
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
902 Expr
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
903 }
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
904
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
905 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
906 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
907 hexlit
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
908 binary
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
909 decimal
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
910 symexpr
230
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
911 lambda
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
912 object
227
8c16ef123aee Implement list literals in grammar
Michael Pavone <pavone@retrodev.com>
parents: 226
diff changeset
913 listlit
228
decdf28a8517 Implemented arrays in grammar
Michael Pavone <pavone@retrodev.com>
parents: 227
diff changeset
914 arraylit
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
915 string
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
916 parenexp
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
917 ]
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
918 } yield: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
919 Lit
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
920 }
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
921
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
922 top <- matchOne: [
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
923 object
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
924 lambda
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
925 ]
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
926
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
927 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
928 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
929 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
930 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
931 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
932 } 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
933 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
934 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
935 }
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
936
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
937 main <- :args {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
938 cmatch <- alpha: "czx0123"
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
939 zeromatch <- alpha: "01234"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
940 if: (cmatch matched?) {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
941 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
942 } else: {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
943 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
944 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
945 if: (zeromatch matched?) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
946 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
947 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
948 print: "0123 didn't match\n"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
949 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
950 zeromatchanum <- alphaNum: "01234"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
951 if: (zeromatchanum matched?) {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
952 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
953 } else: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
954 print: "01234 didn't match\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
955 }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
956 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
957 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
958 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
959 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
960 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
961 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
962 }
213
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
963 tmatch <- digit: "3"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
964 if: (tmatch matched?) {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
965 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
966 } else: {
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
967 print: "3 did not match\n"
e00a8bc6361b Implement match:yield macro
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
968 }
218
b799192e404b Implemented match:where:yield and fixed a bug in zeroPlus
Michael Pavone <pavone@retrodev.com>
parents: 213
diff changeset
969
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
970 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
971 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
972 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
973 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
974 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
975 testmatchintlit: "0b10101" :s {binary: s}
230
195f02ba349b Implement lambdas in grammar. Make assignments an expression in grammar.
Michael Pavone <pavone@retrodev.com>
parents: 228
diff changeset
976 code <- "#{ foo <- 123 > 0x42 && 42 < 104\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n quine <- 123 | [4 5 6 fiddle sticks]\n quizzle <- #[receiver meth: arg]\n blah <- :arg arg2 :arg3 { arg + arg2 + arg3 }}"
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
977 if: (args length) > 1 {
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
978 file <- os open: (args get: 1) (os O_RDONLY)
236
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
979 code <- ""
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
980 chunksize <- 1024
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
981 readsize <- chunksize
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
982 while: { readsize = chunksize} do: {
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
983 seg <- os read: file chunksize
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
984 code <- code . seg
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
985 readsize <- seg byte_length
c463a891ccd3 Support reading files larger than 1024 bytes in parser module
Michael Pavone <pavone@retrodev.com>
parents: 235
diff changeset
986 }
231
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
987 }
e48c74a7539e Fix string parsing in grammar and add it to the primlitsym rule. Add parentheses expressions. Allow parsing from a file.
Michael Pavone <pavone@retrodev.com>
parents: 230
diff changeset
988 codem <- top: code
222
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
989 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
990 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
991 } else: {
c6e321a538d4 Implemented more of the grammar. Dealt with some name conflicts along the way.
Michael Pavone <pavone@retrodev.com>
parents: 220
diff changeset
992 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
993 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
994 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
995 }