extensions.st
author Claus Gittinger <cg@exept.de>
Mon, 12 Sep 2011 19:48:53 +0200
changeset 3 e1b11f74e142
parent 0 739fe9b7253e
child 4 90de244a7fa2
permissions -rw-r--r--
initial checkin

"{ Package: 'squeak:petitparser' }"!

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

asParser
	^ PPPluggableParser on: self
! !

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

asParser
	^ PPPluggableParser on: self
! !

!Character methodsFor:'arithmetic'!

- aMagnitude
    "Return the Character that is <aMagnitude> lower than the receiver.
     Wrap if the resulting value is not a legal Character value. (JS)
     claus:
        modified to return the difference as integer, if the argument
        is another character. If the argument is a number, a character is
        returned."

    aMagnitude isCharacter ifTrue:[
        ^ asciivalue - aMagnitude asInteger
    ].
    ^ Character codePoint:((asciivalue - aMagnitude asInteger) \\ 16r3FFFFFFF)

    "
     $z - $a
     $d - 3
    "

    "Modified: / 27-06-1996 / 12:35:34 / cg"
    "Modified: / 19-12-2010 / 18:36:56 / Jan Kurs <kurs.jan@post.cz>"
! !

!Character methodsFor:'*petitparser-converting'!

asParser
	^ 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>"
! !

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

asParser
	^ 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
	^ PPLiteralSequenceParser on: self
! !

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

asParser
	^ 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
	^ PPEpsilonParser new
! !

!squeak_petitparser class methodsFor:'documentation'!

extensionsVersion_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/extensions.st,v 1.2 2011-09-12 17:48:53 cg Exp $'
! !