Module: Kaiseki::Parseable
- Included in:
- BasicParser, EOFParser, ListParser, 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
- #list(delimiter = ',') ⇒ 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
29 30 31 |
# File 'lib/parseable.rb', line 29 def & other SequenceParser.new self, other end |
#action(node = Node.default, &block) ⇒ Object
85 86 87 |
# File 'lib/parseable.rb', line 85 def action node = Node.default, &block ActionResult.new self, node, &block end |
#cast(to_class) ⇒ Object
77 78 79 |
# File 'lib/parseable.rb', line 77 def cast to_class CastResult.new self, to_class end |
#filter(node = Node.default, &block) ⇒ Object
81 82 83 |
# File 'lib/parseable.rb', line 81 def filter node = Node.default, &block FilterResult.new self, node, &block end |
#list(delimiter = ',') ⇒ Object
53 54 55 |
# File 'lib/parseable.rb', line 53 def list delimiter = ',' ListParser.new self, delimiter end |
#merge ⇒ Object
73 74 75 |
# File 'lib/parseable.rb', line 73 def merge MergeResult.new self end |
#not! ⇒ Object
61 62 63 |
# File 'lib/parseable.rb', line 61 def not! NotPredicate.new self end |
#one_or_more ⇒ Object
49 50 51 |
# File 'lib/parseable.rb', line 49 def one_or_more repeat 1 end |
#optional ⇒ Object
41 42 43 |
# File 'lib/parseable.rb', line 41 def optional repeat 0, 1 end |
#override(options) ⇒ Object
69 70 71 |
# File 'lib/parseable.rb', line 69 def override OverrideResult.new self, end |
#parse(stream, options = {}) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/parseable.rb', line 7 def parse stream, = {} [:global] ||= {} stream = stream.to_stream stream.lock do parse! stream, end end |
#predicate? ⇒ Boolean
15 16 17 |
# File 'lib/parseable.rb', line 15 def predicate? false end |
#protect(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/parseable.rb', line 19 def protect &block catch :ParseSuccess do catch :SkipSuccess do block.call throw :ParseSuccess end raise RuntimeError, "#{self} must not catch a SkipSuccess" end end |
#repeat(min, max = nil) ⇒ Object
37 38 39 |
# File 'lib/parseable.rb', line 37 def repeat min, max = nil RepeatParser.new self, min, max end |
#set(*vars) ⇒ Object
93 94 95 |
# File 'lib/parseable.rb', line 93 def set *vars SetVar.new self, *vars end |
#skip ⇒ Object
65 66 67 |
# File 'lib/parseable.rb', line 65 def skip SkipPredicate.new self end |
#tag_error(name) ⇒ Object
101 102 103 |
# File 'lib/parseable.rb', line 101 def tag_error name ErrorTag.new self, name end |
#tag_result(name) ⇒ Object
97 98 99 |
# File 'lib/parseable.rb', line 97 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
89 90 91 |
# File 'lib/parseable.rb', line 89 def validate validators ValidateResult.new self, validators end |
#zero_or_more ⇒ Object
45 46 47 |
# File 'lib/parseable.rb', line 45 def zero_or_more repeat 0 end |
#|(other) ⇒ Object
33 34 35 |
# File 'lib/parseable.rb', line 33 def | other ChoiceParser.new self, other end |