Class: LanguageParser::SQLT_Comment

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

Overview

class : SQLT_Comment

State object for new style SQL comments (e.g. –)

Instance Method Summary collapse

Constructor Details

#initialize(newstate, addtoken) ⇒ SQLT_Comment

initialize( newstate, addtoken )

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



62
63
64
65
66
67
68
69
70
71
# File 'lib/cgialib/lp/SQLTokenizer.rb', line 62

def initialize( newstate, addtoken )
  
  super( newstate, addtoken )
  
  # Initialize the text buffer with the beginning //
  
  @text = "-"
  @waiting_for_dash = true
  
end

Instance Method Details

#next(ch) ⇒ Object

next( ch )

ch - The character

Handles the character in the parsing stream



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/cgialib/lp/SQLTokenizer.rb', line 79

def next( ch )
  
  if ( @waiting_for_dash && ch != "-" )
  
    @addtoken.call( CommentToken.new( "-" ) )
    @newstate.call( SQLT_NormalState )
    return false
  
  end
  
  @waiting_for_dash = false
  
  # Add the character to the comment text
  
  @text += ch
  
  # Go back to the normal state if we find a return
  
  if ( ch == "\n" )
  
    @addtoken.call( CommentToken.new( @text ) )
    @newstate.call( SQLT_NormalState )
  
  end
  
  # Proceed to the next character
  
  true
  
end