PPConditionalParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 17 Jun 2015 16:49:28 +0100
changeset 492 fc3dbe5654c5
parent 427 a7f5e6de19d2
permissions -rw-r--r--
Use #deepCopy instead of #copy when copying RB parse tree ...because #copy make a copy if child nodes but does not set their parents properly. Therefore node replacing does not work because it replaces it in wrong tree (original, not the copy).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
427
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser' }"
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
"{ NameSpace: Smalltalk }"
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
PPDelegateParser subclass:#PPConditionalParser
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
	instanceVariableNames:'block'
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
	classVariableNames:''
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
	poolDictionaries:''
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
	category:'PetitParser-Parsers'
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
!
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
!PPConditionalParser class methodsFor:'as yet unclassified'!
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
on: aPPParser block: block
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
	^ (PPConditionalParser on: aPPParser)
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
		block: block;
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
		yourself
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
! !
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
!PPConditionalParser methodsFor:'accessing'!
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
block: aBlock
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
	block := aBlock
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
! !
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
!PPConditionalParser methodsFor:'parsing'!
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
parseOn: aPPContext
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
	^ (block value: aPPContext) 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
		ifTrue: [ parser parseOn: aPPContext ]
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
		ifFalse: [ PPFailure message: block asString, ' was not evaluated to true.' context: aPPContext ]
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
! !
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33