extensions.st
author Claus Gittinger <cg@exept.de>
Tue, 04 Mar 2014 16:53:53 +0100
changeset 213 b38781d329c5
parent 155 1109bb0048eb
child 226 f88e1127557a
permissions -rw-r--r--
comments
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
90de244a7fa2 move to package
Claus Gittinger <cg@exept.de>
parents: 3
diff changeset
     1
"{ Package: 'stx:goodies/petitparser' }"!
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
!Block methodsFor:'*petitparser-core-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
asParser
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
     6
	"Answer a parser implemented in the receiving one-argument block."
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
     7
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	^ PPPluggableParser on: self
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
    10
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
!BlockContext methodsFor:'*petitparser-core-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
asParser
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
	^ PPPluggableParser on: self
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
    16
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    17
!Character methodsFor:'*petitparser-core-converting'!
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    19
asParser
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    20
	"Answer a parser that accepts the receiving character."
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    21
	
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    22
	^ PPLiteralObjectParser on: self
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
    24
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!Character methodsFor:'arithmetic'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    27
ppMinus: aCharacter
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    28
    "Create a range of characters between the receiver and the argument."
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    30
    ^ PPPredicateObjectParser between: self and: aCharacter
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    32
    "Created: / 19-12-2010 / 18:13:19 / Jan Kurs <kurs.jan@post.cz>"
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
    34
153
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    35
!Interval methodsFor:'*petitparser-converting'!
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
asParser
153
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    38
    "Create a range of characters between start and stop."
152
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    39
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    40
    self assert:start isCharacter.
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    41
    self assert:stop isCharacter.
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    42
    self assert:step == 1.
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    43
    ^ PPPredicateObjectParser between: start and: stop
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    44
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    45
    "
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    46
     ($a to:$f) asParser parse:'a'
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    47
     ($a to:$f) asParser parse:'g'
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    48
    "
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    49
! !
d104f89293e3 added Interval>>asParser
Claus Gittinger <cg@exept.de>
parents: 150
diff changeset
    50
153
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    51
!Object methodsFor:'*petitparser-core-converting'!
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    52
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    53
asParser
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    54
	"Answer a parser accepting the receiving object."
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
    55
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    56
	^ PPPredicateObjectParser expect: self
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    57
! !
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    58
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    59
!Object methodsFor:'*petitparser-core-testing'!
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    60
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    61
isPetitFailure
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    62
	^ false
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    63
! !
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    64
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    65
!Object methodsFor:'*petitparser-core-testing'!
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    66
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    67
isPetitParser
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    68
	^ false
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    69
! !
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    70
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    71
!PositionableStream methodsFor:'*petitparser-core-converting'!
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    72
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    73
asPetitStream
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    74
	"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."
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    75
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    76
	"DUNNO WHY, but on: collection from: position to: last set the start to position -1"
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    77
	self breakPoint: #petitparser.
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    78
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    79
	^ (collection isNil or: [ position  isNil or: [ readLimit isNil ] ])
153
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    80
		ifFalse: [ PPStream on: collection from: (position +1) to: readLimit ]
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    81
		ifTrue: [ super asPetitStream ]
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    82
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    83
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    84
"/        ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ])
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    85
"/                ifFalse: [ PPStream on: collection from: position to: readLimit ]
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    86
"/                ifTrue: [ super asPetitStream ]
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    87
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    88
    "Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>"
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    89
! !
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    90
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    91
!SequenceableCollection methodsFor:'*petitparser-core-converting'!
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    92
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    93
asParser
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    94
	^ PPSequenceParser withAll: (self collect: [ :each | each asParser ])
153
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    95
! !
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    96
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    97
!SequenceableCollection methodsFor:'*petitparser-core-converting'!
43cdafa051d5 added Interval asParser
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
    98
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
    99
asPetitStream
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   100
	^ PPStream on: self
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   101
! !
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   102
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!Set methodsFor:'*petitparser-core-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   105
asParser
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   106
	^ PPChoiceParser withAll: (self collect: [ :each | each asParser ])
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   108
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!Stream methodsFor:'*petitparser-core-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   111
asPetitStream
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   112
	^ self contents asPetitStream
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   114
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
!String methodsFor:'*petitparser-core-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   117
asParser
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   118
	"Answer a parser that accepts the receiving string."
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   119
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   120
	^ PPLiteralSequenceParser on: self
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   122
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
!Symbol methodsFor:'*petitparser-core-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   125
asParser
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   126
	"Answer a predicate parser named after the receiving symbol. Possible symbols are the method selectors on the class-side of PPPredicateObjectParser."
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   127
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   128
	^ PPPredicateObjectParser perform: self
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   130
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
!Symbol methodsFor:'Compatibility-Squeak'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   133
value:anObject
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   134
    ^ anObject perform: self.
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   135
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   136
    "Created: / 18-12-2010 / 16:47:22 / Jan Kurs <kurs.jan@post.cz>"
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   138
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!Text methodsFor:'*petitparser-core'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   141
asPetitStream
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   142
	^ string asPetitStream
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   144
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
!UndefinedObject methodsFor:'*petitparser-converting'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   147
asParser
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   148
	"Answer a parser that succeeds and does not consume anything."
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   149
	
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   150
	^ PPEpsilonParser new
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
! !
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   152
4
90de244a7fa2 move to package
Claus Gittinger <cg@exept.de>
parents: 3
diff changeset
   153
!stx_goodies_petitparser class methodsFor:'documentation'!
3
e1b11f74e142 initial checkin
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
   154
154
5c8f5da40d90 manually fixed bad checkin version
Claus Gittinger <cg@exept.de>
parents: 153
diff changeset
   155
extensionsVersion_CVS
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   156
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/extensions.st,v 1.10 2014-03-04 15:53:53 cg Exp $'
150
24e8d10ff041 Character>>-not needed here - already in libbasic
Claus Gittinger <cg@exept.de>
parents: 58
diff changeset
   157
! !
213
b38781d329c5 comments
Claus Gittinger <cg@exept.de>
parents: 155
diff changeset
   158