Class: LanguageParser::CT_OldComment

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

Overview

class : CT_OldComment

Handles parsing an old-style C comment (e.g. /* … */ )

Instance Method Summary collapse

Constructor Details

#initialize(newstate, addtoken) ⇒ CT_OldComment

initialize( newstate, addtoken )

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

Intializes the old-style comment state object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cgialib/lp/CTokenizer.rb', line 65

def initialize( newstate, addtoken )
  
  super( newstate, addtoken )
  
  # Initialize the text with the beginning /*
  
  @text = "/*"
  
  # True if the last character was a star
  
  @last_was_star = false
  
end

Instance Method Details

#next(ch) ⇒ Object

next( ch )

ch - The character

Handles the character in the parsing stream



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/cgialib/lp/CTokenizer.rb', line 85

def next( ch )
  
  # Add this character to the comment
  
  @text += ch
  
  # See if we have a '/' if the last character was a star.
  # If that is the case then return to normal parsing
  # and add the comment token to the token array.
  
  if ( ch == "/" && @last_was_star )
  
    @addtoken.call( CommentToken.new( @text ) )
    @newstate.call( CT_NormalState )
  
  end
  
  # Set the last_was_star to true if we see a star
  
  @last_was_star = ( ch == "*" )
  
  # Continue onto the next character
  
  true
  
end