annotate modules/parser.tp @ 212:32080f96c3a0

Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
author Mike Pavone <pavone@retrodev.com>
date Sat, 30 Nov 2013 15:05:24 -0800
parents 4b3b57f39f10
children e00a8bc6361b
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 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
19 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
20 } else: {
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 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
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 }
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 } else: {
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 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
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 }
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 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
33 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
34 matchres
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
35 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
36 elseblock:
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
37 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
38 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
39 _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
40 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
41 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
42 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
43 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
44 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
45 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
46 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
47 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
48 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
49 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
50 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
51 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
52 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
53 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
54 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
55 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
56 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
57 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
58 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
59 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
60 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
61 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
62 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
63 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
64 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
65 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
66 if: (lm matched?) {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
67 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
68 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
69 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
70 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
71 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
72 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
73 matchlen <- { total }
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 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
76 rm
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
77 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
78 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
79 lm
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
80 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
81 } tomatch)
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 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
85 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
86 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
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 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
89 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
90 #{
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
91 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
92 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
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 }
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 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
97 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
98 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 expandClass <- :chars {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 if: (chars length) > 0 {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 pos <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 inverted <- false
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 if: (chars byte: 0) = ("^" byte: 0) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 pos <- 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 inverted <- true
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 state_begin <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 state_normal <- 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 state_rangeend <- 2
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 state <- state_begin
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 out <- ""
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 while: { pos < (chars byte_length)} do: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 if: state = state_begin {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 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
115 state <- state_normal
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 if: state = state_normal {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 if: (chars byte: pos) = ("-" byte: 0) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 state <- state_rangeend
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 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
122 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 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
125 rangeend <- chars byte: pos
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 if: rangeend < rangestart {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 tmp <- rangeend
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 rangeend <- rangestart
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 rangestart <- tmp
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 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
132 while: { rangestart <= rangeend } do: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 out <- out . (rangestart asStringChar)
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
134 rangestart <- rangestart + 1
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 state <- state_begin
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 pos <- pos + 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 if: inverted {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 old <- out
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 out <- ""
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 cur <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 } else: {
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 <- 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
154 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
155 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
156 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
157 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
158 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
159 cur <- cur + 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
160 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
161 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
162 out
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
163 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
164 ""
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
165 }
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 charClass <- macro: :rawchars {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 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
169 orig <- chars
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 chars <- expandClass: chars
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 //TODO: Use a more sophisticated approach for large classes
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 quote: :tomatch {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 if: (tomatch isString?) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 check <- 0
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
176 nomatch <- true
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
177 while: { nomatch && check < (chars byte_length) } do: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
178 if: (tomatch byte: 0) = (chars byte: check) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
179 nomatch <- false
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
180 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 check <- check + 1
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 if: nomatch {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 matched? <- { false }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
186 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 matched? <- { true }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 matchlen <- { 1 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 #{
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 matched? <- { false }
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 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 } 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
200 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
201 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
202 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
203
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
204 zeroPlus <- macro: :matchexpr {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
205 funexpr <- false
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
206 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
207 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
208 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
209 mcall <- mc matchcall
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
210 quote: :tomatch {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
211 cur <- 0
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
212 n <- tomatch byte_length
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
213 orig <- tomatch
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
214 match <- true
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
215 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
216 res <- mcall
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
217 match <- res matched?
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
218 if: match {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
219 //TODO: Use some kind of lightweight substring wrapper here
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
220 tomatch <- tomatch from: (res matchlen)
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
221 cur <- cur + (res matchlen)
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
222 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
223 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
224 if: cur > 0 {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
225 #{
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
226 matched? <- { true }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
227 matchlen <- { cur }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
228 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
229 } else: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
230 #{
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
231 matched? <- { false }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
232 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
233 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
234 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
235 } 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
236 print: "#error Invalid zeroPlus macro call: " . (mc 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
237 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
238 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
239
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
240 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
241 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
242 _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
243 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
244 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
245 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
246 }) 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
247 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
248 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
249 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
250 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
251 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
252 acc
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
253 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
254 }
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
255 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
256 body
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
257 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
258 }
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
259
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
260
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
261 _alpha <- charClass: "a-zA-Z"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
262 alpha <- zeroPlus: _alpha
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
263 alphaNum <- zeroPlus: (charClass: "a-zA-Z0-9")
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
264 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
265 (charClass: " \t")
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
266 "/*" . (zeroPlus: (matchOne: [(charClass: "^*") "*" . (charClass: "^/")])) . "*/"
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
267 ])
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
268
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
269
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
270 main <- {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
271 cmatch <- alpha: "czx0123"
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
272 zeromatch <- alpha: "01234"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 if: (cmatch matched?) {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
274 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
275 } else: {
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
276 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
277 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278 if: (zeromatch matched?) {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 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
280 } else: {
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
281 print: "0123 didn't match\n"
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
282 }
209
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
283 zeromatchanum <- alphaNum: "01234"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
284 if: (zeromatchanum matched?) {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
285 print: "01234 matched with length " . (zeromatchanum matchlen) . "\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
286 } else: {
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
287 print: "01234 didn't match\n"
4b3b57f39f10 Implement zeroPlus macro
Michael Pavone <pavone@retrodev.com>
parents: 208
diff changeset
288 }
212
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
289 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
290 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
291 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
292 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
293 } else: {
32080f96c3a0 Implement matchOne matching macro. Support more AST node types in zeroPlus matching macro.
Mike Pavone <pavone@retrodev.com>
parents: 209
diff changeset
294 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
295 }
208
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296 }
a1b4a2bc8d72 Initial work on pattern match macrosfor the new parser
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 }