compiler/PPCAbstractCharacterNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 05 Nov 2014 23:05:19 +0000
changeset 414 0eaf09920532
parent 397 530d98b90b13
child 421 7e08b31e0dae
permissions -rw-r--r--
Merged JK's work on PetitCompiler Name: PetitCompiler-JanKurs.57 Author: JanKurs Time: 05-11-2014, 05:10:47 AM UUID: 4c625efe-77fd-465d-bd63-72ead0b5d3ba Name: PetitCompiler-Tests-JanVrany.13 Author: JanVrany Time: 05-11-2014, 09:31:07 AM UUID: 189ae287-6bc1-40ba-8458-b8392c4260a0

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

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

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