Class: Token

Inherits:
Object show all
Includes:
Indexable, SourceCodeDumpable
Defined in:
lib/rpdf2txt-rockit/token.rb,
lib/rpdf2txt-rockit/parsetable_generation.rb

Constant Summary collapse

@@empty_array =
[]

Instance Attribute Summary collapse

Attributes included from Indexable

#factory, #index_number

Instance Method Summary collapse

Methods included from SourceCodeDumpable

as_code, as_method_named, as_module_method_named, #create_new, indent_lines, name_hash, #new_of_my_type, #parameter_named, #to_compact_src, #to_src_in_module, #type_to_src

Constructor Details

#initialize(aString, aStringOrRegexpOrTokenRegexp = "", *options) ⇒ Token

Returns a new instance of Token.



67
68
69
70
# File 'lib/rpdf2txt-rockit/token.rb', line 67

def initialize(aString, aStringOrRegexpOrTokenRegexp = "", *options)
  @name, @regexp = aString, TokenRegexp.new(aStringOrRegexpOrTokenRegexp)
  parse_options(options)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



65
66
67
# File 'lib/rpdf2txt-rockit/token.rb', line 65

def name
  @name
end

#regexpObject (readonly)

Returns the value of attribute regexp.



64
65
66
# File 'lib/rpdf2txt-rockit/token.rb', line 64

def regexp
  @regexp
end

#skipObject (readonly)

Returns the value of attribute skip.



64
65
66
# File 'lib/rpdf2txt-rockit/token.rb', line 64

def skip
  @skip
end

Instance Method Details

#==(other) ⇒ Object



87
88
89
90
91
92
# File 'lib/rpdf2txt-rockit/token.rb', line 87

def ==(other)
  other.class == self.class and 
    other.name == name and
    other.regexp.inspect == regexp.inspect and
    other.skip == skip
end

#create_tree(lexeme, position) ⇒ Object



103
104
105
106
107
# File 'lib/rpdf2txt-rockit/token.rb', line 103

def create_tree(lexeme, position)
  t = SyntaxTree.new(@name, ["lexeme", "value"], [value(lexeme), lexeme])
  t.attributes[:position] = position
  t
end

#derives_epsilon?Boolean

Returns:

  • (Boolean)


158
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 158

def derives_epsilon?; false; end

#hashObject



72
73
74
# File 'lib/rpdf2txt-rockit/token.rb', line 72

def hash
  @hashvalue || (@hashvalue = [self.class, @name, @regexp, @skip].hash)
end

#inspectObject



117
118
119
120
121
# File 'lib/rpdf2txt-rockit/token.rb', line 117

def inspect
  name || regexp.inspect
  #osrc = options_to_src
  #"#{name} = #{regexp.inspect} #{osrc.length>0 ? '['+osrc+']' : ''}"
end

#match(aString) ⇒ Object



94
95
96
# File 'lib/rpdf2txt-rockit/token.rb', line 94

def match(aString)
  @regexp.match aString
end

#nonkernel_itemsObject



154
155
156
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 154

def nonkernel_items
  @@empty_array
end

#nonterminal?Boolean

Returns:

  • (Boolean)


149
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 149

def nonterminal?; false; end

#parse_options(options) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/rpdf2txt-rockit/token.rb', line 76

def parse_options(options)
  option_names = options.map do |option| 
    if option.kind_of? Symbol
	option.id2name.downcase
    else
	option.downcase
    end
  end
  @skip = true if option_names.include? "skip"
end

#terminal?Boolean

Returns:

  • (Boolean)


150
# File 'lib/rpdf2txt-rockit/parsetable_generation.rb', line 150

def terminal?; true; end

#to_src(assignToName = nil, nameHash = {}) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/rpdf2txt-rockit/token.rb', line 109

def to_src(assignToName = nil, nameHash = {})
  if skip
    assign_to(assignToName, new_of_my_type(name, as_code(regexp.to_src), :Skip))
  else
    assign_to(assignToName, new_of_my_type(name, as_code(regexp.to_src)))
  end
end

#value(lexeme) ⇒ Object



98
99
100
101
# File 'lib/rpdf2txt-rockit/token.rb', line 98

def value(lexeme)
  # TODO: Add blocks that map lexeme's to values.
  lexeme
end