Class: Mutant::Expression::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/expression/parser.rb

Defined Under Namespace

Classes: AmbiguousExpressionError, InvalidExpressionError, ParserError

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Expression

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse input into expression or raise

Parameters:

  • syntax (String)

Returns:

Raises:



27
28
29
# File 'lib/mutant/expression/parser.rb', line 27

def call(input)
  try_parse(input) or fail InvalidExpressionError, "Expression: #{input.inspect} is not valid"
end

#try_parse(input) ⇒ Expression?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Try to parse input into expression

Parameters:

  • input (String)

Returns:

  • (Expression)

    if expression is valid

  • (nil)

    otherwise



42
43
44
45
46
47
48
49
50
# File 'lib/mutant/expression/parser.rb', line 42

def try_parse(input)
  expressions = expressions(input)
  case expressions.length
  when 0, 1
    expressions.first
  else
    fail AmbiguousExpressionError, "Ambiguous expression: #{input.inspect}"
  end
end