compiler/PPCLiteralNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCLiteralNode.st	Sun Oct 26 01:03:31 2014 +0000
@@ -0,0 +1,39 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+PPCAbstractLiteralNode subclass:#PPCLiteralNode
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Nodes'
+!
+
+PPCLiteralNode comment:''
+!
+
+!PPCLiteralNode methodsFor:'compiling'!
+
+compileWith: compiler effect: effect id: id
+	| encodedLiteral |
+	
+	encodedLiteral := self encodeQuotes: literal.
+	compiler startMethod: id.
+	compiler addVariable: 'retval'.
+	compiler addVariable: 'position'.
+	compiler add: 'position := context position.'.
+
+	compiler add: 'retval := context next: ', literal size asString, '.'.
+	compiler add: 'retval = #''', encodedLiteral, ''' ifTrue: [ ^ #''', encodedLiteral, '''].'.
+	compiler add: 'context position: position.'.
+	compiler add: '^ self error: ''', encodedLiteral,  ' expected'' at: position'.
+ ^	compiler stopMethod.	
+! !
+
+!PPCLiteralNode methodsFor:'optimizing'!
+
+asInlined
+	^ PPCInlineLiteralNode new
+		literal: literal;
+		name: name;
+		yourself
+! !
+