Class: Liquidice::Parser
- Inherits:
-
Object
- Object
- Liquidice::Parser
- Defined in:
- lib/liquidice/parser.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#strict_mode ⇒ Object
Returns the value of attribute strict_mode.
-
#transformed_ast ⇒ Object
Returns the value of attribute transformed_ast.
-
#transformer ⇒ Object
Returns the value of attribute transformer.
Instance Method Summary collapse
-
#initialize(strict_mode: false) ⇒ Parser
constructor
A new instance of Parser.
- #parse(wysiwyg_template) ⇒ Object
- #parse_and_transform(wysiwyg_template) ⇒ Object
- #transformer_tree ⇒ Object
Constructor Details
#initialize(strict_mode: false) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 |
# File 'lib/liquidice/parser.rb', line 7 def initialize(strict_mode: false) @strict_mode = strict_mode @parser = LiquidiceGrammarParser.new @transformer = Liquidice::Transformer::Transformer.new end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
5 6 7 |
# File 'lib/liquidice/parser.rb', line 5 def ast @ast end |
#parser ⇒ Object
Returns the value of attribute parser.
5 6 7 |
# File 'lib/liquidice/parser.rb', line 5 def parser @parser end |
#strict_mode ⇒ Object
Returns the value of attribute strict_mode.
5 6 7 |
# File 'lib/liquidice/parser.rb', line 5 def strict_mode @strict_mode end |
#transformed_ast ⇒ Object
Returns the value of attribute transformed_ast.
5 6 7 |
# File 'lib/liquidice/parser.rb', line 5 def transformed_ast @transformed_ast end |
#transformer ⇒ Object
Returns the value of attribute transformer.
5 6 7 |
# File 'lib/liquidice/parser.rb', line 5 def transformer @transformer end |
Instance Method Details
#parse(wysiwyg_template) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/liquidice/parser.rb', line 13 def parse(wysiwyg_template) @ast = parser.parse(wysiwyg_template) raise Liquidice::Errors::InvalidSyntax, parser.failure_reason if @ast.nil? && strict_mode @ast end |
#parse_and_transform(wysiwyg_template) ⇒ Object
25 26 27 28 29 |
# File 'lib/liquidice/parser.rb', line 25 def parse_and_transform(wysiwyg_template) parse(wysiwyg_template) transformer_tree.transform! transformer_tree.to_s end |
#transformer_tree ⇒ Object
21 22 23 |
# File 'lib/liquidice/parser.rb', line 21 def transformer_tree @transformer_tree ||= transformer.apply(ast) end |