class Stark::Parser

Public Class Methods

ast(arg) click to toggle source
# File lib/stark/parser.rb, line 29
def self.ast(arg)
  parser = Stark::Parser.new arg
  parser.ast
end
expand(ast) click to toggle source
# File lib/stark/parser.rb, line 8
def self.expand(ast)
  out = []

  ast.each do |elem|
    case elem
      when AST::Include
        data = Stark::Parser.read_file(elem.path)
        out += expand(Stark::Parser.ast(data))
      else
        out << elem
    end
  end

  out
end
read_file(file) click to toggle source
# File lib/stark/parser.rb, line 34
def self.read_file(file)
  @@include_path ||= Set.new([Dir.pwd])
  if file.respond_to?(:read)
    if file.respond_to?(:path) && file.path
      @@include_path << File.dirname(File.expand_path(file.path, Dir.pwd))
    end
    return file.read
  else
    @@include_path << File.dirname(File.expand_path(file, Dir.pwd))
    fn = (@@include_path.map {|path|
            File.expand_path(file, path)
          }.detect { |fn|
            File.exist?(fn)
          }) || file
    File.read fn
  end
end

Public Instance Methods

ast() click to toggle source
# File lib/stark/parser.rb, line 24
def ast
  raise_error unless parse
  Stark::Parser.expand result
end