class Rutile::Lang

Public Class Methods

new() click to toggle source
# File lib/rutile/lang.rb, line 6
def initialize
    @tokens = []
    @nfas = []
    @symbols = []
    @id = 0
    @nfa = nil
end

Public Instance Methods

add_file(file, back = false) click to toggle source
# File lib/rutile/lang.rb, line 38
def add_file(file, back = false)
    if back
        @parser.file_stack.unshift file
    else
        @parser.inc_stack file
    end
end
parse(files) click to toggle source
# File lib/rutile/lang.rb, line 25
def parse(files)
    construct_nfa if @nfa.nil?
    @parser = Parser.new(@nfa, files)
    @parser.parse.each do |token|
        id     = token.type.min
        value  = @tokens[id].call(token.string)
        symbol = @symbols[id]
        if symbol != :ignore
            #feed it to the grammar thing
        end
    end
end
run(files = ARGV) click to toggle source
# File lib/rutile/lang.rb, line 46
def run(files = ARGV)
    if files.nil? || files == []
        files = [STDIN]
    end
    parse files
end
tok(regex, symbol = :ignore, &block) click to toggle source
# File lib/rutile/lang.rb, line 14
def tok(regex, symbol = :ignore, &block)
    if block.nil?
        block = Proc.new {|x|}
    end
    new_nfa = NFA::to_nfa(regex, @id)
    @symbols << symbol
    @nfas << new_nfa
    @tokens.append(block)
    @id += 1
end

Private Instance Methods

construct_nfa() click to toggle source
# File lib/rutile/lang.rb, line 55
def construct_nfa
    @nfa = @nfas.shift
    @nfas.each {|n| @nfa.or n}
    @nfas = nil
end