Class: ORB::Temple::Parser
- Inherits:
-
Object
- Object
- ORB::Temple::Parser
- Defined in:
- lib/orb/temple/parser.rb
Instance Method Summary collapse
- #call(template) ⇒ Object
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(options = {}) ⇒ Parser
6 7 8 9 10 11 12 |
# File 'lib/orb/temple/parser.rb', line 6 def initialize( = {}) = # Only raise errors when is used as a standalone library # and not within the Temple engine @raise_errors = !.key?(:generator) end |
Instance Method Details
#call(template) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/orb/temple/parser.rb', line 14 def call(template) tokenizer = ORB::Tokenizer2.new(template, **) tokens = tokenizer.tokenize! parser = ORB::Parser.new(tokens, **) @root = parser.parse! @root rescue ORB::Error => e e.set_backtrace(e.backtrace.unshift("#{@options.fetch(:filename, :nofile)}:#{e.line || 42}")) # Within the Temple engine, tokenizer and parser errors shouldn't be raised # but instead passed on to the compiler, so we can raise them there and # render nice error templates. raise if @raise_errors error_with_lineno(e) end |