Class: RBS::Inline::AST::Annotations::Use
- Defined in:
- lib/rbs/inline/ast/annotations.rb
Overview
‘# @rbs use [USES]`
Instance Attribute Summary collapse
-
#clauses ⇒ Object
readonly
: Array.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(tree, source) ⇒ Use
constructor
A new instance of Use.
Constructor Details
#initialize(tree, source) ⇒ Use
Returns a new instance of Use.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/rbs/inline/ast/annotations.rb', line 463 def initialize(tree, source) @tree = tree @source = source @clauses = [] tree.nth_tree!(1).tap do |use_tree| _, *clause_pairs = use_tree.non_trivia_trees clause_pairs.each_slice(2) do |clause, _comma| if clause.is_a?(Tree) *tokens, last_token = clause.non_trivia_trees token_strs = tokens.map do |tok| if tok.is_a?(Array) tok[1] else raise end end case last_token when Array # `*` clause namespace = Namespace(token_strs.join) @clauses << RBS::AST::Directives::Use::WildcardClause.new( namespace: namespace, location: nil ) when Tree, nil if last_token if new_name_token = last_token.nth_token(1) new_name = new_name_token[1].to_sym end end typename = TypeName(token_strs.join) @clauses << RBS::AST::Directives::Use::SingleClause.new( type_name: typename, new_name: new_name, location: nil ) end end end end end |
Instance Attribute Details
#clauses ⇒ Object (readonly)
: Array
460 461 462 |
# File 'lib/rbs/inline/ast/annotations.rb', line 460 def clauses @clauses end |