Class: LanguageParser::SQLT_DoubleQuote

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

Overview

class : SQLT_DoubleQuote

Handles parsing strings

Instance Method Summary collapse

Constructor Details

#initialize(newstate, addtoken) ⇒ SQLT_DoubleQuote

initialize( newstate, addtoken )

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



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cgialib/lp/SQLTokenizer.rb', line 124

def initialize( newstate, addtoken )
  
  super( newstate, addtoken )
  
  # Start the text buffer with the beginning double quote
  
  @text = "\'"
  
  @waiting_for_end_apostrophe = false
  
  @waiting_for_apostrophe = true
  
end

Instance Method Details

#next(ch) ⇒ Object

next( ch )

ch - The character

Handles the character in the parsing stream



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/cgialib/lp/SQLTokenizer.rb', line 144

def next( ch )
  
  if ( @waiting_for_apostrophe )
  
    if ( ch == "\'" )
  
      @token += ch
      @waiting_for_apostrophe = false
      return true
  
    else
  
      @addtoken.call( CodeToken.new( "\'" ) )
      @newstate.call( SQLT_NormalState )
      return false
  
    end
  
  end
  
  # Add this character to the text buffer
  
  @text += ch
  
  if ( @waiting_for_end_apostrophe && ch == "\'" )
  
    @addtoken.call( CodeToken.new( @text ) )
    @newstate.call( SQLT_NormalState )
  
  end
  
  @waiting_for_end_apostrophe = ( ch == "\'" )
  
  # Proceed to the next character
  
  true
  
end