Sha256: 175254155000add0a20d9527b59e0bfc98425e4bc8efe2c7e9bf35ece83f22b9

Contents?: true

Size: 822 Bytes

Versions: 7

Compression:

Stored size: 822 Bytes

Contents

module Ruco
  module SyntaxParser
    # uv only offers certain syntax
    UV_CONVERT = {
      'scss' => 'sass',
      'html+erb' => 'html_rails',
    }

    def self.syntax_for_lines(lines, languages)
      if syntax = syntax_node(languages)
        processor = syntax.parse(lines.join("\n"),  Ruco::ArrayProcessor.new)
        processor.lines
      else
        []
      end
    end

    def self.syntax_node(languages)
      @@syntax_node ||= {}
      @@syntax_node[languages] ||= begin
        found = nil
        fallbacks = languages.map{|l| UV_CONVERT[l] }.compact

        (languages + fallbacks).detect do |language|
          syntax = File.join(Uv.syntax_path, "#{language}.syntax")
          found = Textpow::SyntaxNode.load(syntax) if File.exist?(syntax)
        end

        found
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruco-0.2.0.beta8 lib/ruco/syntax_parser.rb
ruco-0.2.0.beta7 lib/ruco/syntax_parser.rb
ruco-0.2.0.beta6 lib/ruco/syntax_parser.rb
ruco-0.2.0.beta5 lib/ruco/syntax_parser.rb
ruco-0.2.0.beta4 lib/ruco/syntax_parser.rb
ruco-0.2.0.beta3 lib/ruco/syntax_parser.rb
ruco-0.2.0.beta lib/ruco/syntax_parser.rb