Class: Token::Resolver::Grammar
- Inherits:
-
Object
- Object
- Token::Resolver::Grammar
- Defined in:
- lib/token/resolver/grammar.rb
Overview
Note:
The raw parslet tree contains one :text entry per character. Use Transform to coalesce these into proper Text nodes.
Dynamically builds a Parslet::Parser subclass from a Config.
The grammar recognizes structured tokens (e.g., ‘KJ|GEM_NAME`) within arbitrary text. It is designed to **never fail** — any input is valid. Unrecognized content (including incomplete tokens) becomes text nodes.
Class Method Summary collapse
-
.build(config) ⇒ Class
Build (or retrieve from cache) a Parslet::Parser subclass for the given Config.
-
.clear_cache! ⇒ void
Clear the grammar cache.
Class Method Details
.build(config) ⇒ Class
Build (or retrieve from cache) a Parslet::Parser subclass for the given Config.
33 34 35 36 37 |
# File 'lib/token/resolver/grammar.rb', line 33 def build(config) @cache_mutex.synchronize do @cache[config] ||= build_parser_class(config) end end |
.clear_cache! ⇒ void
This method returns an undefined value.
Clear the grammar cache. Mostly useful for testing.
42 43 44 45 46 |
# File 'lib/token/resolver/grammar.rb', line 42 def clear_cache! @cache_mutex.synchronize do @cache.clear end end |