class Metasm::Preprocessor::Token

a token, as returned by the preprocessor

Attributes

expanded_from[RW]

a list of token this on is expanded from (Preprocessor macro expansion)

raw[RW]

the raw string that gave this token

type[RW]

the token type: :space, :eol, :quoted, :string, :punct, …

value[RW]

the interpreted value of the token (Integer for an int, etc)

Public Class Methods

new(backtrace) click to toggle source
# File metasm/preprocessor.rb, line 37
def initialize(backtrace)
        @backtrace = backtrace
        @value = nil
        @raw = ''
end

Public Instance Methods

dup() click to toggle source
# File metasm/preprocessor.rb, line 56
def dup
        n = self.class.new(backtrace)
        n.type = @type
        n.value = @value.kind_of?(String) ? @value.dup : @value
        n.raw = @raw.dup
        n.expanded_from = @expanded_from.dup if defined? @expanded_from
        n
end
exception(msg='syntax error') click to toggle source

used when doing 'raise tok, “foo”' raises a ParseError, adding backtrace information

# File metasm/preprocessor.rb, line 45
def exception(msg='syntax error')
        msgh = msg.to_s
        if msg
                msgh << ' near '
                expanded_from.to_a.each { |ef| msgh << ef.exception(nil).message << " expanded to \n\t"  }
        end
        msgh << ((@raw.length > 35) ? (@raw[0..10] + '<...>' + @raw[-10..-1]).inspect : @raw.inspect)
        msgh << " at " << backtrace_str
        ParseError.new msgh
end