Sha256: 8cf671923716e754f831d2bee200a6d2b15937c1b85f101e394231e5cec1c04d

Contents?: true

Size: 1.71 KB

Versions: 17

Compression:

Stored size: 1.71 KB

Contents

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 => ex
      # Convert to our own exception type to isolate from upstream changes
      error = SlimLint::Exceptions::ParseError.new(ex.error,
                                                   ex.file,
                                                   ex.line,
                                                   ex.lineno,
                                                   ex.column)
      raise error
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
slim_lint-0.15.1 lib/slim_lint/engine.rb
slim_lint-0.15.0 lib/slim_lint/engine.rb
slim_lint-0.14.0 lib/slim_lint/engine.rb
slim_lint-0.13.0 lib/slim_lint/engine.rb
slim_lint-0.12.0 lib/slim_lint/engine.rb
slim_lint-0.11.0 lib/slim_lint/engine.rb
slim_lint-0.10.0 lib/slim_lint/engine.rb
slim_lint-0.9.0 lib/slim_lint/engine.rb
slim_lint-0.8.3 lib/slim_lint/engine.rb
slim_lint-0.8.2 lib/slim_lint/engine.rb
slim_lint-0.8.1 lib/slim_lint/engine.rb
slim_lint-0.8.0 lib/slim_lint/engine.rb
slim_lint-0.7.2 lib/slim_lint/engine.rb
slim_lint-0.7.1 lib/slim_lint/engine.rb
slim_lint-0.7.0 lib/slim_lint/engine.rb
slim_lint-0.6.1 lib/slim_lint/engine.rb
slim_lint-0.6.0 lib/slim_lint/engine.rb