class Glyph::Interpreter

A Glyph::Interpreter object perform the following actions:

Public Class Methods

new(text, context={}) click to toggle source

Creates a new Glyph::Interpreter object. @param [String] text the string to interpret @param [Hash] context the context to pass along when expanding macros

# 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

Public Instance Methods

document() click to toggle source

Returns the finalized @document (calls self#process and self#postprocess if necessary) @return [Glyph::Document] the finalized document

# 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() click to toggle source

Parses the string provided during initialization @return [Glyph::SyntaxNode] the Abstract Syntax Tree generated from the string @since 0.3.0

# 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() click to toggle source

@see Glyph::Document#finalize

# File lib/glyph/interpreter.rb, line 28
def postprocess
        @document.finalize
end
process() click to toggle source

@see Glyph::Document#analyze

# File lib/glyph/interpreter.rb, line 22
def process
        parse unless @tree
        @document.analyze
end