class Regextest::Front::BracketScanner

Constants

LexCodeLiteral

A table for lexical analysis of elements (Not strict analisis here.)

LexTable

Public Class Methods

new(options = nil) click to toggle source
# File lib/regextest/front/bracket-scanner.rb, line 65
def initialize(options = nil)
  reg_options = options[:reg_options]

  @lex_table = LexTable
  whole_lex = @lex_table.map{|lex| "(?<#{lex[0]}>" + lex[1].source + ")"}.join('|')
  @reg = /^#{whole_lex}/mx
end
test(test_string, reg_options = 0) click to toggle source

method for testing

# File lib/regextest/front/bracket-scanner.rb, line 99
def self.test(test_string, reg_options = 0)
  puts "String: #{test_string.inspect}"
  results = Regextest::Front::BracketScanner.new().scan(test_string)
end

Public Instance Methods

scan(test_string) click to toggle source
# File lib/regextest/front/bracket-scanner.rb, line 74
def scan(test_string)
  results = []
  match_string = test_string
  match_offset = 0
  while (md = @reg.match(match_string))
    scan_offset = @lex_table.index{|elem| md[elem[0]]}
    name = @lex_table[scan_offset][0]
    if(name != :LEX_ERROR)
      lex_word = md[name]
      match_length = md.end(0)
      results.push [name, [lex_word, match_offset, match_length]]
      match_string = md.post_match
      match_offset += match_length
    else
      offset = test_string.index(match_string)
      raise "bracket syntax error, offset #{offset}, \n" +
            test_string + "\n" +
            (" "*offset)+"^"
    end
  end
  results.push [false, nil]
  results
end