|
1 "{ Package: 'stx:goodies/petitparser/compiler' }"! |
|
2 |
|
3 !Character methodsFor:'*petitcompiler'! |
|
4 |
|
5 ppcPrintable |
|
6 ^ self asInteger > 31 and: [ self asInteger < 127 ] |
|
7 ! ! |
|
8 |
|
9 !Object methodsFor:'*petitcompiler'! |
|
10 |
|
11 isInlinedMethod |
|
12 ^ false |
|
13 ! ! |
|
14 |
|
15 !PPActionParser methodsFor:'*petitcompiler'! |
|
16 |
|
17 asCompilerNode |
|
18 ^ PPCActionNode new |
|
19 name: self name; |
|
20 block: block; |
|
21 child: parser; |
|
22 yourself |
|
23 ! ! |
|
24 |
|
25 !PPActionParser methodsFor:'*petitcompiler'! |
|
26 |
|
27 compileWith: aPetitCompiler |
|
28 block isSymbol ifTrue: [ |
|
29 ^ aPetitCompiler compileSymbolBlock: block for: self |
|
30 ]. |
|
31 ^ aPetitCompiler compileBlock: block for: self |
|
32 ! ! |
|
33 |
|
34 !PPAndParser methodsFor:'*petitcompiler'! |
|
35 |
|
36 asCompilerNode |
|
37 ^ PPCAndNode new |
|
38 name: self name; |
|
39 child: parser; |
|
40 yourself |
|
41 ! ! |
|
42 |
|
43 !PPCharSetPredicate methodsFor:'*petitcompiler'! |
|
44 |
|
45 block |
|
46 ^ block |
|
47 ! ! |
|
48 |
|
49 !PPCharSetPredicate methodsFor:'*petitcompiler'! |
|
50 |
|
51 classification |
|
52 ^ classification |
|
53 ! ! |
|
54 |
|
55 !PPCharSetPredicate methodsFor:'*petitcompiler'! |
|
56 |
|
57 equals: anotherPredicate |
|
58 self == anotherPredicate ifTrue: [ ^ true ]. |
|
59 self class == anotherPredicate class ifFalse: [ ^ false ]. |
|
60 |
|
61 ^ classification = anotherPredicate classification. |
|
62 ! ! |
|
63 |
|
64 !PPChoiceParser methodsFor:'*petitcompiler'! |
|
65 |
|
66 asCompilerNode |
|
67 ^ PPCChoiceNode new |
|
68 name: self name; |
|
69 children: parsers; |
|
70 yourself |
|
71 ! ! |
|
72 |
|
73 !PPChoiceParser methodsFor:'*petitcompiler'! |
|
74 |
|
75 compileWith: aPetitCompiler |
|
76 ^ aPetitCompiler compileChoice: self |
|
77 ! ! |
|
78 |
|
79 !PPContext methodsFor:'*petitcompiler'! |
|
80 |
|
81 asCompiledParserContext |
|
82 ^ PPCContext new |
|
83 stream: stream; |
|
84 yourself |
|
85 |
|
86 ! ! |
|
87 |
|
88 !PPContext methodsFor:'*petitcompiler'! |
|
89 |
|
90 comment |
|
91 ^ self globalAt: #comment ifAbsent: [ nil ]. |
|
92 ! ! |
|
93 |
|
94 !PPContext methodsFor:'*petitcompiler'! |
|
95 |
|
96 comment: value |
|
97 ^ self globalAt: #comment put: value |
|
98 ! ! |
|
99 |
|
100 !PPContext methodsFor:'*petitcompiler'! |
|
101 |
|
102 compiledParser |
|
103 ^ self globalAt: #compiledParser |
|
104 ! ! |
|
105 |
|
106 !PPContext methodsFor:'*petitcompiler'! |
|
107 |
|
108 compiledParser: aPPParser |
|
109 ^ self globalAt: #compiledParser put: aPPParser |
|
110 ! ! |
|
111 |
|
112 !PPContext methodsFor:'*petitcompiler'! |
|
113 |
|
114 lastTokenResult |
|
115 ^ scanner lastResult |
|
116 ! ! |
|
117 |
|
118 !PPContext methodsFor:'*petitcompiler'! |
|
119 |
|
120 lwRemember |
|
121 ^ self position |
|
122 ! ! |
|
123 |
|
124 !PPContext methodsFor:'*petitcompiler'! |
|
125 |
|
126 lwRestore: position |
|
127 ^ self position: position |
|
128 ! ! |
|
129 |
|
130 !PPContext methodsFor:'*petitcompiler'! |
|
131 |
|
132 matchToken: id |
|
133 ^ scanner matchToken: id |
|
134 ! ! |
|
135 |
|
136 !PPContext methodsFor:'*petitcompiler'! |
|
137 |
|
138 nextToken |
|
139 scanner next |
|
140 ! ! |
|
141 |
|
142 !PPContext methodsFor:'*petitcompiler'! |
|
143 |
|
144 nextToken: id |
|
145 ^ scanner next: id |
|
146 ! ! |
|
147 |
|
148 !PPContext methodsFor:'*petitcompiler'! |
|
149 |
|
150 peek: anInteger |
|
151 ^ stream peek: anInteger |
|
152 ! ! |
|
153 |
|
154 !PPContext methodsFor:'*petitcompiler'! |
|
155 |
|
156 whitespace |
|
157 ^ self globalAt: #whitespace ifAbsent: [ nil ]. |
|
158 ! ! |
|
159 |
|
160 !PPContext methodsFor:'*petitcompiler'! |
|
161 |
|
162 whitespace: value |
|
163 ^ self globalAt: #whitespace put: value |
|
164 ! ! |
|
165 |
|
166 !PPDelegateParser methodsFor:'*petitcompiler'! |
|
167 |
|
168 asCompilerNode |
|
169 self class == PPDelegateParser ifTrue: [ |
|
170 ^ PPCForwardNode new |
|
171 name: self name; |
|
172 child: parser; |
|
173 yourself |
|
174 ]. |
|
175 ^ super asCompilerNode |
|
176 ! ! |
|
177 |
|
178 !PPDelegateParser methodsFor:'*petitcompiler'! |
|
179 |
|
180 compileWith: aPetitCompiler |
|
181 (self class == PPDelegateParser) ifTrue: [ |
|
182 (self name notNil and: [ parser name isNil ]) ifTrue: [ |
|
183 parser name: self name. |
|
184 ^ parser compileWith: aPetitCompiler. |
|
185 ]. |
|
186 |
|
187 (self name notNil and: [ parser name notNil ]) ifTrue: [ |
|
188 ^ aPetitCompiler compileDelegate: self. |
|
189 ] |
|
190 ]. |
|
191 ^ super compileWith: aPetitCompiler. |
|
192 ! ! |
|
193 |
|
194 !PPEpsilonParser methodsFor:'*petitcompiler'! |
|
195 |
|
196 asCompilerNode |
|
197 ^ PPCNilNode new |
|
198 ! ! |
|
199 |
|
200 !PPEpsilonParser methodsFor:'*petitcompiler'! |
|
201 |
|
202 compileWith: aPetitCompiler |
|
203 ^ aPetitCompiler compileNil |
|
204 ! ! |
|
205 |
|
206 !PPFailure methodsFor:'*petitcompiler'! |
|
207 |
|
208 context: aPPContext |
|
209 context := aPPContext |
|
210 ! ! |
|
211 |
|
212 !PPFailure methodsFor:'*petitcompiler'! |
|
213 |
|
214 message: text |
|
215 message := text |
|
216 ! ! |
|
217 |
|
218 !PPFailure methodsFor:'*petitcompiler'! |
|
219 |
|
220 position: anInteger |
|
221 position := anInteger |
|
222 ! ! |
|
223 |
|
224 !PPLiteralObjectParser methodsFor:'*petitcompiler'! |
|
225 |
|
226 asCompilerNode |
|
227 ^ PPCCharacterNode new |
|
228 character: literal; |
|
229 name: self name; |
|
230 yourself |
|
231 ! ! |
|
232 |
|
233 !PPLiteralObjectParser methodsFor:'*petitcompiler'! |
|
234 |
|
235 compileWith: aPetitCompiler |
|
236 ^ aPetitCompiler compileCharacter: literal. |
|
237 ! ! |
|
238 |
|
239 !PPLiteralObjectParser methodsFor:'*petitcompiler'! |
|
240 |
|
241 firstCharParser |
|
242 ^ self |
|
243 ! ! |
|
244 |
|
245 !PPLiteralParser methodsFor:'*petitcompiler'! |
|
246 |
|
247 id |
|
248 ^ literal printString |
|
249 ! ! |
|
250 |
|
251 !PPLiteralSequenceParser methodsFor:'*petitcompiler'! |
|
252 |
|
253 asCompilerNode |
|
254 ^ PPCLiteralNode new |
|
255 literal: literal; |
|
256 name: self name; |
|
257 yourself |
|
258 ! ! |
|
259 |
|
260 !PPLiteralSequenceParser methodsFor:'*petitcompiler'! |
|
261 |
|
262 compileWith: aPetitCompiler |
|
263 ^ aPetitCompiler compileLiteral: literal. |
|
264 ! ! |
|
265 |
|
266 !PPLiteralSequenceParser methodsFor:'*petitcompiler'! |
|
267 |
|
268 firstCharParser |
|
269 ^ literal first asParser |
|
270 ! ! |
|
271 |
|
272 !PPNotParser methodsFor:'*petitcompiler'! |
|
273 |
|
274 asCompilerNode |
|
275 ^ PPCNotNode new |
|
276 child: parser; |
|
277 name: self name; |
|
278 yourself |
|
279 ! ! |
|
280 |
|
281 !PPNotParser methodsFor:'*petitcompiler'! |
|
282 |
|
283 compileWith: aPetitCompiler |
|
284 ^ aPetitCompiler compileNot: self |
|
285 ! ! |
|
286 |
|
287 !PPNotParser methodsFor:'*petitcompiler'! |
|
288 |
|
289 firstCharParser |
|
290 ^ parser firstCharParser not |
|
291 ! ! |
|
292 |
|
293 !PPOptionalParser methodsFor:'*petitcompiler'! |
|
294 |
|
295 asCompilerNode |
|
296 ^ PPCOptionalNode new |
|
297 name: self name; |
|
298 child: parser; |
|
299 yourself |
|
300 |
|
301 " ^ super asCompilerNode " |
|
302 ! ! |
|
303 |
|
304 !PPOptionalParser methodsFor:'*petitcompiler'! |
|
305 |
|
306 compileWith: aPetitCompiler |
|
307 ^ aPetitCompiler compileOptional: self |
|
308 ! ! |
|
309 |
|
310 !PPParser methodsFor:'*petitcompiler'! |
|
311 |
|
312 asCompilerNode |
|
313 ^ PPCUnknownNode new |
|
314 parser: self; |
|
315 name: self name; |
|
316 yourself |
|
317 ! ! |
|
318 |
|
319 !PPParser methodsFor:'*petitcompiler'! |
|
320 |
|
321 asCompilerTree |
|
322 ^ self transform: [ :p | p asCompilerNode ] |
|
323 ! ! |
|
324 |
|
325 !PPParser methodsFor:'*petitcompiler'! |
|
326 |
|
327 bridge |
|
328 ^ self |
|
329 ! ! |
|
330 |
|
331 !PPParser methodsFor:'*petitcompiler'! |
|
332 |
|
333 cached |
|
334 "Faster way of memoizing --- it ignores context information, therefore it is not suitable for context-sensitive rules" |
|
335 |
|
336 ^ PPCachingParser on: self |
|
337 ! ! |
|
338 |
|
339 !PPParser methodsFor:'*petitcompiler'! |
|
340 |
|
341 compile |
|
342 ^ self compile: #PPGeneratedParser |
|
343 ! ! |
|
344 |
|
345 !PPParser methodsFor:'*petitcompiler'! |
|
346 |
|
347 compile: name |
|
348 ^ self compile: name parameters: #() |
|
349 ! ! |
|
350 |
|
351 !PPParser methodsFor:'*petitcompiler'! |
|
352 |
|
353 compile: name andParse: input |
|
354 ^ (self compile: name) parse: input |
|
355 ! ! |
|
356 |
|
357 !PPParser methodsFor:'*petitcompiler'! |
|
358 |
|
359 compile: name parameters: params |
|
360 ^ (PPCCompiler new parameters: params; compile: self as: name) new |
|
361 ! ! |
|
362 |
|
363 !PPParser methodsFor:'*petitcompiler'! |
|
364 |
|
365 compileWith: aPetitCompiler |
|
366 | compiled | |
|
367 self children do: [ :child | |
|
368 compiled := child compileWith: aPetitCompiler. |
|
369 self replace: child with: compiled bridge. |
|
370 ]. |
|
371 ^ aPetitCompiler compileBridgeTo: self |
|
372 ! ! |
|
373 |
|
374 !PPParser methodsFor:'*petitcompiler'! |
|
375 |
|
376 compileWithParameters: params |
|
377 ^ self compile: #PPGeneratedParser parameters: params |
|
378 ! ! |
|
379 |
|
380 !PPParser methodsFor:'*petitcompiler'! |
|
381 |
|
382 first |
|
383 first ifNil: [ |
|
384 first := self firstSet |
|
385 ]. |
|
386 ^ first |
|
387 ! ! |
|
388 |
|
389 !PPParser methodsFor:'*petitcompiler'! |
|
390 |
|
391 first: firstSet |
|
392 first := firstSet |
|
393 ! ! |
|
394 |
|
395 !PPParser methodsFor:'*petitcompiler'! |
|
396 |
|
397 firstSetSuchThat: block |
|
398 ^ self firstSetSuchThat: block into: (OrderedCollection new) openSet: IdentitySet new. |
|
399 ! ! |
|
400 |
|
401 !PPParser methodsFor:'*petitcompiler'! |
|
402 |
|
403 firstSetSuchThat: block into: aCollection openSet: aSet |
|
404 (aSet includes: self) ifTrue: [ ^ aCollection ]. |
|
405 aSet add: self. |
|
406 |
|
407 (block value: self) ifTrue: [aCollection add: self. ^ aCollection ]. |
|
408 self children do: [ :child | |
|
409 child firstSetSuchThat: block into: aCollection openSet: aSet |
|
410 ]. |
|
411 ^ aCollection |
|
412 ! ! |
|
413 |
|
414 !PPParser methodsFor:'*petitcompiler'! |
|
415 |
|
416 id |
|
417 self name ifNotNil: [ ^ self name ]. |
|
418 ^ self hash asString |
|
419 ! ! |
|
420 |
|
421 !PPParser methodsFor:'*petitcompiler'! |
|
422 |
|
423 isCompiled |
|
424 ^ false |
|
425 ! ! |
|
426 |
|
427 !PPParser methodsFor:'*petitcompiler'! |
|
428 |
|
429 isContextFree |
|
430 ^ self propertyAt: #isContextFree ifAbsentPut: |
|
431 [ self allParsers allSatisfy: [ :p | p isContextFreePrim ] ]. |
|
432 |
|
433 ! ! |
|
434 |
|
435 !PPParser methodsFor:'*petitcompiler'! |
|
436 |
|
437 isContextFreePrim |
|
438 ^ true |
|
439 ! ! |
|
440 |
|
441 !PPParser methodsFor:'*petitcompiler'! |
|
442 |
|
443 isToken |
|
444 ^ false |
|
445 ! ! |
|
446 |
|
447 !PPParser methodsFor:'*petitcompiler'! |
|
448 |
|
449 isTokenParser |
|
450 ^ false |
|
451 ! ! |
|
452 |
|
453 !PPParser methodsFor:'*petitcompiler'! |
|
454 |
|
455 optimize |
|
456 ^ self copy |
|
457 ! ! |
|
458 |
|
459 !PPParser methodsFor:'*petitcompiler'! |
|
460 |
|
461 optimized |
|
462 ^ self copy |
|
463 ! ! |
|
464 |
|
465 !PPParser methodsFor:'*petitcompiler'! |
|
466 |
|
467 trimmingToken |
|
468 | ws | |
|
469 ws := #space asParser star. |
|
470 ^ ((ws, (PPTokenParser on: self), ws) ==> #second) |
|
471 name: 'trimmingToken'; |
|
472 yourself |
|
473 ! ! |
|
474 |
|
475 !PPPluggableParser methodsFor:'*petitcompiler'! |
|
476 |
|
477 acceptsEpsilon |
|
478 ^ true |
|
479 ! ! |
|
480 |
|
481 !PPPluggableParser methodsFor:'*petitcompiler'! |
|
482 |
|
483 asCompilerNode |
|
484 ^ PPCPluggableNode new |
|
485 block: block; |
|
486 name: self name; |
|
487 yourself |
|
488 ! ! |
|
489 |
|
490 !PPPossessiveRepeatingParser methodsFor:'*petitcompiler'! |
|
491 |
|
492 asCompilerNode |
|
493 ((self min = 0) and: [ self max = SmallInteger maxVal ]) ifTrue: [ |
|
494 ^ PPCStarNode new |
|
495 name: self name; |
|
496 child: parser; |
|
497 yourself |
|
498 ]. |
|
499 |
|
500 ((self min = 1) and: [ self max = SmallInteger maxVal ]) ifTrue: [ |
|
501 ^ PPCPlusNode new |
|
502 name: self name; |
|
503 child: parser; |
|
504 yourself |
|
505 ]. |
|
506 ^ super asCompilerNode |
|
507 ! ! |
|
508 |
|
509 !PPPossessiveRepeatingParser methodsFor:'*petitcompiler'! |
|
510 |
|
511 compileWith: aPetitCompiler |
|
512 ((self min = 1) and: [ self max = SmallInteger maxVal ]) ifTrue: [ |
|
513 ^ aPetitCompiler compilePlus: self. |
|
514 ]. |
|
515 ((self min = 0) and: [ self max = SmallInteger maxVal ]) ifTrue: [ |
|
516 ^ aPetitCompiler compileStar: self. |
|
517 ]. |
|
518 |
|
519 ^ super compileWith: aPetitCompiler. |
|
520 ! ! |
|
521 |
|
522 !PPPossessiveRepeatingParser methodsFor:'*petitcompiler'! |
|
523 |
|
524 optimized |
|
525 ^ (PPFastPossessiveRepeatingParser on: parser) |
|
526 setMin: min; |
|
527 setMax: max; |
|
528 yourself |
|
529 ! ! |
|
530 |
|
531 !PPPredicateObjectParser methodsFor:'*petitcompiler'! |
|
532 |
|
533 asCompilerNode |
|
534 ^ PPCPredicateNode new |
|
535 name: self name; |
|
536 predicate: predicate; |
|
537 yourself |
|
538 ! ! |
|
539 |
|
540 !PPPredicateObjectParser methodsFor:'*petitcompiler'! |
|
541 |
|
542 compileWith: aPetitCompiler |
|
543 (predicateMessage = 'input expected') ifTrue: [ |
|
544 ^ aPetitCompiler compileAny. |
|
545 ]. |
|
546 ^ aPetitCompiler compilePredicate: predicate. |
|
547 ! ! |
|
548 |
|
549 !PPPredicateObjectParser methodsFor:'*petitcompiler'! |
|
550 |
|
551 firstCharParser |
|
552 ^ self |
|
553 ! ! |
|
554 |
|
555 !PPSequenceParser methodsFor:'*petitcompiler'! |
|
556 |
|
557 asCompilerNode |
|
558 ^ PPCSequenceNode new |
|
559 children: parsers; |
|
560 name: self name; |
|
561 yourself |
|
562 ! ! |
|
563 |
|
564 !PPSequenceParser methodsFor:'*petitcompiler'! |
|
565 |
|
566 checkFirst: context |
|
567 first isEmpty ifTrue: [ ^ true ]. |
|
568 |
|
569 first do: [ :elem | |
|
570 (context matchToken: elem id) ifTrue: [ ^ true ]. |
|
571 ]. |
|
572 ^ false |
|
573 ! ! |
|
574 |
|
575 !PPSequenceParser methodsFor:'*petitcompiler'! |
|
576 |
|
577 compileWith: aPetitCompiler |
|
578 ^ aPetitCompiler compileSequence: self. |
|
579 ! ! |
|
580 |
|
581 !PPSequenceParser methodsFor:'*petitcompiler'! |
|
582 |
|
583 firstSetSuchThat: block into: aCollection openSet: aSet |
|
584 (aSet includes: self) ifTrue: [ ^ aCollection ]. |
|
585 aSet add: self. |
|
586 |
|
587 (block value: self) ifTrue: [ aCollection add: self. ^ aCollection ]. |
|
588 |
|
589 self children do: [ :child | |
|
590 child firstSetSuchThat: block into: aCollection openSet: aSet. |
|
591 child acceptsEpsilon ifFalse: [ ^ aCollection ] |
|
592 ]. |
|
593 ^ aCollection |
|
594 ! ! |
|
595 |
|
596 !PPSequenceParser methodsFor:'*petitcompiler'! |
|
597 |
|
598 optimized |
|
599 ^ PPFastSequenceParser withAll: parsers |
|
600 ! ! |
|
601 |
|
602 !PPSmalltalkGrammar methodsFor:'*petitcompiler'! |
|
603 |
|
604 comment |
|
605 ^ $" asParser, $" asParser negate star, $" asParser. |
|
606 ! ! |
|
607 |
|
608 !PPSmalltalkGrammar methodsFor:'*petitcompiler'! |
|
609 |
|
610 updateContext: aPPContext |
|
611 super updateContext: aPPContext. |
|
612 " |
|
613 aPPContext globalAt: #comment ifAbsentPut: [ self comment ]. |
|
614 aPPContext globalAt: #whitespace ifAbsentPut: [ PPSmalltalkWhitespaceParser new ]. |
|
615 " |
|
616 ! ! |
|
617 |
|
618 !PPSmalltalkGrammar methodsFor:'*petitcompiler'! |
|
619 |
|
620 whitespace |
|
621 ^ #space asParser plus |
|
622 ! ! |
|
623 |
|
624 !PPSmalltalkGrammar methodsFor:'*petitcompiler'! |
|
625 |
|
626 whitespaceOld |
|
627 ^ #space asParser plus |
|
628 ! ! |
|
629 |
|
630 !PPSmalltalkGrammar methodsFor:'*petitcompiler'! |
|
631 |
|
632 whitespaceX |
|
633 whitespace ifNil: [ |
|
634 whitespace := PPSmalltalkWhitespaceParser new |
|
635 ]. |
|
636 ^ whitespace |
|
637 ! ! |
|
638 |
|
639 !PPSmalltalkTokenParser methodsFor:'*petitcompiler'! |
|
640 |
|
641 compileWith: aPetitCompiler |
|
642 |
|
643 ^ aPetitCompiler compileSmalltalkToken: self. |
|
644 ! ! |
|
645 |
|
646 !PPSmalltalkTokenParser methodsFor:'*petitcompiler'! |
|
647 |
|
648 parseOnX: aPPContext |
|
649 | memento comments token | |
|
650 |
|
651 memento := aPPContext remember. |
|
652 comments := self |
|
653 parseComments: #() |
|
654 on: aPPContext. |
|
655 token := super parseOn: aPPContext. |
|
656 token isPetitFailure ifTrue: [ |
|
657 aPPContext restore: memento. |
|
658 ^ token ]. |
|
659 comments := self |
|
660 parseComments: comments |
|
661 on: aPPContext. |
|
662 ^ token comments: comments |
|
663 ! ! |
|
664 |
|
665 !PPSmalltalkTokenParser methodsFor:'*petitcompiler'! |
|
666 |
|
667 updateContext: aPPContext |
|
668 aPPContext globalAt: #whitespace ifAbsentPut: PPSmalltalkWhitespaceParser new |
|
669 ! ! |
|
670 |
|
671 !PPSmalltalkTokenParser methodsFor:'*petitcompiler'! |
|
672 |
|
673 whitespace |
|
674 ^ PPSmalltalkWhitespaceParser new |
|
675 ! ! |
|
676 |
|
677 !PPSmalltalkWhitespaceParser methodsFor:'*petitcompiler'! |
|
678 |
|
679 acceptsEpsilon |
|
680 ^ true |
|
681 ! ! |
|
682 |
|
683 !PPSmalltalkWhitespaceParser methodsFor:'*petitcompiler'! |
|
684 |
|
685 acceptsEpsilonOpenSet: set |
|
686 ^ true |
|
687 ! ! |
|
688 |
|
689 !PPSmalltalkWhitespaceParser methodsFor:'*petitcompiler'! |
|
690 |
|
691 firstCharParser |
|
692 ^ PPFailingParser new |
|
693 ! ! |
|
694 |
|
695 !PPStream methodsFor:'*petitcompiler'! |
|
696 |
|
697 peek: anInteger |
|
698 | endPosition | |
|
699 endPosition := position + anInteger min: readLimit. |
|
700 ^ collection copyFrom: position+1 to: endPosition. |
|
701 ! ! |
|
702 |
|
703 !PPToken methodsFor:'*petitcompiler'! |
|
704 |
|
705 = anObject |
|
706 ^ self class = anObject class and: [ self inputValue = anObject inputValue ] |
|
707 ! ! |
|
708 |
|
709 !PPToken methodsFor:'*petitcompiler'! |
|
710 |
|
711 hash |
|
712 ^ self inputValue hash |
|
713 ! ! |
|
714 |
|
715 !PPToken methodsFor:'*petitcompiler'! |
|
716 |
|
717 isToken |
|
718 ^ true |
|
719 ! ! |
|
720 |
|
721 !PPTokenParser methodsFor:'*petitcompiler'! |
|
722 |
|
723 asCompilerNode |
|
724 ^ PPCTokenNode new |
|
725 name: self name; |
|
726 tokenClass: self tokenClass; |
|
727 child: parser; |
|
728 yourself |
|
729 ! ! |
|
730 |
|
731 !PPTokenParser methodsFor:'*petitcompiler'! |
|
732 |
|
733 displayName |
|
734 ^ 'TOKEN[', parser displayName, ']' |
|
735 ! ! |
|
736 |
|
737 !PPTokenParser methodsFor:'*petitcompiler'! |
|
738 |
|
739 firstSets: aFirstDictionary into: aSet |
|
740 "Or keep empty, if token is a terminal" |
|
741 ^ super firstSets: aFirstDictionary into: aSet |
|
742 ! ! |
|
743 |
|
744 !PPTokenParser methodsFor:'*petitcompiler'! |
|
745 |
|
746 id |
|
747 id ifNil: [ |
|
748 id := ('TOK[', parser id, ']') asSymbol |
|
749 ]. |
|
750 ^ id |
|
751 ! ! |
|
752 |
|
753 !PPTokenParser methodsFor:'*petitcompiler'! |
|
754 |
|
755 isFirstSetTerminal |
|
756 ^ false |
|
757 ! ! |
|
758 |
|
759 !PPTokenParser methodsFor:'*petitcompiler'! |
|
760 |
|
761 isTokenParser |
|
762 ^ true |
|
763 ! ! |
|
764 |
|
765 !PPTokenParser methodsFor:'*petitcompiler'! |
|
766 |
|
767 isUnique |
|
768 unique ifNil: [ |
|
769 unique := parser firstSet size = 1 and: [ (parser firstSet anyOne isKindOf: PPLiteralParser) ] |
|
770 ]. |
|
771 ^ unique |
|
772 ! ! |
|
773 |
|
774 !PPTokenParser methodsFor:'*petitcompiler'! |
|
775 |
|
776 optimize |
|
777 ^ self transform: [ :each | each optimized ] |
|
778 ! ! |
|
779 |
|
780 !PPTokenParser methodsFor:'*petitcompiler'! |
|
781 |
|
782 parseOnX: aPPContext |
|
783 (aPPContext matchToken: self id) ifTrue: [ |
|
784 ^ aPPContext nextToken: self id. |
|
785 ]. |
|
786 ^ PPFailure message: self id, ' not found' context: aPPContext. |
|
787 ! ! |
|
788 |
|
789 !PPTokenParser methodsFor:'*petitcompiler'! |
|
790 |
|
791 parser |
|
792 ^ parser |
|
793 ! ! |
|
794 |
|
795 !PPTokenParser methodsFor:'*petitcompiler'! |
|
796 |
|
797 startsWith: aCharacter |
|
798 self first do: [:first | (first startsWith: aCharacter) ifTrue: [ ^ true ] ]. |
|
799 ^ false |
|
800 ! ! |
|
801 |
|
802 !PPTokenParser methodsFor:'*petitcompiler'! |
|
803 |
|
804 whitespace |
|
805 ^ self class whitespace |
|
806 ! ! |
|
807 |
|
808 !PPTrimmingParser methodsFor:'*petitcompiler'! |
|
809 |
|
810 asCompilerNode |
|
811 ^ PPCTrimNode new |
|
812 child: parser; |
|
813 name: self name; |
|
814 yourself |
|
815 ! ! |
|
816 |
|
817 !PPTrimmingParser methodsFor:'*petitcompiler'! |
|
818 |
|
819 compileWith: aPetitCompiler |
|
820 ^ aPetitCompiler compileTrim: self. |
|
821 ! ! |
|
822 |
|
823 !PPTrimmingParser methodsFor:'*petitcompiler'! |
|
824 |
|
825 firstSets: aFirstDictionary into: aSet |
|
826 super firstSets: aFirstDictionary into: aSet |
|
827 ! ! |
|
828 |
|
829 !UndefinedObject methodsFor:'*petitcompiler'! |
|
830 |
|
831 asInteger |
|
832 ^ 256 |
|
833 ! ! |
|
834 |
|
835 !UndefinedObject methodsFor:'*petitcompiler'! |
|
836 |
|
837 isAlphaNumeric |
|
838 ^ false |
|
839 ! ! |
|
840 |
|
841 !UndefinedObject methodsFor:'*petitcompiler'! |
|
842 |
|
843 isDigit |
|
844 ^ false |
|
845 ! ! |
|
846 |
|
847 !UndefinedObject methodsFor:'*petitcompiler'! |
|
848 |
|
849 isLetter |
|
850 ^ false |
|
851 ! ! |
|
852 |
|
853 !stx_goodies_petitparser_compiler class methodsFor:'documentation'! |
|
854 |
|
855 extensionsVersion_HG |
|
856 |
|
857 ^ '$Changeset: <not expanded> $' |
|
858 ! ! |