compiler/PPCStarNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCStarNode.st	Sun Oct 26 01:03:31 2014 +0000
@@ -0,0 +1,73 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+PPCDelegateNode subclass:#PPCStarNode
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Nodes'
+!
+
+PPCStarNode comment:''
+!
+
+!PPCStarNode methodsFor:'accessing'!
+
+acceptsEpsilon
+	^ true
+!
+
+acceptsEpsilonOpenSet: set
+	^ true
+!
+
+prefix
+	^ #star
+!
+
+rewrite: changeStatus
+	(child isKindOf: PPCMessagePredicateNode) ifTrue: [ 
+		changeStatus change.
+		^ PPCStarMessagePredicateNode new
+			name: name;
+			message: child message;
+			yourself
+	]. 
+
+	(child isKindOf: PPCAnyNode) ifTrue: [ 
+		changeStatus change.
+		^ PPCStarAnyNode new
+			name: name;
+			yourself
+	]. 
+
+	(child isKindOf: PPCCharSetPredicateNode) ifTrue: [ 
+		changeStatus change.
+		^ PPCStarCharSetPredicateNode new
+			name: name;
+			predicate: child predicate;
+			yourself
+	] 
+! !
+
+!PPCStarNode methodsFor:'as yet unclassified'!
+
+compileWith: compiler effect: effect id: id
+	compiler startMethod: id.
+	compiler addVariable: 'retval'.
+	compiler addVariable: 'element'.
+
+	compiler add: 'retval := OrderedCollection new.'.
+	compiler add: 'element := '.
+	compiler callOnLine: (child compileWith: compiler).
+	compiler add: '[ error ] whileFalse: ['.
+	compiler indent.
+	compiler add: 'retval add: element.'.
+	compiler add: 'element := '.
+	compiler callOnLine: (child compileWith: compiler).
+	compiler dedent.
+	compiler add: '].'.
+	compiler add: 'self clearError.'.
+	compiler add: '^ retval asArray'.
+ ^ compiler stopMethod.
+! !
+