Module: SyntaxTree::Reflection::Type
- Defined in:
- lib/syntax_tree/reflection.rb
Overview
This module represents the type of the values being passed to attributes of nodes. It is used as part of the documentation of the attributes.
Defined Under Namespace
Classes: ArrayType, TupleType, UnionType
Constant Summary collapse
- CONSTANTS =
SyntaxTree.constants.to_h { [_1, SyntaxTree.const_get(_1)] }
Class Method Summary collapse
Class Method Details
.parse(comment) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/syntax_tree/reflection.rb', line 66 def parse(comment) comment = comment.gsub(/\n/, " ") unless comment.start_with?("[") raise "Comment does not start with a bracket: #{comment.inspect}" end count = 1 found = comment.chars[1..] .find .with_index(1) do |char, index| count += { "[" => 1, "]" => -1 }.fetch(char, 0) break index if count == 0 end # If we weren't able to find the end of the balanced brackets, then # the comment is malformed. if found.nil? raise "Comment does not have balanced brackets: #{comment.inspect}" end parse_type(comment[1...found].strip) end |