Class: OrigenVerilog::Node
- Inherits:
-
AST::Node
- Object
- AST::Node
- OrigenVerilog::Node
- Defined in:
- lib/origen_verilog/node.rb
Direct Known Subclasses
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.
5 6 7 |
# File 'lib/origen_verilog/node.rb', line 5 def file @file end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
5 6 7 |
# File 'lib/origen_verilog/node.rb', line 5 def input @input end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
5 6 7 |
# File 'lib/origen_verilog/node.rb', line 5 def interval @interval end |
#number_of_lines ⇒ Object (readonly)
Returns the value of attribute number_of_lines.
5 6 7 |
# File 'lib/origen_verilog/node.rb', line 5 def number_of_lines @number_of_lines end |
Instance Method Details
#directory ⇒ Object
42 43 44 45 46 |
# File 'lib/origen_verilog/node.rb', line 42 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
24 25 26 27 |
# File 'lib/origen_verilog/node.rb', line 24 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)
30 31 32 |
# File 'lib/origen_verilog/node.rb', line 30 def find_all(*types) Extractor.new.process(self, types) end |
#line_number ⇒ Object
34 35 36 |
# File 'lib/origen_verilog/node.rb', line 34 def line_number input.line_of(interval.first) end |
#text_value ⇒ Object
38 39 40 |
# File 'lib/origen_verilog/node.rb', line 38 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
17 18 19 20 21 |
# File 'lib/origen_verilog/node.rb', line 17 def value val = children.first val = val.children.first while val.respond_to?(:children) val end |