extensions.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 26 Oct 2014 01:03:31 +0000
changeset 391 553a5456963b
parent 383 e9919f8e47de
child 405 0470a5e6e712
permissions -rw-r--r--
Ported PetitCompiler-(Tests). Name: PetitCompiler-JanKurs.41 Author: JanKurs Time: 25-10-2014, 03:30:28 AM UUID: 105186d1-1187-4ca6-8d66-3d2d47def4d3 Repository: http://smalltalkhub.com/mc/JanKurs/PetitParser/main Name: PetitCompiler-Tests-JanKurs.4 Author: JanKurs Time: 25-10-2014, 03:30:58 AM UUID: 3e798fad-d5f6-4881-a583-f0bbffe27869 Repository: http://smalltalkhub.com/mc/JanKurs/PetitParser/main In addition, fixed some problems to make it compilable under Smalltalk/X: * Fixed PPCTokenNode>>initialize - there's no children instvar, it's initialization removed. * Fixed PPCContextMemento>>propertyAt:ifAbsent: - removed return-in-return, not compilable under Smalltalk/X (C issues) * Fixed PPCContextMemento>>hash - there's no stream instvar, access to it removed. * Fixed PPCAbstractCharacterNode>>compileWith:effect:id: - removed dot after method selector (stc does not like it)

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

!Block methodsFor:'*petitparser-core-converting'!

asParser
	"Answer a parser implemented in the receiving one-argument block."

	^ PPPluggableParser on: self
! !

!BlockContext methodsFor:'*petitparser-core-converting'!

asParser
	^ PPPluggableParser on: self
! !

!Character methodsFor:'*petitparser-core-converting'!

asParser
	"Answer a parser that accepts the receiving character."
	
	^ PPLiteralObjectParser on: self
! !

!Character methodsFor:'arithmetic'!

ppMinus: aCharacter
    "Create a range of characters between the receiver and the argument."

    ^ PPPredicateObjectParser between: self and: aCharacter

    "Created: / 19-12-2010 / 18:13:19 / Jan Kurs <kurs.jan@post.cz>"
! !

!Collection methodsFor:'*petitparser-core-converting'!

asChoiceParser
	^ PPChoiceParser withAll: (self collect: [ :each | each asParser ])
! !

!Collection methodsFor:'*petitparser-core-converting'!

asSequenceParser
	^ PPSequenceParser withAll: (self collect: [ :each | each asParser ])
! !

!Interval methodsFor:'*petitparser-converting'!

asParser
    "Create a range of characters between start and stop."

    self assert:start isCharacter.
    self assert:stop isCharacter.
    self assert:step == 1.
    ^ PPPredicateObjectParser between: start and: stop

    "
     ($a to:$f) asParser parse:'a'
     ($a to:$f) asParser parse:'g'
    "
! !

!Object methodsFor:'*petitparser-core-converting'!

asParser
	"Answer a parser accepting the receiving object."

	^ PPPredicateObjectParser expect: self
! !

!Object methodsFor:'*petitparser-core-testing'!

isPetitFailure
	^ false
! !

!Object methodsFor:'*petitparser-core-testing'!

isPetitParser
	^ false
! !

!PositionableStream methodsFor:'*petitparser-core-converting'!

asPetitStream
        "Some of my subclasses do not use the instance-variables collection, position and readLimit but instead have a completely different internal representation. In these cases just use the super implementation that is inefficient but should work in all cases."

        ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ])
                ifFalse: [ PPStream on: collection from: ( position + 1 ) to: readLimit ]
                ifTrue: [ super asPetitStream ]

    "Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>"
    "Modified: / 04-10-2014 / 23:27:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PositionableStream methodsFor:'*petitparser-core'!

peekTwice
	"Answer what would be returned if the message next were sent to the 
	receiver. If the receiver is at the end, answer nil."

	| array |
	self atEnd 
		ifTrue: [^Array with: nil with: nil].
	array := Array with: (self next) with: (self peek).
	position := position - 1.
	^array
! !

!SequenceableCollection methodsFor:'*petitparser-core-converting'!

asParser
	^ PPSequenceParser withAll: (self collect: [ :each | each asParser ])
! !

!SequenceableCollection methodsFor:'*petitparser-core-converting'!

asPetitStream
	^ PPStream on: self
! !

!Set methodsFor:'*petitparser-core-converting'!

asParser
	^ PPChoiceParser withAll: (self collect: [ :each | each asParser ])
! !

!Stream methodsFor:'*petitparser-core-converting'!

asPetitStream
	^ self contents asPetitStream
! !

!String methodsFor:'*petitparser-core-converting'!

asParser
	"Answer a parser that accepts the receiving string."

	^ PPLiteralSequenceParser on: self
! !

!Symbol methodsFor:'*petitparser-core-converting'!

asParser
	"Answer a predicate parser named after the receiving symbol. Possible symbols are the method selectors on the class-side of PPPredicateObjectParser."

	^ PPPredicateObjectParser perform: self
! !

!Symbol methodsFor:'Compatibility-Squeak'!

value:anObject
    ^ anObject perform: self.

    "Created: / 18-12-2010 / 16:47:22 / Jan Kurs <kurs.jan@post.cz>"
! !

!Text methodsFor:'*petitparser-core'!

asPetitStream
	^ string asPetitStream
! !

!UndefinedObject methodsFor:'*petitparser-converting'!

asParser
	"Answer a parser that succeeds and does not consume anything."
	
	^ PPEpsilonParser new
! !

!stx_goodies_petitparser class methodsFor:'documentation'!

extensionsVersion_HG

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