Class: RBI::SigBuilder
- Inherits:
-
ASTVisitor
- Object
- ASTVisitor
- RBI::SigBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/parser.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ SigBuilder
constructor
A new instance of SigBuilder.
- #visit(node) ⇒ Object
- #visit_send(node) ⇒ Object
Methods inherited from ASTVisitor
Constructor Details
#initialize ⇒ SigBuilder
Returns a new instance of SigBuilder.
562 563 564 565 |
# File 'lib/rbi/parser.rb', line 562 def initialize super @current = T.let(Sig.new, Sig) end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
559 560 561 |
# File 'lib/rbi/parser.rb', line 559 def current @current end |
Class Method Details
.build(node) ⇒ Object
552 553 554 555 556 |
# File 'lib/rbi/parser.rb', line 552 def self.build(node) v = SigBuilder.new v.visit_all(node.children[2..-1]) v.current end |
Instance Method Details
#visit(node) ⇒ Object
568 569 570 571 572 573 574 |
# File 'lib/rbi/parser.rb', line 568 def visit(node) return unless node case node.type when :send visit_send(node) end end |
#visit_send(node) ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/rbi/parser.rb', line 577 def visit_send(node) visit(node.children[0]) if node.children[0] name = node.children[1] case name when :abstract @current.is_abstract = true when :override @current.is_override = true when :overridable @current.is_overridable = true when :checked @current.checked = node.children[2].children[0] when :type_parameters node.children[2..-1].each do |child| @current.type_params << child.children[0].to_s end when :params node.children[2].children.each do |child| name = child.children[0].children[0].to_s type = parse_expr(child.children[1]) @current << SigParam.new(name, type) end when :returns @current.return_type = parse_expr(node.children[2]) when :void @current.return_type = nil else raise "#{node.location.line}: Unhandled #{name}" end end |