class Parslet::Atoms::Dynamic
Evaluates a block at parse time. The result from the block must be a parser (something which implements apply
). In the first case, the parser will then be applied to the input, creating the result.
Dynamic
parses are never cached.
Example:
dynamic { rand < 0.5 ? str('a') : str('b') }
Attributes
block[R]
Public Class Methods
new(block)
click to toggle source
# File lib/parslet/atoms/dynamic.rb, line 13 def initialize(block) @block = block end
Public Instance Methods
cached?()
click to toggle source
# File lib/parslet/atoms/dynamic.rb, line 17 def cached? false end
to_s_inner(prec)
click to toggle source
# File lib/parslet/atoms/dynamic.rb, line 28 def to_s_inner(prec) "dynamic { ... }" end
try(source, context, consume_all)
click to toggle source
# File lib/parslet/atoms/dynamic.rb, line 21 def try(source, context, consume_all) result = block.call(source, context) # Result is a parslet atom. return result.apply(source, context, consume_all) end