Class: TypedRb::TypeSignature::Parser

Inherits:
Object
  • Object
show all
Includes:
TokenProcessor, TypeProcessor
Defined in:
lib/typed/type_signature/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TypeProcessor

#block_arg?, #parse_binding, #parse_block_arg, #parse_end_of_binding, #parse_end_of_function, #parse_new_type, #parse_next_elem, #parse_start_of_type, #parse_variable_binding

Methods included from TokenProcessor

#group_tokens, #transform_function_tokens, #transform_nested_function, #variable_group?

Constructor Details

#initialize(method_info = {}) ⇒ Parser

Returns a new instance of Parser.



169
170
171
172
173
174
175
# File 'lib/typed/type_signature/parser.rb', line 169

def initialize(method_info = {})
  @method_info = method_info
  @current_type = []
  @current_function = []
  @stack = []
  @in_binding = false
end

Instance Attribute Details

#method_infoObject (readonly)

Returns the value of attribute method_info.



167
168
169
# File 'lib/typed/type_signature/parser.rb', line 167

def method_info
  @method_info
end

Class Method Details

.parse(expr, method_info = {}) ⇒ Object



163
164
165
# File 'lib/typed/type_signature/parser.rb', line 163

def self.parse(expr, method_info = {})
  (@parser || Parser.new(method_info)).parse(expr)
end

Instance Method Details

#parse(expr) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/typed/type_signature/parser.rb', line 177

def parse(expr)
  @input_expression = expr
  expr = sanitize_input(expr)
  expr.each_char { |elem| parse_next_char(elem) }
  build_final_signature
rescue TypedRb::TypeSignature::ParsingError => e
  raise e
rescue StandardError => e
  raise TypedRb::TypeSignature::ParsingError.new(expr, e.message)
end