4
|
1 |
"{ Package: 'stx:goodies/petitparser' }"
|
0
|
2 |
|
|
3 |
Object subclass:#PPToken
|
|
4 |
instanceVariableNames:'collection start stop'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'PetitParser-Core'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!PPToken class methodsFor:'instance creation'!
|
|
12 |
|
|
13 |
new
|
|
14 |
self error: 'Token can only be created using a dedicated constructor.'
|
|
15 |
!
|
|
16 |
|
|
17 |
on: aSequenceableCollection
|
|
18 |
^ self on: aSequenceableCollection start: 1 stop: aSequenceableCollection size
|
|
19 |
!
|
|
20 |
|
|
21 |
on: aSequenceableCollection start: aStartInteger stop: aStopInteger
|
30
|
22 |
^ self basicNew
|
0
|
23 |
initializeOn: aSequenceableCollection
|
|
24 |
start: aStartInteger stop: aStopInteger
|
|
25 |
! !
|
|
26 |
|
|
27 |
!PPToken methodsFor:'accessing'!
|
|
28 |
|
|
29 |
collection
|
|
30 |
"Answer the underlying collection of this token."
|
|
31 |
|
|
32 |
^ collection
|
|
33 |
!
|
|
34 |
|
|
35 |
size
|
|
36 |
"Answer the size of this token."
|
|
37 |
|
|
38 |
^ stop - start + 1
|
|
39 |
!
|
|
40 |
|
|
41 |
start
|
|
42 |
"Answer the start position of this token in the underlying collection."
|
|
43 |
|
|
44 |
^ start
|
|
45 |
!
|
|
46 |
|
|
47 |
stop
|
|
48 |
"Answer the stop position of this token in the underlying collection."
|
30
|
49 |
|
0
|
50 |
^ stop
|
|
51 |
!
|
|
52 |
|
|
53 |
value
|
|
54 |
"Answer the contents of this token."
|
|
55 |
|
|
56 |
^ collection copyFrom: start to: stop
|
|
57 |
! !
|
|
58 |
|
|
59 |
!PPToken methodsFor:'comparing'!
|
|
60 |
|
|
61 |
= anObject
|
|
62 |
^ self class = anObject class and: [ self value = anObject value ]
|
|
63 |
!
|
|
64 |
|
|
65 |
hash
|
|
66 |
^ self value hash
|
|
67 |
! !
|
|
68 |
|
|
69 |
!PPToken methodsFor:'copying'!
|
|
70 |
|
|
71 |
copyFrom: aStartInteger to: aStopInteger
|
|
72 |
^ self class on: collection start: start + aStartInteger - 1 stop: stop + aStopInteger - 3
|
|
73 |
! !
|
|
74 |
|
|
75 |
!PPToken methodsFor:'initialization'!
|
|
76 |
|
|
77 |
initializeOn: aSequenceableCollection start: aStartInteger stop: aStopInteger
|
|
78 |
collection := aSequenceableCollection.
|
|
79 |
start := aStartInteger.
|
|
80 |
stop := aStopInteger
|
|
81 |
! !
|
|
82 |
|
|
83 |
!PPToken methodsFor:'printing'!
|
|
84 |
|
|
85 |
printOn: aStream
|
|
86 |
super printOn: aStream.
|
|
87 |
aStream nextPut: $(; nextPutAll: self value; nextPut: $)
|
|
88 |
! !
|
|
89 |
|
|
90 |
!PPToken methodsFor:'private'!
|
|
91 |
|
|
92 |
newline
|
91
|
93 |
"Parser a platform independent newline sequence. LF: Unix, CR+LF: Windows, and CR: Apple."
|
0
|
94 |
|
91
|
95 |
Smalltalk isSmalltalkX ifTrue:[
|
|
96 |
^ (Character lf asParser)
|
|
97 |
/ (Character return asParser , Character lf asParser optional)
|
|
98 |
] ifFalse:[
|
|
99 |
^ (Character lf asParser)
|
|
100 |
/ (Character cr asParser , Character lf asParser optional)
|
|
101 |
]
|
0
|
102 |
! !
|
|
103 |
|
|
104 |
!PPToken methodsFor:'querying'!
|
|
105 |
|
|
106 |
column
|
|
107 |
"Answer the column number of this token in the underlying collection."
|
30
|
108 |
|
0
|
109 |
| position |
|
|
110 |
position := 0.
|
|
111 |
(self newline , [ :stream |
|
|
112 |
start <= stream position
|
|
113 |
ifTrue: [ ^ start - position ].
|
|
114 |
position := stream position ] asParser
|
|
115 |
/ #any asParser) star
|
|
116 |
parse: collection.
|
|
117 |
^ start - position
|
|
118 |
!
|
|
119 |
|
|
120 |
line
|
|
121 |
"Answer the line number of this token in the underlying collection."
|
30
|
122 |
|
0
|
123 |
| line |
|
|
124 |
line := 1.
|
|
125 |
(self newline , [ :stream |
|
|
126 |
start <= stream position
|
|
127 |
ifTrue: [ ^ line ].
|
|
128 |
line := line + 1 ] asParser
|
|
129 |
/ #any asParser) star
|
|
130 |
parse: collection.
|
|
131 |
^ line
|
|
132 |
! !
|
|
133 |
|
|
134 |
!PPToken class methodsFor:'documentation'!
|
|
135 |
|
30
|
136 |
version
|
91
|
137 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPToken.st,v 1.4 2012-12-01 14:27:17 cg Exp $'
|
30
|
138 |
!
|
|
139 |
|
|
140 |
version_CVS
|
91
|
141 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPToken.st,v 1.4 2012-12-01 14:27:17 cg Exp $'
|
30
|
142 |
!
|
|
143 |
|
0
|
144 |
version_SVN
|
30
|
145 |
^ '§Id: PPToken.st 2 2010-12-17 18:44:23Z vranyj1 §'
|
0
|
146 |
! !
|