Sha256: 218d3f3c754fc9253a6a43e74270a55d0c05f26fa8fd7501ae726dd13a293433
Contents?: true
Size: 917 Bytes
Versions: 22
Compression:
Stored size: 917 Bytes
Contents
# frozen_string_literal: true module Mutant class Expression class Parser include Concord.new(:types) # Apply expression parsing # # @param [String] input # # @return [Either<String, Expression>] # if expression is valid # # @return [nil] # otherwise def apply(input) expressions = expressions(input) case expressions.length when 0 Either::Left.new("Expression: #{input.inspect} is invalid") when 1 Either::Right.new(expressions.first) else Either::Left.new("Expression: #{input.inspect} is ambiguous") end end private def expressions(input) types.each_with_object([]) do |type, aggregate| expression = type.try_parse(input) and aggregate << expression end end end # Parser end # Expression end # Mutant
Version data entries
22 entries across 22 versions & 1 rubygems