Class: LanguageParser::SQLT_NormalState

Inherits:
SQLT_State
  • Object
show all
Defined in:
lib/cgialib/lp/SQLTokenizer.rb

Overview

class : SQLT_NormalState

The default state machine to which all of the other states return.

Instance Method Summary collapse

Constructor Details

#initialize(newstate, addtoken) ⇒ SQLT_NormalState

initialize( newstate, addtoken )

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



254
255
256
257
258
259
260
261
262
263
264
# File 'lib/cgialib/lp/SQLTokenizer.rb', line 254

def initialize( newstate, addtoken )
  
  super( newstate, addtoken )
  
  # This normal state handles adding CodeTokens in the 
  # basic stream (e.g. not in a string). So we have a
  # text buffer.
  
  @text = ""
  
end

Instance Method Details

#next(ch) ⇒ Object

next( ch )

ch - The character

Handles the character in the parsing stream



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/cgialib/lp/SQLTokenizer.rb', line 272

def next( ch )
  
  if ch == "-"
  
    # Start the comment switcher state if we 
    # see a slash
  
    @addtoken.call( CodeToken.new( @text ) )
    @newstate.call( SQLT_Comment )
  
  elsif @@specials[ch]
  
    # If this is a special character (e.g. ;,*,+, etc.)
    # then dump the current token and add the special  
    # characer token
  
    @addtoken.call( CodeToken.new( @text ) )
    @text = ""
  
    @addtoken.call( CodeToken.new( ch ) )
  
  elsif ch == "\'"
  
    # Start the double quote state if we see a
    # double quote
  
    @addtoken.call( CodeToken.new( @text ) )
    @newstate.call( SQLT_DoubleQuote )
  
  elsif ch =~ /\s/

    # Move into the whitespace state if we 
    # see whitespace.  Return true to re-run
    # the parser on this character.
  
    @addtoken.call( CodeToken.new( @text ) )
    @newstate.call( SQLT_WhitespaceTokenizer )
    return false
  
  else
  
    # Otherwise add this character to the buffer
  
    @text += ch
  
  end
  
  # Continue onto the next character
  
  true
  
end