compiler/PPCLiteralNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 01 Nov 2014 00:30:28 +0000
changeset 403 7063d523b064
parent 392 9b297f0d949c
child 422 116d2b2af905
permissions -rw-r--r--
Removed autoload attribut for tests. As all classes are in a test package, when package is loaded likely tests are required, so load them right away.

"{ Package: 'stx:goodies/petitparser/compiler' }"

PPCAbstractLiteralNode subclass:#PPCLiteralNode
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!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
! !