compiler/PPCAbstractCharacterNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Oct 2014 23:01:54 +0000
changeset 398 b3e47bab2de6
parent 397 530d98b90b13
child 414 0eaf09920532
permissions -rw-r--r--
Added teardown to PetitCompilerTests to clean up a generated parser after tests.

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

PPCNode subclass:#PPCAbstractCharacterNode
	instanceVariableNames:'character'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!


!PPCAbstractCharacterNode methodsFor:'accessing'!

acceptsEpsilon
	^ false
!

character
	^ character
!

character: char
	character := char
!

prefix
	^ #char
! !

!PPCAbstractCharacterNode methodsFor:'analysis'!

firstCharParser
	^ character asParser
! !

!PPCAbstractCharacterNode methodsFor:'compiling'!

body: compiler
        | id |

        character ppcPrintable ifTrue: [
                id := character storeString.
        ] ifFalse: [
                id := compiler idFor: character prefixed: #char.
                compiler addConstant: (Character value: character asInteger) as: id .
        ].

        compiler add: '(context peek == ', id, ')'.
        compiler indent.
        compiler add: 'ifFalse: [ self error: ''', character asInteger asString, ' expected'' at: context position ] '.
        compiler add: 'ifTrue: [ context next ].'.
        compiler dedent.

    "Modified: / 30-10-2014 / 10:59:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

compileWith: compiler effect: effect id: id
	self start: compiler id: id.
	self body: compiler.
	^ self stop: compiler.
!

compileWith: compiler id: id
	self start: compiler.
	self body: compiler.
 	^ compiler stopMethod.
! !

!PPCAbstractCharacterNode class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !