extensions.st
changeset 405 0470a5e6e712
parent 383 e9919f8e47de
child 408 ead04d661728
equal deleted inserted replaced
404:8da796db7f95 405:0470a5e6e712
    36 
    36 
    37 asChoiceParser
    37 asChoiceParser
    38 	^ PPChoiceParser withAll: (self collect: [ :each | each asParser ])
    38 	^ PPChoiceParser withAll: (self collect: [ :each | each asParser ])
    39 ! !
    39 ! !
    40 
    40 
       
    41 !Collection methodsFor:'*petitparser-converting'!
       
    42 
       
    43 asParser    
       
    44 	"Create a range of characters between start and stop."
       
    45 
       
    46 	(self allSatisfy: [ :e | e isCharacter ]) ifTrue: [ 
       
    47 		| charSet |
       
    48 		charSet := PPCharSetPredicate on: [ :char | self includes: char ] .
       
    49      	^ PPPredicateObjectParser on: charSet message: 'One of these charactes expected: ', self printString.
       
    50 	].
       
    51 
       
    52 
       
    53 	^ super asParser
       
    54 	"
       
    55 		($a to:$f) asParser parse:'a'
       
    56 		($a to:$f) asParser parse:'g'
       
    57 	"
       
    58 ! !
       
    59 
    41 !Collection methodsFor:'*petitparser-core-converting'!
    60 !Collection methodsFor:'*petitparser-core-converting'!
    42 
    61 
    43 asSequenceParser
    62 asSequenceParser
    44 	^ PPSequenceParser withAll: (self collect: [ :each | each asParser ])
    63 	^ PPSequenceParser withAll: (self collect: [ :each | each asParser ])
    45 ! !
    64 ! !
    46 
    65 
    47 !Interval methodsFor:'*petitparser-converting'!
    66 !Interval methodsFor:'*petitparser-core-converting'!
    48 
    67 
    49 asParser
    68 asParser    
    50     "Create a range of characters between start and stop."
    69         "Create a range of characters between start and stop."
    51 
    70 
    52     self assert:start isCharacter.
    71     self assert:start isCharacter.
    53     self assert:stop isCharacter.
    72     self assert:stop isCharacter.
    54     self assert:step == 1.
    73     self assert:step == 1.
    55     ^ PPPredicateObjectParser between: start and: stop
    74     ^ PPPredicateObjectParser between: start and: stop
    56 
    75 
    57     "
    76     "
    58      ($a to:$f) asParser parse:'a'
    77                 ($a to: $f) asParser parse: 'a'
    59      ($a to:$f) asParser parse:'g'
    78                 ($a to: $f) asParser parse: 'g'
    60     "
    79     "
       
    80 
       
    81     "Modified (comment): / 01-11-2014 / 13:13:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    61 ! !
    82 ! !
    62 
    83 
    63 !Object methodsFor:'*petitparser-core-converting'!
    84 !Object methodsFor:'*petitparser-core-converting'!
    64 
    85 
    65 asParser
    86 asParser
    81 ! !
   102 ! !
    82 
   103 
    83 !PositionableStream methodsFor:'*petitparser-core-converting'!
   104 !PositionableStream methodsFor:'*petitparser-core-converting'!
    84 
   105 
    85 asPetitStream
   106 asPetitStream
    86         "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."
   107 	"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."
    87 
   108 
    88         ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ])
   109 	^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ])
    89                 ifFalse: [ PPStream on: collection from: ( position + 1 ) to: readLimit ]
   110 		ifFalse: [ PPStream on: collection from: ( position + 1 ) to: readLimit ]
    90                 ifTrue: [ super asPetitStream ]
   111       ifTrue: [ super asPetitStream ]
    91 
       
    92     "Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>"
       
    93     "Modified: / 04-10-2014 / 23:27:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    94 ! !
   112 ! !
    95 
   113 
    96 !PositionableStream methodsFor:'*petitparser-core'!
   114 !PositionableStream methodsFor:'*petitparser-core'!
    97 
   115 
    98 peekTwice
   116 peekTwice
   103 	self atEnd 
   121 	self atEnd 
   104 		ifTrue: [^Array with: nil with: nil].
   122 		ifTrue: [^Array with: nil with: nil].
   105 	array := Array with: (self next) with: (self peek).
   123 	array := Array with: (self next) with: (self peek).
   106 	position := position - 1.
   124 	position := position - 1.
   107 	^array
   125 	^array
   108 ! !
       
   109 
       
   110 !SequenceableCollection methodsFor:'*petitparser-core-converting'!
       
   111 
       
   112 asParser
       
   113 	^ PPSequenceParser withAll: (self collect: [ :each | each asParser ])
       
   114 ! !
   126 ! !
   115 
   127 
   116 !SequenceableCollection methodsFor:'*petitparser-core-converting'!
   128 !SequenceableCollection methodsFor:'*petitparser-core-converting'!
   117 
   129 
   118 asPetitStream
   130 asPetitStream