compiler/PPCStarCharSetPredicateNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCStarCharSetPredicateNode.st	Sun Oct 26 01:03:31 2014 +0000
@@ -0,0 +1,59 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+PPCNode subclass:#PPCStarCharSetPredicateNode
+	instanceVariableNames:'predicate'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Nodes'
+!
+
+PPCStarCharSetPredicateNode comment:''
+!
+
+!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
+! !
+