Method: Parslet.dynamic
- Defined in:
- lib/parslet.rb
.dynamic(&block) ⇒ Object
Designates a piece of the parser as being dynamic. Dynamic parsers can either return a parser at runtime, which will be applied on the input, or return a result from a parse.
Dynamic parse pieces are never cached and can introduce performance abnormalitites - use sparingly where other constructs fail.
Example:
# Parses either 'a' or 'b', depending on the weather
dynamic { rand() < 0.5 ? str('a') : str('b') }
199 200 201 |
# File 'lib/parslet.rb', line 199 def dynamic(&block) Parslet::Atoms::Dynamic.new(block) end |