Sha256: d37237f8c0fbdf56856fac6f418b4acdfbbaef1465bd3e412aa6e1b7e7d46bf0

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

# @Opulent
module Opulent
  # @Parser
  class Parser
    # Analyze the input code and check for matching tokens.
    # In case no match was found, throw an exception.
    # In special cases, modify the token hash.
    #
    # @param nodes [Array] Parent node to which we append to
    #
    def root(parent = @root, min_indent = -1)
      while(@line = @code[(@i += 1)])
        # Skip to next iteration if we have a blank line
        if @line =~ /\A\s*\Z/ then next end

        # Reset the line offset
        @offset = 0

        # Parse the current line by trying to match each node type towards it
        # Add current indentation to the indent stack
        indent = accept(:indent).size

        # Stop using the current parent as root if it does not match the
        # minimum indentation requirements
        unless min_indent < indent
          @i -= 1; break
        end

        # Try the main Opulent node types and process each one of them using
        # their matching evaluation procedure
        current_node =  node(parent, indent)        ||
                        text(parent, indent)        ||
                        comment(parent, indent)     ||
                        define(parent, indent)      ||
                        control(parent, indent)     ||
                        evaluate(parent, indent)    ||
                        filter(parent, indent)      ||
                        block_yield(parent, indent) ||
                        block(parent, indent)       ||
                        require_file(parent, indent)||
                        doctype(parent, indent)

        # Throw an error if we couldn't find a valid node
        error :unknown_node_type unless current_node
      end

      return parent
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opulent-1.1.5 lib/opulent/parser/root.rb