Sha256: 516f8ff8de929dbbdb529d3cd059d19c8aea0841207baa3d16129f065f595a08

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module Faml
  class FilterParser
    def initialize(indent_tracker)
      @ast = nil
      @indent_level = nil
      @indent_tracker = indent_tracker
    end

    def enabled?
      !!@ast
    end

    def start(name, filename, lineno)
      @ast = Ast::Filter.new
      @ast.name = name
      @ast.filename
      @ast.lineno = lineno
    end

    def append(line)
      indent, text = @indent_tracker.split(line)
      if text.empty?
        @ast.texts << ''
        return
      end
      indent_level = indent.size

      if @indent_level
        if indent_level < @indent_level
          # Finish filter
          @indent_level = nil
          ast = @ast
          @ast = nil
          return ast
        end
      else
        if indent_level > @indent_tracker.current_level
          # Start filter
          @indent_level = indent_level
        else
          # Empty filter
          @ast = nil
          return nil
        end
      end

      text = line[@indent_level .. -1]
      @ast.texts << text
      nil
    end

    def finish
      @ast
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
faml-0.2.16 lib/faml/filter_parser.rb
faml-0.2.15 lib/faml/filter_parser.rb
faml-0.2.14 lib/faml/filter_parser.rb
faml-0.2.13 lib/faml/filter_parser.rb
faml-0.2.12 lib/faml/filter_parser.rb
faml-0.2.11 lib/faml/filter_parser.rb
faml-0.2.10 lib/faml/filter_parser.rb
faml-0.2.9 lib/faml/filter_parser.rb
faml-0.2.8 lib/faml/filter_parser.rb
faml-0.2.7 lib/faml/filter_parser.rb