author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 08 Sep 2015 01:31:37 +0100 | |
changeset 541 | ac763af77fc2 |
parent 377 | 6112a403a52d |
child 642 | 77d5fddb6462 |
permissions | -rw-r--r-- |
4 | 1 |
"{ Package: 'stx:goodies/petitparser' }" |
0 | 2 |
|
3 |
PPDelegateParser subclass:#PPMemoizedParser |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
4 |
instanceVariableNames:'buffer context hash' |
0 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'PetitParser-Parsers' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPMemoizedParser methodsFor:'operations'! |
|
12 |
||
13 |
memoized |
|
14 |
"Ther is no point in memoizing more than once." |
|
15 |
||
16 |
^ self |
|
17 |
! ! |
|
18 |
||
19 |
!PPMemoizedParser methodsFor:'parsing'! |
|
20 |
||
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
21 |
parseOn: aPPContext |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
22 |
| memento contextMemento aStream | |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
23 |
"TODO: JK memoizing needs review!!" |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
24 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
25 |
contextMemento := aPPContext remember. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
26 |
(hash == aPPContext hash) |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
27 |
ifFalse: [ self reset: aPPContext ]. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
28 |
memento := (buffer at: contextMemento ifAbsentPut: [ PPMemento new ]). |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
29 |
|
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
30 |
memento contextMemento isNil |
0 | 31 |
ifTrue: [ |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
32 |
aStream := aPPContext stream. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
33 |
memento result: (aStream size - aStream position + 2 < memento count |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
34 |
ifTrue: [ PPFailure message: 'overflow' context: aPPContext ] |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
35 |
ifFalse: [ memento increment. parser parseOn: aPPContext ]). |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
36 |
memento contextMemento: aPPContext remember ] |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
37 |
ifFalse: [ context restore: memento contextMemento ]. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
38 |
^ memento result. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
39 |
! |
0 | 40 |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
41 |
reset: aPPContext |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
42 |
hash := aPPContext hash. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
43 |
context := aPPContext. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
44 |
buffer := Dictionary new. |
0 | 45 |
! ! |
46 |
||
47 |
!PPMemoizedParser class methodsFor:'documentation'! |
|
48 |
||
10 | 49 |
version |
50 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPMemoizedParser.st,v 1.3 2012-05-04 21:58:48 vrany Exp $' |
|
51 |
! |
|
52 |
||
53 |
version_CVS |
|
54 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPMemoizedParser.st,v 1.3 2012-05-04 21:58:48 vrany Exp $' |
|
55 |
! |
|
56 |
||
0 | 57 |
version_SVN |
10 | 58 |
^ '§Id: PPMemoizedParser.st 2 2010-12-17 18:44:23Z vranyj1 §' |
0 | 59 |
! ! |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10
diff
changeset
|
60 |