Class: Atomy::Grammar::AST::Word

Inherits:
Node show all
Defined in:
lib/atomy/grammar.rb,
lib/atomy/node/meta.rb,
lib/atomy/node/pretty.rb,
lib/atomy/node/equality.rb,
lib/atomy/node/constructable.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#accept, #attributes, basename, #children, #each_child, #through

Constructor Details

#initialize(text) ⇒ Word

Returns a new instance of Word.



161
162
163
# File 'lib/atomy/grammar.rb', line 161

def initialize(text)
  @text = text
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



164
165
166
# File 'lib/atomy/grammar.rb', line 164

def text
  @text
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
# File 'lib/atomy/node/equality.rb', line 50

def ==(other)
  super || other.is_a?(self.class) && @text == other.text
end

#construct(gen) ⇒ Object



80
81
82
83
84
# File 'lib/atomy/node/constructable.rb', line 80

def construct(gen)
  push_node(gen, :Word)
  gen.push_literal(@text)
  gen.send(:new, 1)
end

#each_attribute {|:text, @text| ... } ⇒ Object

Yields:



111
112
113
# File 'lib/atomy/node/meta.rb', line 111

def each_attribute
  yield :text, @text
end

#to_sObject



47
48
49
50
# File 'lib/atomy/node/pretty.rb', line 47

def to_s
  word = @text.to_s
  word[0] + word[1..-1].tr("_", "-")
end