compiler/PPCStarCharSetPredicateNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Oct 2014 23:01:54 +0000
changeset 398 b3e47bab2de6
parent 392 9b297f0d949c
child 414 0eaf09920532
permissions -rw-r--r--
Added teardown to PetitCompilerTests to clean up a generated parser after tests.

"{ Package: 'stx:goodies/petitparser/compiler' }"

PPCNode subclass:#PPCStarCharSetPredicateNode
	instanceVariableNames:'predicate'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCStarCharSetPredicateNode methodsFor:'accessing'!

acceptsEpsilon
	^ true
!

compileWith: compiler effect: effect id: id
	| classification classificationId |
	
	compiler startMethod: id.
	classification := self extendClassification: predicate classification.
	classificationId := compiler idFor: classification prefixed: #classification.
	compiler addConstant: classification as: classificationId.
	
	compiler addVariable: 'retval'.
	compiler add: 'retval := OrderedCollection new.'.	
	compiler add: '[ ', classificationId, ' at: context peek asInteger ] whileTrue: ['.
	compiler indent.
	compiler add: ' retval add: context next.'.
	compiler dedent.
	compiler add: '].'.
   compiler add: '^ retval asArray'.
 ^ compiler stopMethod.
!

extendClassification: classification
	^ (classification asOrderedCollection addLast: false; yourself) asArray
!

firstCharParser
	^ PPPredicateObjectParser on: predicate message: 'predicate expected'.
!

predicate
	
	^ predicate
!

predicate: anObject
	
	predicate := anObject
!

prefix
	^ #starPredicate
! !