class DParse::Parsers::Except

Public Class Methods

new(parser, bad_parser) click to toggle source
# File lib/d-parse/parsers/primitives/except.rb, line 4
def initialize(parser, bad_parser)
  @parser = parser
  @bad_parser = bad_parser
end

Public Instance Methods

expectation_message() click to toggle source
# File lib/d-parse/parsers/primitives/except.rb, line 28
def expectation_message
  @parser.expectation_message + ', not ' + @bad_parser.expectation_message
end
inspect() click to toggle source
# File lib/d-parse/parsers/primitives/except.rb, line 24
def inspect
  "except(#{@parser.inspect}, #{@bad_parser.inspect})"
end
read(input, pos) click to toggle source
# File lib/d-parse/parsers/primitives/except.rb, line 9
def read(input, pos)
  res = @parser.read(input, pos)
  case res
  when Success
    bad_res = @bad_parser.read(input, pos)
    if bad_res.is_a?(Success) && bad_res.pos.index == res.pos.index
      Failure.new(input, pos, origin: self)
    else
      res
    end
  when Failure
    res
  end
end