class Mutest::Expression::Parser

Public Instance Methods

call(input) click to toggle source

Parse input into expression or raise

@param [String] syntax

@return [Expression]

if expression is valid

@raise [ParserError]

otherwise
# File lib/mutest/expression/parser.rb, line 25
def call(input)
  try_parse(input) or raise InvalidExpressionError, "Expression: #{input.inspect} is not valid"
end
try_parse(input) click to toggle source

Try to parse input into expression

@param [String] input

@return [Expression]

if expression is valid

@return [nil]

otherwise
# File lib/mutest/expression/parser.rb, line 38
def try_parse(input)
  expressions = expressions(input)
  case expressions.length
  when 0 # rubocop:disable Lint/EmptyWhen
  when 1
    Util.one(expressions)
  else
    raise AmbiguousExpressionError, "Ambiguous expression: #{input.inspect}"
  end
end

Private Instance Methods

expressions(input) click to toggle source

Expressions parsed from input

@param [String] input

@return [Array<Expression>]

if expressions can be parsed from input
# File lib/mutest/expression/parser.rb, line 57
def expressions(input)
  types.each_with_object([]) do |type, aggregate|
    expression = type.try_parse(input)
    aggregate << expression if expression
  end
end