Class: Glyph::Interpreter
- Inherits:
-
Object
- Object
- Glyph::Interpreter
- Defined in:
- lib/glyph/interpreter.rb
Overview
A Glyph::Interpreter object perform the following actions:
-
Parses a string of text containing Glyph macros
-
Creates a document based on the parsed syntax tree
-
Analyzes and finalizes the document
Instance Method Summary collapse
-
#document ⇒ Glyph::Document
Returns the finalized @document (calls self#process and self#postprocess if necessary).
-
#initialize(text, context = {}) ⇒ Interpreter
constructor
Creates a new Glyph::Interpreter object.
-
#parse ⇒ Glyph::SyntaxNode
Parses the string provided during initialization.
- #postprocess ⇒ Object
- #process ⇒ Object
Constructor Details
#initialize(text, context = {}) ⇒ Interpreter
Creates a new Glyph::Interpreter object.
14 15 16 17 18 19 |
# File 'lib/glyph/interpreter.rb', line 14 def initialize(text, context={}) @context = context @context[:source] ||= {:name => "--", :file => nil, :topic => nil} @text = text @parser = Glyph::Parser.new text, @context[:source][:name] end |
Instance Method Details
#document ⇒ Glyph::Document
Returns the finalized @document (calls self#process and self#postprocess if necessary)
34 35 36 37 38 39 40 |
# File 'lib/glyph/interpreter.rb', line 34 def document parse unless @tree return @document if @document.finalized? process if @document.new? postprocess if @document.analyzed? @document end |
#parse ⇒ Glyph::SyntaxNode
Parses the string provided during initialization
45 46 47 48 49 50 51 |
# File 'lib/glyph/interpreter.rb', line 45 def parse Glyph.info "Parsing: #{@context[:source][:name]}" if Glyph.debug? && @context[:info] && @context[:source][:name] @tree = @parser.parse @document = Glyph::Document.new @tree, @context @document.inherit_from @context[:document] if @context[:document] @tree end |
#postprocess ⇒ Object
28 29 30 |
# File 'lib/glyph/interpreter.rb', line 28 def postprocess @document.finalize end |
#process ⇒ Object
22 23 24 25 |
# File 'lib/glyph/interpreter.rb', line 22 def process parse unless @tree @document.analyze end |