class DParse::Parser

Public Instance Methods

apply(input) click to toggle source
# File lib/d-parse/parser.rb, line 3
def apply(input)
  # FIXME: convert input to chars first
  read(input, DParse::Position.new)
end
bind(&block) click to toggle source
# File lib/d-parse/parser.rb, line 60
def bind(&block)
  DParse::Parsers::Bind.new(self, &block)
end
capture() click to toggle source
# File lib/d-parse/parser.rb, line 64
def capture
  DParse::Parsers::Capturing.new(self)
end
compact() click to toggle source
# File lib/d-parse/parser.rb, line 48
def compact
  map { |d, _, _| d.compact }
end
expectation_message() click to toggle source
# File lib/d-parse/parser.rb, line 16
def expectation_message
  '?'
end
first() click to toggle source
# File lib/d-parse/parser.rb, line 28
def first
  map { |d| d[0] }
end
flatten() click to toggle source
# File lib/d-parse/parser.rb, line 44
def flatten
  map { |d| d.is_a?(Array) ? d.reduce(:+) : d }
end
ignore() click to toggle source
# File lib/d-parse/parser.rb, line 56
def ignore
  DParse::Parsers::Ignore.new(self)
end
inspect() click to toggle source
# File lib/d-parse/parser.rb, line 20
def inspect
  raise NotImplementedError
end
map(&block) click to toggle source
# File lib/d-parse/parser.rb, line 52
def map(&block)
  DParse::Parsers::Map.new(self, &block)
end
match?(input) click to toggle source
# File lib/d-parse/parser.rb, line 8
def match?(input)
  apply(input).success?
end
read(_input, _pos) click to toggle source
# File lib/d-parse/parser.rb, line 12
def read(_input, _pos)
  raise NotImplementedError
end
second() click to toggle source
# File lib/d-parse/parser.rb, line 32
def second
  map { |d| d[1] }
end
select_even() click to toggle source
# File lib/d-parse/parser.rb, line 40
def select_even
  map { |d| d.select.with_index { |_, i| i.even? } }
end
select_odd() click to toggle source
# File lib/d-parse/parser.rb, line 36
def select_odd
  map { |d| d.select.with_index { |_, i| i.odd? } }
end
to_s() click to toggle source
# File lib/d-parse/parser.rb, line 24
def to_s
  inspect
end

Private Instance Methods

display(char) click to toggle source
# File lib/d-parse/parser.rb, line 70
def display(char)
  case char
  when nil
    'end of input'
  when "\n"
    'line break (LF)'
  when "\r"
    'line break (CR)'
  else
    quote_char =
      if char == '\''
        '"'
      else
        '\''
      end

    display_char =
      case char
      when '\\'
        '\\'
      when '"'
        '"'
      when '\''
        '\''
      else
        char.inspect.gsub(/^"|"$/, '')
      end

    quote_char + display_char + quote_char
  end
end