PPLiteralParser.st
author sr
Wed, 04 Jul 2018 15:23:55 +0200
changeset 607 019302eb9dd9
parent 171 eebf3d210c09
child 377 6112a403a52d
permissions -rw-r--r--
build order was wrong

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

PPParser subclass:#PPLiteralParser
	instanceVariableNames:'literal message'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitParser-Parsers'
!


!PPLiteralParser class methodsFor:'instance creation'!

on: anObject
    |msg|

    "portable - does not depend on character to print with a $"
    msg := anObject isCharacter 
            ifTrue:[ '$',anObject asString]
            ifFalse:[ anObject printString ].
    ^ self on: anObject message: msg , ' expected'
!

on: anObject message: aString
	^ self new initializeOn: anObject message: aString
! !

!PPLiteralParser methodsFor:'*petitanalyzer-matching'!

match: aParser inContext: aDictionary seen: anIdentitySet
	^ (super match: aParser inContext: aDictionary seen: anIdentitySet) and: [ self literal = aParser literal and: [ self message = aParser message ] ]
! !

!PPLiteralParser methodsFor:'accessing'!

literal
	"Answer the parsed literal."

	^ literal
!

message
	"Answer the failure message."
	
	^ message
! !

!PPLiteralParser methodsFor:'initialization'!

initializeOn: anObject message: aString
	literal := anObject.
	message := aString
! !

!PPLiteralParser methodsFor:'operators'!

caseInsensitive
	"Answer a parser that can parse the receiver case-insensitive."
	
	self subclassResponsibility
! !

!PPLiteralParser methodsFor:'printing'!

printNameOn: aStream
        super printNameOn: aStream.
        literal isCharacter ifTrue:[
            "/ portable - does not depend on character-print to print with $
            aStream nextPutAll: ', $'; print: literal asString
        ] ifFalse:[
            aStream nextPutAll: ', '; print: literal
        ].
! !

!PPLiteralParser class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLiteralParser.st,v 1.4 2014-03-04 14:33:03 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLiteralParser.st,v 1.4 2014-03-04 14:33:03 cg Exp $'
!

version_SVN
    ^ '$Id: PPLiteralParser.st,v 1.4 2014-03-04 14:33:03 cg Exp $'
! !