Class: DParse::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/d-parse/parser.rb

Instance Method Summary collapse

Instance Method Details

#apply(input) ⇒ Object



3
4
5
6
# 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) ⇒ Object



60
61
62
# File 'lib/d-parse/parser.rb', line 60

def bind(&block)
  DParse::Parsers::Bind.new(self, &block)
end

#captureObject



64
65
66
# File 'lib/d-parse/parser.rb', line 64

def capture
  DParse::Parsers::Capturing.new(self)
end

#compactObject



48
49
50
# File 'lib/d-parse/parser.rb', line 48

def compact
  map { |d, _, _| d.compact }
end

#expectation_messageObject



16
17
18
# File 'lib/d-parse/parser.rb', line 16

def expectation_message
  '?'
end

#firstObject



28
29
30
# File 'lib/d-parse/parser.rb', line 28

def first
  map { |d| d[0] }
end

#flattenObject



44
45
46
# File 'lib/d-parse/parser.rb', line 44

def flatten
  map { |d| d.is_a?(Array) ? d.reduce(:+) : d }
end

#ignoreObject



56
57
58
# File 'lib/d-parse/parser.rb', line 56

def ignore
  DParse::Parsers::Ignore.new(self)
end

#inspectObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/d-parse/parser.rb', line 20

def inspect
  raise NotImplementedError
end

#map(&block) ⇒ Object



52
53
54
# File 'lib/d-parse/parser.rb', line 52

def map(&block)
  DParse::Parsers::Map.new(self, &block)
end

#match?(input) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/d-parse/parser.rb', line 8

def match?(input)
  apply(input).success?
end

#read(_input, _pos) ⇒ Object

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/d-parse/parser.rb', line 12

def read(_input, _pos)
  raise NotImplementedError
end

#secondObject



32
33
34
# File 'lib/d-parse/parser.rb', line 32

def second
  map { |d| d[1] }
end

#select_evenObject



40
41
42
# File 'lib/d-parse/parser.rb', line 40

def select_even
  map { |d| d.select.with_index { |_, i| i.even? } }
end

#select_oddObject



36
37
38
# File 'lib/d-parse/parser.rb', line 36

def select_odd
  map { |d| d.select.with_index { |_, i| i.odd? } }
end

#to_sObject



24
25
26
# File 'lib/d-parse/parser.rb', line 24

def to_s
  inspect
end