compiler/PPCTrimNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCTrimNode.st	Sun Oct 26 01:03:31 2014 +0000
@@ -0,0 +1,45 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+PPCDelegateNode subclass:#PPCTrimNode
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Nodes'
+!
+
+PPCTrimNode comment:''
+!
+
+!PPCTrimNode methodsFor:'accessing'!
+
+prefix
+	^ #trim
+! !
+
+!PPCTrimNode methodsFor:'compiling'!
+
+compileWith: compiler effect: effect id: id
+	"TODO: This ignores the TrimmingParser trimmer object!!"
+	compiler startMethod: id.
+	compiler addVariable: 'result'.	
+
+	compiler add: '[context atEnd not and: [ context uncheckedPeek isSeparator ]] whileTrue: ['.
+	compiler indent.
+	compiler add: 'context next'.
+	compiler dedent.
+	compiler add: '].'.
+
+	compiler add: 'result := '.
+	compiler callOnLine: (child compileWith: compiler).
+
+	compiler add: '[context atEnd not and: [ context uncheckedPeek isSeparator ]] whileTrue: ['.
+	compiler indent.
+	compiler add: 'context next'.
+	compiler dedent.
+	compiler add: '].'.
+
+	compiler add: '^ result'.
+	compiler stopMethod.
+ ^ compiler lastMethod
+! !
+