compiler/PPCInlineLiteralNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCInlineLiteralNode.st	Sun Oct 26 01:03:31 2014 +0000
@@ -0,0 +1,47 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+PPCAbstractLiteralNode subclass:#PPCInlineLiteralNode
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Nodes'
+!
+
+PPCInlineLiteralNode comment:''
+!
+
+!PPCInlineLiteralNode methodsFor:'compiling'!
+
+compileWith: compiler effect: effect id: id
+	| encodedLiteral |
+	
+	encodedLiteral := self encodeQuotes: literal.
+	compiler startInline: id.
+	compiler add: '((context peek: ', literal size asString, ') = #''', encodedLiteral, ''')'.
+	compiler indent.
+	compiler add: ' ifTrue: [ context skip: ', literal size asString, '. #''', encodedLiteral, ''']'.
+	compiler add: ' ifFalse: [ self error: ''', encodedLiteral,  ' expected'' ].'.
+	compiler dedent.
+ ^ compiler stopInline.
+!
+
+inlineWith: compiler id: id
+	| encodedLiteral |
+	
+	encodedLiteral := self encodeQuotes: literal.
+	compiler startInline: id.
+	compiler add: '((context peek: ', literal size asString, ') = #''', encodedLiteral, ''')'.
+	compiler indent.
+	compiler add: ' ifTrue: [ context skip: ', literal size asString, '. #''', encodedLiteral, ''']'.
+	compiler add: ' ifFalse: [ self error: ''', encodedLiteral,  ' expected'' ].'.
+	compiler dedent.
+ ^ compiler stopInline.
+! !
+
+!PPCInlineLiteralNode methodsFor:'printing'!
+
+printOn: aStream
+	aStream nextPutAll: '#inline'.
+	super printOn: aStream
+! !
+