class NodeClass

Attributes

source_text[RW]

The 'text_value' method can be used to read the parse tree as Treetop originally read it. The 'source_text' method returns redefined value or falls back to original text_value if none was set.

Public Instance Methods

assignment?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 55
def assignment?; false end
block?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 43
def block?; false end
branch?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 42
def branch?; false end
comment?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 49
def comment?; false end
datatype?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 53
def datatype?; false end
else?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 59
def else?; false; end
expression?() click to toggle source

overridden in subclasses

# File lib/piggly/parser/nodes.rb, line 41
def expression?; false end
for?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 46
def for?; false end
identifier?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 54
def identifier?; false end
if?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 58
def if?; false; end
indent(method = nil) click to toggle source
# File lib/piggly/parser/nodes.rb, line 63
def indent(method = nil)
  if method and respond_to?(method)
    send(method).text_value[/\n[\t ]*\z/]
  else
    text_value[/\n[\t ]*\z/]
  end || ""
end
keyword?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 61
def keyword?; false; end
label?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 60
def label?; false; end
loop?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 45
def loop?; false end
named?(label) click to toggle source

True if node is called `label` by the parent node

# File lib/piggly/parser/nodes.rb, line 72
def named?(label)
  if p = parent
    p.respond_to?(label) and p.send(label).equal?(self)
  end
end
sql?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 56
def sql?; false end
statement?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 57
def statement?; false; end
string?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 52
def string?; false end
stub?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 44
def stub?; false end
style() click to toggle source
# File lib/piggly/parser/nodes.rb, line 48
def style; nil end
tag(prefix = nil, id = nil) click to toggle source

Return a newly created Tag value, but only the tag.id is attached to the tree. The reason that is we maintain the Tags in a separate collection (to avoid a full traversal just to get the list of tags later), and we can retrieve the Tag associated with this node by its tag_id.

# File lib/piggly/parser/nodes.rb, line 22
def tag(prefix = nil, id = nil)
  unless defined? @tag_id
    if named?(:body)
      Piggly::Tags::BlockTag.new(prefix, id)
    else
      Piggly::Tags::EvaluationTag.new(prefix, id)
    end.tap{|tag| @tag_id = tag.id }
  end
end
tag_id() click to toggle source
# File lib/piggly/parser/nodes.rb, line 32
def tag_id
  @tag_id or raise RuntimeError, "Node is not tagged"
end
tagged?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 36
def tagged?
  defined? @tag_id
end
token?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 51
def token?; false end
while?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 47
def while?; false end
whitespace?() click to toggle source
# File lib/piggly/parser/nodes.rb, line 50
def whitespace?; false end