compiler/PPCAbstractCharacterNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 15 Apr 2015 11:28:09 +0100
changeset 422 116d2b2af905
parent 421 7e08b31e0dae
child 429 23de165842c3
permissions -rw-r--r--
To fold

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

"{ NameSpace: Smalltalk }"

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

firstCharSet
	^ PPCharSetPredicate on: [:e | e = character ]
! !

!PPCAbstractCharacterNode methodsFor:'comparison'!

= anotherNode
	super = anotherNode ifFalse: [ ^ false ].
	^ character = anotherNode character.
!

hash
	^ super hash bitXor: character hash
! !

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

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