PPToken.st
changeset 30 6d6315787d46
parent 4 90de244a7fa2
child 91 ed96c98bff4a
equal deleted inserted replaced
29:2235aaee7da6 30:6d6315787d46
     3 Object subclass:#PPToken
     3 Object subclass:#PPToken
     4 	instanceVariableNames:'collection start stop'
     4 	instanceVariableNames:'collection start stop'
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'PetitParser-Core'
     7 	category:'PetitParser-Core'
     8 !
       
     9 
       
    10 PPToken comment:'PPToken represents a parsed part of the input stream. Contrary to a simple String it remembers where it came from, the original collection and its start and stop position.
       
    11 Instance Variables:
       
    12 	collection      <SequenceableCollection>        The collection this token comes from.
       
    13 	start   <Integer>       The start position in the collection.
       
    14 	stop    <Integer>       The stop position in the collection.'
       
    15 !
     8 !
    16 
     9 
    17 
    10 
    18 !PPToken class methodsFor:'instance creation'!
    11 !PPToken class methodsFor:'instance creation'!
    19 
    12 
    24 on: aSequenceableCollection
    17 on: aSequenceableCollection
    25 	^ self on: aSequenceableCollection start: 1 stop: aSequenceableCollection size
    18 	^ self on: aSequenceableCollection start: 1 stop: aSequenceableCollection size
    26 !
    19 !
    27 
    20 
    28 on: aSequenceableCollection start: aStartInteger stop: aStopInteger
    21 on: aSequenceableCollection start: aStartInteger stop: aStopInteger
    29 	^ self basicNew
    22 	^ self basicNew 
    30 		initializeOn: aSequenceableCollection
    23 		initializeOn: aSequenceableCollection
    31 		start: aStartInteger stop: aStopInteger
    24 		start: aStartInteger stop: aStopInteger
    32 ! !
    25 ! !
    33 
    26 
    34 !PPToken methodsFor:'accessing'!
    27 !PPToken methodsFor:'accessing'!
    51 	^ start
    44 	^ start
    52 !
    45 !
    53 
    46 
    54 stop
    47 stop
    55 	"Answer the stop position of this token in the underlying collection."
    48 	"Answer the stop position of this token in the underlying collection."
    56 
    49 	
    57 	^ stop
    50 	^ stop
    58 !
    51 !
    59 
    52 
    60 value
    53 value
    61 	"Answer the contents of this token."
    54 	"Answer the contents of this token."
   105 
    98 
   106 !PPToken methodsFor:'querying'!
    99 !PPToken methodsFor:'querying'!
   107 
   100 
   108 column
   101 column
   109 	"Answer the column number of this token in the underlying collection."
   102 	"Answer the column number of this token in the underlying collection."
   110 
   103 	
   111 	| position |
   104 	| position |
   112 	position := 0.
   105 	position := 0.
   113 	(self newline , [ :stream |
   106 	(self newline , [ :stream |
   114 		start <= stream position
   107 		start <= stream position
   115 			ifTrue: [ ^ start - position ].
   108 			ifTrue: [ ^ start - position ].
   119 	 ^ start - position
   112 	 ^ start - position
   120 !
   113 !
   121 
   114 
   122 line
   115 line
   123 	"Answer the line number of this token in the underlying collection."
   116 	"Answer the line number of this token in the underlying collection."
   124 
   117 	
   125 	| line |
   118 	| line |
   126 	line := 1.
   119 	line := 1.
   127 	(self newline , [ :stream |
   120 	(self newline , [ :stream |
   128 		start <= stream position
   121 		start <= stream position
   129 			ifTrue: [ ^ line ].
   122 			ifTrue: [ ^ line ].
   133 	^ line
   126 	^ line
   134 ! !
   127 ! !
   135 
   128 
   136 !PPToken class methodsFor:'documentation'!
   129 !PPToken class methodsFor:'documentation'!
   137 
   130 
       
   131 version
       
   132     ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPToken.st,v 1.3 2012-05-04 22:03:13 vrany Exp $'
       
   133 !
       
   134 
       
   135 version_CVS
       
   136     ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPToken.st,v 1.3 2012-05-04 22:03:13 vrany Exp $'
       
   137 !
       
   138 
   138 version_SVN
   139 version_SVN
   139     ^ '$Id: PPToken.st,v 1.2 2012-01-13 11:22:50 cg Exp $'
   140     ^ '§Id: PPToken.st 2 2010-12-17 18:44:23Z vranyj1 §'
   140 ! !
   141 ! !