Parent

Methods

Class/Module Index [+]

Quicksearch

JGrep::Scanner

Attributes

arguments[RW]
token_index[RW]

Public Class Methods

new(arguments) click to toggle source
# File lib/parser/scanner.rb, line 5
def initialize(arguments)
    @token_index = 0
    @arguments = arguments
end

Public Instance Methods

get_token() click to toggle source

Scans the input string and identifies single language tokens

# File lib/parser/scanner.rb, line 11
def get_token
    if @token_index >= @arguments.size
        return nil
    end

    begin
        case @arguments.split("")[@token_index]
            when "["
                return "statement", gen_substatement

            when "]"
                return "]"

            when "("
                return "(", "("

            when ")"
                return ")", ")"

            when "n"
                if (@arguments.split("")[@token_index + 1] == "o") && (@arguments.split("")[@token_index + 2] == "t") && ((@arguments.split("")[@token_index + 3] == " ") || (@arguments.split("")[@token_index + 3] == "("))
                    @token_index += 2
                    return "not", "not"
                else
                    gen_statement
                end

            when "!"
                return "not", "not"

            when "a"
                if (@arguments.split("")[@token_index + 1] == "n") && (@arguments.split("")[@token_index + 2] == "d") && ((@arguments.split("")[@token_index + 3] == " ") || (@arguments.split("")[@token_index + 3] == "("))
                    @token_index += 2
                    return "and", "and"
                else
                    gen_statement
                end

            when "&"
                if(@arguments.split("")[@token_index +1] == "&")
                    @token_index +=1
                    return "and", "and"
                else
                    gen_statement
                end

            when "o"
                if (@arguments.split("")[@token_index + 1] == "r") && ((@arguments.split("")[@token_index + 2] == " ") || (@arguments.split("")[@token_index + 2] == "("))
                    @token_index += 1
                    return "or", "or"
                else
                    gen_statement
                end

            when "|"
                if(@arguments.split("")[@token_index +1] == "|")
                    @token_index +=1
                    return "or", "or"
                else
                    gen_statement
                end

            when "+"
                value = ""
                i = @token_index + 1

                begin
                    value +=  @arguments.split("")[i]
                    i += 1
                end until (i >= @arguments.size)  || (@arguments.split("")[i] =~ /\s|\)/)

                @token_index = i - 1
                return "+", value

            when "-"
                value = ""
                i = @token_index + 1

                begin
                    value +=  @arguments.split("")[i]
                    i += 1
                end until (i >= @arguments.size)  || (@arguments.split("")[i] =~ /\s|\)/)

                @token_index = i - 1
                return "-", value


            when " "
                return " ", " "

            else
                gen_statement
        end
    end
rescue NoMethodError => e
    raise "Error. Expression cannot be parsed."
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.