Class: DParse::Parser
- Inherits:
-
Object
show all
- Defined in:
- lib/d-parse/parser.rb
Direct Known Subclasses
DParse::Parsers::Alt, DParse::Parsers::Any, DParse::Parsers::Bind, DParse::Parsers::Capturing, DParse::Parsers::Char, DParse::Parsers::CharIn, DParse::Parsers::CharNot, DParse::Parsers::CharNotIn, DParse::Parsers::Describe, DParse::Parsers::EOF, DParse::Parsers::Except, DParse::Parsers::Fail, DParse::Parsers::Ignore, DParse::Parsers::Intersperse, DParse::Parsers::JSON, DParse::Parsers::Lazy, DParse::Parsers::Map, DParse::Parsers::Opt, DParse::Parsers::Repeat, DParse::Parsers::Seq, DParse::Parsers::String, DParse::Parsers::Succeed, DParse::Parsers::WhitespaceChar
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)
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
|
#capture ⇒ Object
64
65
66
|
# File 'lib/d-parse/parser.rb', line 64
def capture
DParse::Parsers::Capturing.new(self)
end
|
#compact ⇒ Object
48
49
50
|
# File 'lib/d-parse/parser.rb', line 48
def compact
map { |d, _, _| d.compact }
end
|
#expectation_message ⇒ Object
16
17
18
|
# File 'lib/d-parse/parser.rb', line 16
def expectation_message
'?'
end
|
#first ⇒ Object
28
29
30
|
# File 'lib/d-parse/parser.rb', line 28
def first
map { |d| d[0] }
end
|
#flatten ⇒ Object
44
45
46
|
# File 'lib/d-parse/parser.rb', line 44
def flatten
map { |d| d.is_a?(Array) ? d.reduce(:+) : d }
end
|
#ignore ⇒ Object
56
57
58
|
# File 'lib/d-parse/parser.rb', line 56
def ignore
DParse::Parsers::Ignore.new(self)
end
|
#inspect ⇒ Object
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
8
9
10
|
# File 'lib/d-parse/parser.rb', line 8
def match?(input)
apply(input).success?
end
|
#read(_input, _pos) ⇒ Object
12
13
14
|
# File 'lib/d-parse/parser.rb', line 12
def read(_input, _pos)
raise NotImplementedError
end
|
#second ⇒ Object
32
33
34
|
# File 'lib/d-parse/parser.rb', line 32
def second
map { |d| d[1] }
end
|
#select_even ⇒ Object
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_odd ⇒ Object
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_s ⇒ Object
24
25
26
|
# File 'lib/d-parse/parser.rb', line 24
def to_s
inspect
end
|