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.
503 504 505 506 |
# File 'lib/rbi/parser.rb', line 503 def initialize super @current = T.let(Sig.new, Sig) end |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
500 501 502 |
# File 'lib/rbi/parser.rb', line 500 def current @current end |
Class Method Details
.build(node) ⇒ Object
493 494 495 496 497 |
# File 'lib/rbi/parser.rb', line 493 def self.build(node) v = SigBuilder.new v.visit_all(node.children[2..-1]) v.current end |
Instance Method Details
#visit(node) ⇒ Object
509 510 511 512 513 514 515 |
# File 'lib/rbi/parser.rb', line 509 def visit(node) return unless node case node.type when :send visit_send(node) end end |
#visit_send(node) ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/rbi/parser.rb', line 518 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 |