compiler/PPCAbstractLiteralNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 01 May 2015 14:39:47 +0200
changeset 445 eb33780df2f9
parent 438 20598d7ce9fa
child 452 9f4558b3be66
permissions -rw-r--r--
Portability: Inlined #asLegalSelector since Smalltalk/X does not support it

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

"{ NameSpace: Smalltalk }"

PPCNode subclass:#PPCAbstractLiteralNode
	instanceVariableNames:'literal'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCAbstractLiteralNode methodsFor:'accessing'!

literal
	
	^ literal
!

literal: anObject
	
	literal := anObject
!

prefix
	^ #lit
! !

!PPCAbstractLiteralNode methodsFor:'analysis'!

acceptsEpsilon
	^ literal size = 0
!

firstCharSet
	| letter |
	letter := literal first.
	^ PPCharSetPredicate on: [:e | e = letter ]
! !

!PPCAbstractLiteralNode methodsFor:'comparison'!

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

hash
	^ super hash bitXor: literal hash
! !

!PPCAbstractLiteralNode methodsFor:'compiling'!

encodeQuotes: string
	| x s |
	s := WriteStream on: ''.
	1 to: string size do: [ :i|
		s nextPut: (x := string at: i).
		x = $' ifTrue: [ s nextPut: x ].
	].
	^ s contents
! !