compiler/PPCAbstractCharacterNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Apr 2015 23:43:14 +0200
changeset 438 20598d7ce9fa
parent 429 23de165842c3
child 452 9f4558b3be66
permissions -rw-r--r--
Updated to PetitCompiler-JanKurs.100, PetitCompiler-Tests-JanKurs.44 and PetitCompiler-Benchmarks-JanKurs.4 Name: PetitCompiler-JanKurs.100 Author: JanKurs Time: 30-04-2015, 10:48:52.165 AM UUID: 80196870-5921-46d9-ac20-a43bf5c2f3c2 Name: PetitCompiler-Tests-JanKurs.44 Author: JanKurs Time: 30-04-2015, 10:49:22.489 AM UUID: 348c02e8-18ce-48f6-885d-fcff4516a298 Name: PetitCompiler-Benchmarks-JanKurs.4 Author: JanKurs Time: 30-04-2015, 10:58:44.890 AM UUID: 18cadb42-f9ef-45fb-82e9-8469ade56c8b

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

"{ NameSpace: Smalltalk }"

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


!PPCAbstractCharacterNode methodsFor:'accessing'!

character
	^ character
!

character: char
	character := char
!

prefix
	^ #char
! !

!PPCAbstractCharacterNode methodsFor:'analysis'!

acceptsEpsilon
	^ false
!

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

!PPCAbstractCharacterNode class methodsFor:'documentation'!

version_HG

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