Class: Umwelt::Semantic::Base
- Inherits:
-
Object
- Object
- Umwelt::Semantic::Base
- Extended by:
- Forwardable
- Defined in:
- lib/umwelt/semantic.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #ancestry_path ⇒ Object
- #code ⇒ Object
-
#context ⇒ Object
nil check for case of root node, which has not context.
-
#csymbol ⇒ Object
classified symbol.
-
#initialize(node:) ⇒ Base
constructor
A new instance of Base.
- #label ⇒ Object
-
#path(location: nil) ⇒ Object
default_location defined, for example, in Semantic::Plain::Base or base file from another semantic.
- #s(type, *children) ⇒ Object
- #tail_path ⇒ Object
Constructor Details
#initialize(node:) ⇒ Base
Returns a new instance of Base.
11 12 13 |
# File 'lib/umwelt/semantic.rb', line 11 def initialize(node:) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
9 10 11 |
# File 'lib/umwelt/semantic.rb', line 9 def node @node end |
Instance Method Details
#ancestry_path ⇒ Object
19 20 21 22 23 24 |
# File 'lib/umwelt/semantic.rb', line 19 def ancestry_path ancestry .collect(&:body) .map { |body| underscore(body) } .join '/' end |
#code ⇒ Object
26 27 28 |
# File 'lib/umwelt/semantic.rb', line 26 def code Unparser.unparse(ast) end |
#context ⇒ Object
nil check for case of root node, which has not context
38 39 40 |
# File 'lib/umwelt/semantic.rb', line 38 def context node.context&.semantic(:Plain) end |
#csymbol ⇒ Object
classified symbol
43 44 45 |
# File 'lib/umwelt/semantic.rb', line 43 def csymbol classify(body).to_sym end |
#label ⇒ Object
47 48 49 |
# File 'lib/umwelt/semantic.rb', line 47 def label self.class.name.split('::').last.to_sym end |
#path(location: nil) ⇒ Object
default_location defined, for example, in Semantic::Plain::Base or base file from another semantic
33 34 35 |
# File 'lib/umwelt/semantic.rb', line 33 def path(location: nil) Pathname.pwd / (location || default_location) / tail_path end |
#s(type, *children) ⇒ Object
15 16 17 |
# File 'lib/umwelt/semantic.rb', line 15 def s(type, *children) Parser::AST::Node.new(type, children) end |
#tail_path ⇒ Object
51 52 53 |
# File 'lib/umwelt/semantic.rb', line 51 def tail_path Pathname.new(ancestry_path).sub_ext('.rb') end |