class Copper::Parser

Public Class Methods

new() click to toggle source
# File lib/copper/parser.rb, line 3
def initialize
        @parser = CopperParser.new
end

Public Instance Methods

cc_parser() click to toggle source
# File lib/copper/parser.rb, line 32
def cc_parser
        @parser
end
clean_tree(root_node) click to toggle source
# File lib/copper/parser.rb, line 36
def clean_tree(root_node)
        return if(root_node.elements.nil?)
        root_node.elements.delete_if { |node| !node.is_a?(CopperNode) }
        root_node.elements.each { |node| self.clean_tree(node) }
end
parse(content) click to toggle source
# File lib/copper/parser.rb, line 7
def parse(content)
        root_node = @parser.parse(content)

        # Raise any errors.
        unless root_node
                @parser.failure_reason =~ /^(Expected .+) after/m
                if $1.nil?
                        puts "#{@parser.failure_reason}"
                else
                        puts "#{$1.gsub("\n", '$NEWLINE')}:"
                end
                puts content.lines.to_a[@parser.failure_line - 1]
                puts "#{'~' * (@parser.failure_column - 1)}^"
                return nil
        end

        puts root_node.inspect if $parser_debug

        clean_tree(root_node)

        puts root_node.inspect if $parser_debug

        root_node
end