Class: LanguageParser::CT_NewComment

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

Overview

class : CT_NewComment

State object for new style C comments (e.g. //)

Instance Method Summary collapse

Constructor Details

#initialize(newstate, addtoken) ⇒ CT_NewComment

initialize( newstate, addtoken )

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



126
127
128
129
130
131
132
133
134
# File 'lib/cgialib/lp/CTokenizer.rb', line 126

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

Instance Method Details

#next(ch) ⇒ Object

next( ch )

ch - The character

Handles the character in the parsing stream



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cgialib/lp/CTokenizer.rb', line 142

def next( ch )
  
  # 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( CT_NormalState )
  
  end
  
  # Proceed to the next character
  
  true
  
end