compiler/PPCLiteralNode.st
changeset 391 553a5456963b
child 392 9b297f0d949c
equal deleted inserted replaced
390:17ba167b8ee1 391:553a5456963b
       
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
       
     2 
       
     3 PPCAbstractLiteralNode subclass:#PPCLiteralNode
       
     4 	instanceVariableNames:''
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitCompiler-Nodes'
       
     8 !
       
     9 
       
    10 PPCLiteralNode comment:''
       
    11 !
       
    12 
       
    13 !PPCLiteralNode methodsFor:'compiling'!
       
    14 
       
    15 compileWith: compiler effect: effect id: id
       
    16 	| encodedLiteral |
       
    17 	
       
    18 	encodedLiteral := self encodeQuotes: literal.
       
    19 	compiler startMethod: id.
       
    20 	compiler addVariable: 'retval'.
       
    21 	compiler addVariable: 'position'.
       
    22 	compiler add: 'position := context position.'.
       
    23 
       
    24 	compiler add: 'retval := context next: ', literal size asString, '.'.
       
    25 	compiler add: 'retval = #''', encodedLiteral, ''' ifTrue: [ ^ #''', encodedLiteral, '''].'.
       
    26 	compiler add: 'context position: position.'.
       
    27 	compiler add: '^ self error: ''', encodedLiteral,  ' expected'' at: position'.
       
    28  ^	compiler stopMethod.	
       
    29 ! !
       
    30 
       
    31 !PPCLiteralNode methodsFor:'optimizing'!
       
    32 
       
    33 asInlined
       
    34 	^ PPCInlineLiteralNode new
       
    35 		literal: literal;
       
    36 		name: name;
       
    37 		yourself
       
    38 ! !
       
    39