class YARD::Tags::TypesExplainer::Parser
@private
Constants
- TOKENS
Public Class Methods
new(string)
click to toggle source
# File lib/yard/tags/types_explainer.rb, line 117 def initialize(string) @scanner = StringScanner.new(string) end
parse(string)
click to toggle source
# File lib/yard/tags/types_explainer.rb, line 113 def self.parse(string) new(string).parse end
Public Instance Methods
parse()
click to toggle source
# File lib/yard/tags/types_explainer.rb, line 121 def parse types = [] type = nil name = nil loop do found = false TOKENS.each do |token_type, match| # TODO: cleanup this code. # rubocop:disable Lint/AssignmentInCondition next unless (match.nil? && @scanner.eos?) || (match && token = @scanner.scan(match)) found = true case token_type when :type_name raise SyntaxError, "expecting END, got name '#{token}'" if name name = token when :type_next raise SyntaxError, "expecting name, got '#{token}' at #{@scanner.pos}" if name.nil? type = Type.new(name) unless type types << type type = nil name = nil when :fixed_collection_start, :collection_start name ||= "Array" klass = token_type == :collection_start ? CollectionType : FixedCollectionType type = klass.new(name, parse) when :hash_collection_start name ||= "Hash" type = HashCollectionType.new(name, parse, parse) when :hash_collection_next, :hash_collection_end, :fixed_collection_end, :collection_end, :parse_end raise SyntaxError, "expecting name, got '#{token}'" if name.nil? type = Type.new(name) unless type types << type return types end end raise SyntaxError, "invalid character at #{@scanner.peek(1)}" unless found end end