10 compile-symbols = List new
12 do-coke-lexer-test = false
13 do-words-lexer-test = false
14 do-lines-lexer-test = false
15 for arg in arguments tail
16 if arg starts-with: "--"
17 compile-symbols append: (arg substr: 2)
18 if arg == "--lex-test"
20 else if arg == "--test-coke-lexer"
21 do-coke-lexer-test = true
22 else if arg == "--test-words-lexer"
23 do-words-lexer-test = true
24 else if arg == "--test-lines-lexer"
25 do-lines-lexer-test = true
26 else if arg == "--verbose"
29 throw MessageException new: ("Unknown option: " + arg)
31 file-names append: arg
34 for arg in arguments tail tail
36 else if do-coke-lexer-test
37 for arg in arguments tail tail
39 else if do-words-lexer-test
40 for arg in arguments tail tail
42 else if do-lines-lexer-test
43 for arg in arguments tail tail
47 return-value = Compiler compile: compile-symbols
50 print-line: exception message
62 return the-compiler status-reporter
69 status-reporter report: message
71 status-reporter indent
73 status-reporter unindent
81 tuple = Tuple new: num-items
84 expr = Expression new: 1
88 class-fn with: value-1 with: value-2
89 expr = Expression new: 2
90 expr at: 0 put: value-1
91 expr at: 1 put: value-2
94 class-fn with: value-1 with: value-2 with: value-3
95 expr = Expression new: 3
96 expr at: 0 put: value-1
97 expr at: 1 put: value-2
98 expr at: 2 put: value-3
101 class-fn with: value-1 with: value-2 with: value-3 with: value-4
102 expr = Expression new: 4
103 expr at: 0 put: value-1
104 expr at: 1 put: value-2
105 expr at: 2 put: value-3
106 expr at: 3 put: value-4
110 with: value-1 with: value-2 with: value-3 with: value-4 with: value-5
111 expr = Expression new: 5
112 expr at: 0 put: value-1
113 expr at: 1 put: value-2
114 expr at: 2 put: value-3
115 expr at: 3 put: value-4
116 expr at: 4 put: value-5
120 tuple at: index put: value
123 return tuple at: index
126 return tuple iterator
129 return tuple num-items
134 reporter = the-compiler status-reporter
138 if num-items == 2 && (this at: 0) == 'quote'
140 if (value is-a: InternedString)
141 c = value first-character
142 if (c < `A`) || (c >= `{`) || (c == `[`) || (c == `]`)
143 # Special-case non-alpha symbols.
145 stream write: value string
146 stream write: "\" asSymbol]"
149 emit-value: value on: stream
154 else if num-items >= 3 && (this at: 0) == 'send' && --
155 ((this at: 1) is-a: Expression) && --
156 ((this at: 1) at: 0) == 'quote'
158 emit-value: (this at: 2) on: stream
160 emit-value: ((this at: 1) at: 1) on: stream
162 while index < num-items
164 emit-value: (this at: index) on: stream
176 emit-value: value on: stream
183 emit-value: value on: stream
184 if (value is-a: String) && !(value is-a: Symbol)
188 else if value is-a: Expression
191 stream write: value string
195 superclass Pepsi Expression
198 return super new: size asInteger
204 return super at: index asInteger
207 super at: index asInteger put: value
212 reporter = the-compiler status-reporter
216 if num-items == 2 && (this at: 0) == 'quote'
218 if (value is-a: Pepsi Symbol)
219 c = value string first-character
220 if (c < `A`) || (c >= `{`) || (c == `[`) || (c == `]`)
221 # Special-case non-alpha symbols.
223 stream write: value string
224 stream write: "\" asSymbol]"
227 emit-value: value on: stream
232 if num-items >= 3 && (this at: 0) == 'send' && --
233 ((this at: 1) is-a: Expression) && --
234 ((this at: 1) at: 0) == 'quote'
236 emit-value: (this at: 2) on: stream
238 emit-value: ((this at: 1) at: 1) on: stream
240 while index < num-items
242 emit-value: (this at: index) on: stream
249 while index < num-items
252 emit-value: (this at: index) on: stream
260 emit-value: value on: stream
261 if value is-a: String
265 else if value is-a: Expression
268 stream write: value string
279 return this string == string
282 return string first-character
288 return InternedString new: this
297 lexer = Compiler Lexer new: (File new: filename) contents
299 token = lexer next-token
301 if token text && !token text is-empty
305 if token type == 'eof'
308 print-line: "Error: " + exception message
311 test-coke-lexer: filename
314 for line in (File new: filename) contents lines
316 lexer = Compiler CokeLexer new: lines
318 expr = lexer next-expr
321 dump-expr: expr level: 0
324 print-line: "Error: " + exception message
327 dump-expr: expr level: level
328 print: (" " substr: 0 length: level)
329 if expr is-a: Expression
330 print-line: "Expression (" + expr num-items string + ")"
332 dump-expr: item level: level + 1
333 else if expr is-a: String
334 print-line: "\"" + expr + "\""
336 print-line: expr string
339 test-words-lexer: filename
341 for line in (File new: filename) contents lines
342 lexer = Compiler WordsLexer new: line
344 print-line: lexer next
346 print-line: "Error: " + exception message
349 test-lines-lexer: filename
351 lexer = Compiler LinesLexer new: (File new: filename) contents
353 dump-lines: lines level: 0
355 print-line: "Error: " + exception message
358 dump-lines: lines level: level
362 print-line: line text
364 dump-lines: line block level: level + 1
368 # Copyright 2007 Steve Folta. See the License file.