Module: Kaiseki::Parseable
- Included in:
- BasicParser, EOFParser, RepeatParser, Proc, Regexp, String, Symbol
- Defined in:
- lib/parseable.rb
Instance Method Summary collapse
- #&(other) ⇒ Object
- #action(node = Node.default, &block) ⇒ Object
- #and? ⇒ Boolean
- #cast(to_class) ⇒ Object
- #filter(node = Node.default, &block) ⇒ Object
- #merge ⇒ Object
- #not! ⇒ Object
- #one_or_more ⇒ Object
- #optional ⇒ Object
- #override(options) ⇒ Object
- #parse(stream, options = {}) ⇒ Object
- #predicate? ⇒ Boolean
- #protect(&block) ⇒ Object
- #repeat(min, max = nil) ⇒ Object
- #set(*vars) ⇒ Object
- #skip ⇒ Object
- #tag_error(name) ⇒ Object
- #tag_result(name) ⇒ Object
- #to_parseable ⇒ Object
- #validate(validators) ⇒ Object
- #zero_or_more ⇒ Object
- #|(other) ⇒ Object
Instance Method Details
#&(other) ⇒ Object
28 29 30 |
# File 'lib/parseable.rb', line 28 def & other SequenceParser.new self, other end |
#action(node = Node.default, &block) ⇒ Object
80 81 82 |
# File 'lib/parseable.rb', line 80 def action node = Node.default, &block ActionResult.new self, node, &block end |
#cast(to_class) ⇒ Object
72 73 74 |
# File 'lib/parseable.rb', line 72 def cast to_class CastResult.new self, to_class end |
#filter(node = Node.default, &block) ⇒ Object
76 77 78 |
# File 'lib/parseable.rb', line 76 def filter node = Node.default, &block FilterResult.new self, node, &block end |
#merge ⇒ Object
68 69 70 |
# File 'lib/parseable.rb', line 68 def merge MergeResult.new self end |
#not! ⇒ Object
56 57 58 |
# File 'lib/parseable.rb', line 56 def not! NotPredicate.new self end |
#one_or_more ⇒ Object
48 49 50 |
# File 'lib/parseable.rb', line 48 def one_or_more repeat 1 end |
#optional ⇒ Object
40 41 42 |
# File 'lib/parseable.rb', line 40 def optional repeat 0, 1 end |
#override(options) ⇒ Object
64 65 66 |
# File 'lib/parseable.rb', line 64 def override OverrideResult.new self, end |
#parse(stream, options = {}) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/parseable.rb', line 7 def parse stream, = {} stream = stream.to_stream stream.lock do parse! stream, end end |
#predicate? ⇒ Boolean
14 15 16 |
# File 'lib/parseable.rb', line 14 def predicate? false end |
#protect(&block) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/parseable.rb', line 18 def protect &block catch :ParseSuccess do catch :SkipSuccess do block.call throw :ParseSuccess end raise RuntimeError, "#{self.to_s} must not catch a SkipSuccess" end end |
#repeat(min, max = nil) ⇒ Object
36 37 38 |
# File 'lib/parseable.rb', line 36 def repeat min, max = nil RepeatParser.new self, min, max end |
#set(*vars) ⇒ Object
88 89 90 |
# File 'lib/parseable.rb', line 88 def set *vars SetVar.new self, *vars end |
#skip ⇒ Object
60 61 62 |
# File 'lib/parseable.rb', line 60 def skip SkipPredicate.new self end |
#tag_error(name) ⇒ Object
96 97 98 |
# File 'lib/parseable.rb', line 96 def tag_error name ErrorTag.new self, name end |
#tag_result(name) ⇒ Object
92 93 94 |
# File 'lib/parseable.rb', line 92 def tag_result name ResultTag.new self, name end |
#to_parseable ⇒ Object
3 4 5 |
# File 'lib/parseable.rb', line 3 def to_parseable self end |
#validate(validators) ⇒ Object
84 85 86 |
# File 'lib/parseable.rb', line 84 def validate validators ValidateResult.new self, validators end |
#zero_or_more ⇒ Object
44 45 46 |
# File 'lib/parseable.rb', line 44 def zero_or_more repeat 0 end |
#|(other) ⇒ Object
32 33 34 |
# File 'lib/parseable.rb', line 32 def | other ChoiceParser.new self, other end |