script.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. require 'sass/script/node'
  2. require 'sass/script/variable'
  3. require 'sass/script/funcall'
  4. require 'sass/script/operation'
  5. require 'sass/script/literal'
  6. require 'sass/script/parser'
  7. module Sass
  8. # SassScript is code that's embedded in Sass documents
  9. # to allow for property values to be computed from variables.
  10. #
  11. # This module contains code that handles the parsing and evaluation of SassScript.
  12. module Script
  13. # The regular expression used to parse variables.
  14. MATCH = /^\$(#{Sass::SCSS::RX::IDENT})\s*:\s*(.+?)(!(?i:default))?$/
  15. # The regular expression used to validate variables without matching.
  16. VALIDATE = /^\$#{Sass::SCSS::RX::IDENT}$/
  17. # Parses a string of SassScript
  18. #
  19. # @param value [String] The SassScript
  20. # @param line [Fixnum] The number of the line on which the SassScript appeared.
  21. # Used for error reporting
  22. # @param offset [Fixnum] The number of characters in on `line` that the SassScript started.
  23. # Used for error reporting
  24. # @param options [{Symbol => Object}] An options hash;
  25. # see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
  26. # @return [Script::Node] The root node of the parse tree
  27. def self.parse(value, line, offset, options = {})
  28. Parser.parse(value, line, offset, options)
  29. rescue Sass::SyntaxError => e
  30. e.message << ": #{value.inspect}." if e.message == "SassScript error"
  31. e.modify_backtrace(:line => line, :filename => options[:filename])
  32. raise e
  33. end
  34. end
  35. end