Class: Bade::AST::NodeRegistrator
- Defined in:
- lib/bade/ast/node_registrator.rb
Class Method Summary collapse
-
.create(type, parent, lineno: nil, filename: nil) ⇒ Bade::AST::Node
Method to create node backing instance.
-
.register_type(klass, type) ⇒ nil
Method to map some node type to backing node class.
- .registered_types ⇒ Hash<Symbol, Class>
Class Method Details
.create(type, parent, lineno: nil, filename: nil) ⇒ Bade::AST::Node
Method to create node backing instance
41 42 43 44 45 46 47 |
# File 'lib/bade/ast/node_registrator.rb', line 41 def create(type, parent, lineno: nil, filename: nil) klass = registered_types[type] raise ::KeyError, "Undefined node type #{type.inspect}" if klass.nil? klass.new(type, parent, lineno: lineno, filename: filename) end |
.register_type(klass, type) ⇒ nil
Method to map some node type to backing node class
28 29 30 31 32 |
# File 'lib/bade/ast/node_registrator.rb', line 28 def register_type(klass, type) raise StandardError, "Class #{klass} should be subclass of #{Node}" unless klass <= Node registered_types[type] = klass end |
.registered_types ⇒ Hash<Symbol, Class>
17 18 19 |
# File 'lib/bade/ast/node_registrator.rb', line 17 def registered_types @registered_types ||= {} end |