Class: Mutant::Expression::Parser Private

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

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

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:



25
26
27
# File 'lib/mutant/expression/parser.rb', line 25

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



38
39
40
41
42
43
44
45
46
# File 'lib/mutant/expression/parser.rb', line 38

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