|
1 "{ Package: 'squeak:petitparser' }" |
|
2 |
|
3 ! |
|
4 |
|
5 !Block methodsFor:'*petitparser-core-converting'! |
|
6 |
|
7 asParser |
|
8 ^ PPPluggableParser on: self |
|
9 ! ! |
|
10 !BlockContext methodsFor:'*petitparser-core-converting'! |
|
11 |
|
12 asParser |
|
13 ^ PPPluggableParser on: self |
|
14 ! ! |
|
15 !Character methodsFor:'arithmetic'! |
|
16 |
|
17 - aMagnitude |
|
18 "Return the Character that is <aMagnitude> lower than the receiver. |
|
19 Wrap if the resulting value is not a legal Character value. (JS) |
|
20 claus: |
|
21 modified to return the difference as integer, if the argument |
|
22 is another character. If the argument is a number, a character is |
|
23 returned." |
|
24 |
|
25 aMagnitude isCharacter ifTrue:[ |
|
26 ^ asciivalue - aMagnitude asInteger |
|
27 ]. |
|
28 ^ Character codePoint:((asciivalue - aMagnitude asInteger) \\ 16r3FFFFFFF) |
|
29 |
|
30 " |
|
31 $z - $a |
|
32 $d - 3 |
|
33 " |
|
34 |
|
35 "Modified: / 27-06-1996 / 12:35:34 / cg" |
|
36 "Modified: / 19-12-2010 / 18:36:56 / Jan Kurs <kurs.jan@post.cz>" |
|
37 ! ! |
|
38 !Character methodsFor:'*petitparser-converting'! |
|
39 |
|
40 asParser |
|
41 ^ PPLiteralObjectParser on: self |
|
42 ! ! |
|
43 !Character methodsFor:'arithmetic'! |
|
44 |
|
45 ppMinus: aCharacter |
|
46 "Create a range of characters between the receiver and the argument." |
|
47 |
|
48 ^ PPPredicateObjectParser between: self and: aCharacter |
|
49 |
|
50 "Created: / 19-12-2010 / 18:13:19 / Jan Kurs <kurs.jan@post.cz>" |
|
51 ! ! |
|
52 !Object methodsFor:'*petitparser-core-converting'! |
|
53 |
|
54 asParser |
|
55 ^ PPPredicateObjectParser expect: self |
|
56 ! ! |
|
57 !Object methodsFor:'*petitparser-core-testing'! |
|
58 |
|
59 isPetitFailure |
|
60 ^ false |
|
61 ! ! |
|
62 !Object methodsFor:'*petitparser-core-testing'! |
|
63 |
|
64 isPetitParser |
|
65 ^ false |
|
66 ! ! |
|
67 !PositionableStream methodsFor:'*petitparser-core-converting'! |
|
68 |
|
69 asPetitStream |
|
70 "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." |
|
71 |
|
72 "DUNNO WHY, but on: collection from: position to: last set the start to position -1" |
|
73 self breakPoint: #petitparser. |
|
74 |
|
75 ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
|
76 ifFalse: [ PPStream on: collection from: (position +1) to: readLimit ] |
|
77 ifTrue: [ super asPetitStream ] |
|
78 |
|
79 |
|
80 "/ ^ (collection isNil or: [ position isNil or: [ readLimit isNil ] ]) |
|
81 "/ ifFalse: [ PPStream on: collection from: position to: readLimit ] |
|
82 "/ ifTrue: [ super asPetitStream ] |
|
83 |
|
84 "Modified: / 18-12-2010 / 17:38:01 / Jan Kurs <kurs.jan@post.cz>" |
|
85 ! ! |
|
86 !SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
87 |
|
88 asParser |
|
89 ^ PPSequenceParser withAll: (self collect: [ :each | each asParser ]) |
|
90 ! ! |
|
91 !SequenceableCollection methodsFor:'*petitparser-core-converting'! |
|
92 |
|
93 asPetitStream |
|
94 ^ PPStream on: self |
|
95 ! ! |
|
96 !Set methodsFor:'*petitparser-core-converting'! |
|
97 |
|
98 asParser |
|
99 ^ PPChoiceParser withAll: (self collect: [ :each | each asParser ]) |
|
100 ! ! |
|
101 !Stream methodsFor:'*petitparser-core-converting'! |
|
102 |
|
103 asPetitStream |
|
104 ^ self contents asPetitStream |
|
105 ! ! |
|
106 !String methodsFor:'*petitparser-core-converting'! |
|
107 |
|
108 asParser |
|
109 ^ PPLiteralSequenceParser on: self |
|
110 ! ! |
|
111 !Symbol methodsFor:'*petitparser-core-converting'! |
|
112 |
|
113 asParser |
|
114 ^ PPPredicateObjectParser perform: self |
|
115 ! ! |
|
116 !Symbol methodsFor:'Compatibility-Squeak'! |
|
117 |
|
118 value:anObject |
|
119 ^ anObject perform: self. |
|
120 |
|
121 "Created: / 18-12-2010 / 16:47:22 / Jan Kurs <kurs.jan@post.cz>" |
|
122 ! ! |
|
123 !Text methodsFor:'*petitparser-core'! |
|
124 |
|
125 asPetitStream |
|
126 ^ string asPetitStream |
|
127 ! ! |
|
128 !UndefinedObject methodsFor:'*petitparser-converting'! |
|
129 |
|
130 asParser |
|
131 ^ PPEpsilonParser new |
|
132 ! ! |