Sha256: 336944e7e5efb03b84469b02fde0559555d126b38bb14e3fc82d0bdad21dc96b

Contents?: true

Size: 1.73 KB

Versions: 21

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module SlimLint
  # Temple engine used to generate a {Sexp} parse tree for use by linters.
  #
  # We omit a lot of the filters that are in {Slim::Engine} because they result
  # in information potentially being removed from the parse tree (since some
  # Sexp abstractions are optimized/removed or otherwise transformed). In order
  # for linters to be useful, they need to operate on the original parse tree.
  #
  # The other key task this engine accomplishes is converting the Array-based
  # S-expressions into {SlimLint::Sexp} objects, which have a number of helper
  # methods that makes working with them easier. It also annotates these
  # {SlimLint::Sexp} objects with line numbers so it's easy to cross reference
  # with the original source code.
  class Engine < Temple::Engine
    filter :Encoding
    filter :RemoveBOM

    # Parse into S-expression using Slim parser
    use Slim::Parser

    # Converts Array-based S-expressions into SlimLint::Sexp objects
    use SlimLint::Filters::SexpConverter

    # Annotates Sexps with line numbers
    use SlimLint::Filters::InjectLineNumbers

    # Parses the given source code into a Sexp.
    #
    # @param source [String] source code to parse
    # @return [SlimLint::Sexp] parsed Sexp
    def parse(source)
      call(source)
    rescue ::Slim::Parser::SyntaxError => e
      # Convert to our own exception type to isolate from upstream changes
      error = SlimLint::Exceptions::ParseError.new(e.error,
                                                   e.file,
                                                   e.line,
                                                   e.lineno,
                                                   e.column)
      raise error
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
slim_lint-0.31.1 lib/slim_lint/engine.rb
slim_lint-0.31.0 lib/slim_lint/engine.rb
slim_lint-0.30.0 lib/slim_lint/engine.rb
slim_lint-0.29.0 lib/slim_lint/engine.rb
slim_lint-0.28.0 lib/slim_lint/engine.rb
slim_lint-0.27.0 lib/slim_lint/engine.rb
slim_lint-0.26.0 lib/slim_lint/engine.rb
slim_lint-0.25.0 lib/slim_lint/engine.rb
slim_lint-0.24.0 lib/slim_lint/engine.rb
slim_lint-0.23.0 lib/slim_lint/engine.rb
slim_lint-0.22.1 lib/slim_lint/engine.rb
slim_lint-0.22.0 lib/slim_lint/engine.rb
slim_lint-0.21.1 lib/slim_lint/engine.rb
slim_lint-0.21.0 lib/slim_lint/engine.rb
slim_lint-0.20.2 lib/slim_lint/engine.rb
slim_lint-0.20.1 lib/slim_lint/engine.rb
slim_lint-0.20.0 lib/slim_lint/engine.rb
slim_lint-0.19.0 lib/slim_lint/engine.rb
slim_lint-0.18.0 lib/slim_lint/engine.rb
slim_lint-0.17.1 lib/slim_lint/engine.rb