Class: LanguageParser::CT_DoubleQuote

Inherits:
CT_State
  • Object
show all
Defined in:
lib/cgialib/lp/CTokenizer.rb

Overview

class : CT_DoubleQuote

Handles parsing strings

Instance Method Summary collapse

Constructor Details

#initialize(newstate, addtoken) ⇒ CT_DoubleQuote

initialize( newstate, addtoken )

newstate - A method to be called to change state addtoken - The method to be called to add a token



177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/cgialib/lp/CTokenizer.rb', line 177

def initialize( newstate, addtoken )
  
  super( newstate, addtoken )
  
  # Start the text buffer with the beginning double quote
  
  @text = "\""
  
  # Set the escaped flag to false.  This will go true when
  # we see a '\'
  
  @escaped = false
  
end

Instance Method Details

#next(ch) ⇒ Object

next( ch )

ch - The character

Handles the character in the parsing stream



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/cgialib/lp/CTokenizer.rb', line 198

def next( ch )
  
  # Add this character to the text buffer
  
  @text += ch
  
  # If the character is a double qoute and we are not
  # escape then go back to the normal state and add
  # the string token to the array
  
  if ( ch == "\"" && ! @escaped )
  
    @addtoken.call( CodeToken.new( @text ) )
    @newstate.call( CT_NormalState )
  
  end
  
  # Set escaped to true if we see a    
  @escaped = ( ch == "\\" )
  
  # Proceed to the next character
  
  true
  
end