Class: Rucoa::ParserBuilder

Inherits:
Parser::Builders::Default
  • Object
show all
Defined in:
lib/rucoa/parser_builder.rb

Constant Summary collapse

NODE_CLASS_BY_TYPE =
{
  arg: Nodes::ArgNode,
  args: Nodes::ArgsNode,
  begin: Nodes::BeginNode,
  block: Nodes::BlockNode,
  case: Nodes::CaseNode,
  casgn: Nodes::CasgnNode,
  cbase: Nodes::CbaseNode,
  class: Nodes::ClassNode,
  const: Nodes::ConstNode,
  csend: Nodes::SendNode,
  cvar: Nodes::CvarNode,
  cvasgn: Nodes::CvasgnNode,
  def: Nodes::DefNode,
  defs: Nodes::DefNode,
  ensure: Nodes::EnsureNode,
  for: Nodes::ForNode,
  gvar: Nodes::GvarNode,
  gvasgn: Nodes::GvasgnNode,
  if: Nodes::IfNode,
  ivar: Nodes::IvarNode,
  ivasgn: Nodes::IvasgnNode,
  kwarg: Nodes::ArgNode,
  kwbegin: Nodes::BeginNode,
  lvar: Nodes::LvarNode,
  lvasgn: Nodes::LvasgnNode,
  module: Nodes::ModuleNode,
  resbody: Nodes::ResbodyNode,
  rescue: Nodes::RescueNode,
  sclass: Nodes::SclassNode,
  send: Nodes::SendNode,
  str: Nodes::StrNode,
  super: Nodes::SendNode,
  sym: Nodes::SymNode,
  until: Nodes::UntilNode,
  when: Nodes::WhenNode,
  while: Nodes::WhileNode,
  zsuper: Nodes::SendNode
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.node_class_for(type) ⇒ Class

Parameters:

  • type (Symbol)

Returns:

  • (Class)


50
51
52
# File 'lib/rucoa/parser_builder.rb', line 50

def node_class_for(type)
  NODE_CLASS_BY_TYPE.fetch(type, Nodes::Base)
end

Instance Method Details

#n(type, children, source_map) ⇒ Object

Note:

Override.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rucoa/parser_builder.rb', line 56

def n(
  type,
  children,
  source_map
)
  self.class.node_class_for(type).new(
    type,
    children,
    location: source_map
  )
end