extensions.st
author sr
Wed, 04 Jul 2018 15:30:19 +0200
changeset 611 38338f2de417
parent 309 a60bee92ad60
child 376 a2656b27cace
child 634 e63445bb2c9a
permissions -rw-r--r--
build order was wrong

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

	"DUNNO WHY, but on: collection from: position to: last set the start to position -1"
	self breakPoint: #petitparser.

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


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

    "Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>"
! !

!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_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/extensions.st,v 1.12 2014-03-04 20:29:55 cg Exp $'
! !