Class: TRuby::ParserCombinator::TypeParser

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/t_ruby/parser_combinator.rb

Overview

Type Parser - Parse T-Ruby type expressions

Instance Method Summary collapse

Methods included from DSL

#alphanumeric, #chainl, #char, #choice, #digit, #eof, #fail, #float, #identifier, #integer, #lazy, #letter, #lexeme, #literal, #newline, #pure, #quoted_string, #regex, #satisfy, #sequence, #spaces, #spaces1, #string, #whitespace

Constructor Details

#initializeTypeParser

Returns a new instance of TypeParser.



657
658
659
# File 'lib/t_ruby/parser_combinator.rb', line 657

def initialize
  build_parsers
end

Instance Method Details

#parse(input) ⇒ Object



661
662
663
664
665
666
667
668
# File 'lib/t_ruby/parser_combinator.rb', line 661

def parse(input)
  result = @type_expr.parse(input.strip)
  if result.success?
    { success: true, type: result.value, remaining: input[result.position..] }
  else
    { success: false, error: result.error, position: result.position }
  end
end