Class: Rules::Lexical

Inherits:
Object
  • Object
show all
Defined in:
lib/rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/rules.rb', line 5

def errors
  @errors
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/rules.rb', line 4

def result
  @result
end

Instance Method Details

#analyze(text, filename) ⇒ Object

Разбор на лексемы



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/rules.rb', line 174

def analyze (text, filename)
  @p = 0
  @l = 1
  @t = text + "\n\x0\n" 
  # Удаление блочных комментариев
  # @t.gsub!(/\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\//, '')
  # Удаление строчных комментариев
  # @t.gsub!(/\-\-.*\n/, '') 

  @result = []
  @errors = []
  loop do
    lexem = get_lexem
    break if lexem.nil?
    break if lexem[:lexem] == :end
    lexem[:filename] = filename
    if lexem[:lexem] == :lexical_error
      @errors << {
        :message => @error_msg[:incorrect_lexem],
        :lexem   => lexem } if @errors.length < 5
    else
      @result << lexem 
    end
  end
end

#set_progress_callback(classp, mth) ⇒ Object



199
200
201
202
# File 'lib/rules.rb', line 199

def set_progress_callback(classp, mth)
  @cls = classp
  @mth = mth
end