author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 09 Nov 2015 00:38:23 +0000 | |
changeset 549 | 8ad6734770cd |
parent 502 | 1e45d3c96ec5 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/petitparser' }" |
0 | 2 |
|
502
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
4 |
|
0 | 5 |
PPListParser subclass:#PPSequenceParser |
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'PetitParser-Parsers' |
|
10 |
! |
|
11 |
||
12 |
||
180 | 13 |
|
502
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
14 |
!PPSequenceParser methodsFor:'*petitcompiler'! |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
15 |
|
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
16 |
map: aBlock |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
17 |
^ aBlock numArgs = self children size |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
18 |
ifTrue: [ self ==> [ :nodes | aBlock valueWithArguments: nodes ] ] |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
19 |
ifFalse: [ self error: aBlock numArgs asString , ' arguments expected.' ] |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
421
diff
changeset
|
20 |
! ! |
421
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
21 |
|
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
22 |
|
0 | 23 |
!PPSequenceParser methodsFor:'operations'! |
24 |
||
25 |
, aRule |
|
26 |
^ self copyWith: aRule |
|
27 |
! |
|
28 |
||
29 |
permutation: anArrayOfIntegers |
|
30 |
"Answer a permutation of the receivers sequence." |
|
12 | 31 |
|
0 | 32 |
anArrayOfIntegers do: [ :index | |
33 |
(index isInteger and: [ index between: 1 and: parsers size ]) |
|
34 |
ifFalse: [ self error: 'Invalid permutation index: ' , index printString ] ]. |
|
35 |
^ self ==> [ :nodes | anArrayOfIntegers collect: [ :index | nodes at: index ] ] |
|
36 |
! ! |
|
37 |
||
38 |
!PPSequenceParser methodsFor:'parsing'! |
|
39 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
180
diff
changeset
|
40 |
parseOn: aPPContext |
0 | 41 |
"This is optimized code that avoids unnecessary block activations, do not change." |
12 | 42 |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
180
diff
changeset
|
43 |
| memento elements element | |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
180
diff
changeset
|
44 |
memento := aPPContext remember. |
0 | 45 |
elements := Array new: parsers size. |
46 |
1 to: parsers size do: [ :index | |
|
12 | 47 |
element := (parsers at: index) |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
180
diff
changeset
|
48 |
parseOn: aPPContext. |
0 | 49 |
element isPetitFailure ifTrue: [ |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
180
diff
changeset
|
50 |
aPPContext restore: memento. |
0 | 51 |
^ element ]. |
52 |
elements at: index put: element ]. |
|
53 |
^ elements |
|
54 |
! ! |
|
55 |
||
56 |
!PPSequenceParser class methodsFor:'documentation'! |
|
57 |
||
12 | 58 |
version |
180 | 59 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $' |
12 | 60 |
! |
61 |
||
62 |
version_CVS |
|
180 | 63 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $' |
12 | 64 |
! |
65 |
||
421
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
66 |
version_HG |
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
67 |
|
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
68 |
^ '$Changeset: <not expanded> $' |
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
69 |
! |
7e08b31e0dae
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
70 |
|
0 | 71 |
version_SVN |
180 | 72 |
^ '$Id: PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $' |
0 | 73 |
! ! |
180 | 74 |