PPStartOfWordParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 16 Jun 2015 06:45:26 +0100
changeset 489 0ca7a70db0f5
parent 427 a7f5e6de19d2
permissions -rw-r--r--
Fix in codegen for inlined sequence nodes. For inlined sequence nodes, generate nested ifs rather than sequential code which does not work when inlined. The reason is that #codeReturn: in inline generates instvar assignment, not method return, so in sequential code the next child of a sequence will be probed even if previous failed. If that happends, the whole sequence fail and therefore we must generate nested ifs to correctly handle this w.r.t. inlining.
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
PPParser subclass:#PPStartOfWordParser
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
	instanceVariableNames:''
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
!PPStartOfWordParser 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
acceptsEpsilon
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
	^ true
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
!
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
parseOn: aPPContext
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
	aPPContext atEnd ifTrue: [  
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
		^ PPFailure message: 'Start of word expected' context: aPPContext at: aPPContext position 
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
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
	(aPPContext position == 0) ifTrue: [ 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
		(aPPContext peek isAlphaNumeric) ifTrue: [ 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
			^ #startOfWord
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
		] ifFalse: [ 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
			^ PPFailure message: 'Start of word expected' context: aPPContext at: aPPContext position 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
	 	]
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
	].
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
	aPPContext back.
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
	aPPContext peek isAlphaNumeric ifTrue: [
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
		^ PPFailure message: 'Start of word expected' context: aPPContext at: aPPContext position 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
	].
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
	aPPContext next.
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
	
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
	^ aPPContext peek isAlphaNumeric ifTrue: [ #startOfWord ] ifFalse: [ 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
		PPFailure message: 'Start of word expected' context: aPPContext at: aPPContext position 
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
	]
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
	
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
! !
a7f5e6de19d2 Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42