Class: OrigenSTIL::Syntax::Node
- Inherits:
-
AST::Node
- Object
- AST::Node
- OrigenSTIL::Syntax::Node
- Defined in:
- lib/origen_stil/syntax/node.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#number_of_lines ⇒ Object
readonly
Returns the value of attribute number_of_lines.
Instance Method Summary collapse
- #directory ⇒ Object
-
#find(type) ⇒ Object
Returns the first child node of the given type that is found.
-
#find_all(*types) ⇒ Object
Returns an array containing all child nodes of the given type(s).
- #line_number ⇒ Object
- #text_value ⇒ Object
-
#value ⇒ Object
Returns the value at the root of an AST node like this:.
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/origen_stil/syntax/node.rb', line 6 def file @file end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/origen_stil/syntax/node.rb', line 6 def input @input end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
6 7 8 |
# File 'lib/origen_stil/syntax/node.rb', line 6 def interval @interval end |
#number_of_lines ⇒ Object (readonly)
Returns the value of attribute number_of_lines.
6 7 8 |
# File 'lib/origen_stil/syntax/node.rb', line 6 def number_of_lines @number_of_lines end |
Instance Method Details
#directory ⇒ Object
43 44 45 46 47 |
# File 'lib/origen_stil/syntax/node.rb', line 43 def directory if file Pathname.new(file).dirname end end |
#find(type) ⇒ Object
Returns the first child node of the given type that is found
25 26 27 28 |
# File 'lib/origen_stil/syntax/node.rb', line 25 def find(type) nodes = find_all(type) nodes.first end |
#find_all(*types) ⇒ Object
Returns an array containing all child nodes of the given type(s)
31 32 33 |
# File 'lib/origen_stil/syntax/node.rb', line 31 def find_all(*types) Extractor.new.process(self, types) end |
#line_number ⇒ Object
35 36 37 |
# File 'lib/origen_stil/syntax/node.rb', line 35 def line_number input.line_of(interval.first) end |
#text_value ⇒ Object
39 40 41 |
# File 'lib/origen_stil/syntax/node.rb', line 39 def text_value input[interval] end |
#value ⇒ Object
Returns the value at the root of an AST node like this:
node # => (module-def
(module-name
(SCALAR-ID "Instrument"))
node.value # => "Instrument"
No error checking is done and the caller is responsible for calling this only on compatible nodes
18 19 20 21 22 |
# File 'lib/origen_stil/syntax/node.rb', line 18 def value val = children.first val = val.children.first while val.respond_to?(:children) val end |