extensions.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 21 May 2015 14:12:22 +0100
changeset 464 f6d77fee9811
parent 421 7e08b31e0dae
permissions -rw-r--r--
Updated to PetitCompiler-JanKurs.118, PetitCompiler-Tests-JanKurs.46, PetitCompiler-Extras-Tests-JanKurs.11, and PetitCompiler-Benchmarks-JanKurs.11 Name: PetitCompiler-JanKurs.118 Author: JanKurs Time: 13-05-2015, 03:59:01.292 PM UUID: 4a8ccd94-3131-4cc7-9098-528f8e5ea0b5 Name: PetitCompiler-Tests-JanKurs.46 Author: JanKurs Time: 04-05-2015, 04:25:06.162 PM UUID: 9f4cf8b7-876e-4a13-9579-b833f016db66 Name: PetitCompiler-Extras-Tests-JanKurs.11 Author: JanKurs Time: 13-05-2015, 04:27:27.940 PM UUID: e9f30c31-fbd0-4e96-ad2a-868f88d20ea8 Name: PetitCompiler-Benchmarks-JanKurs.11 Author: JanKurs Time: 13-05-2015, 02:21:49.932 PM UUID: 6a23fd1e-a86f-46db-8221-cc41b778d32c

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

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

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

!Collection methodsFor:'*petitparser-converting'!

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

	(self allSatisfy: [ :e | e isCharacter ]) ifTrue: [ 
		| charSet |
		charSet := PPCharSetPredicate on: [ :char | self includes: char ] .
     	^ PPPredicateObjectParser on: charSet message: 'One of these charactes expected: ', self printString.
	].


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

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

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

!Interval methodsFor:'*petitparser-core-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."

"
	Disabled until we agree on some way how to optimize this

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

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

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