2008-10-12 19:03:06 -07:00
|
|
|
require 'strscan'
|
2009-04-25 02:00:36 -07:00
|
|
|
require 'sass/script/node'
|
2008-10-12 20:26:56 -07:00
|
|
|
require 'sass/script/variable'
|
2008-10-12 19:03:06 -07:00
|
|
|
require 'sass/script/funcall'
|
|
|
|
require 'sass/script/operation'
|
|
|
|
require 'sass/script/literal'
|
|
|
|
require 'sass/script/parser'
|
|
|
|
|
|
|
|
module Sass
|
2009-04-23 17:29:06 -07:00
|
|
|
# SassScript is code that's embedded in Sass documents
|
|
|
|
# to allow for property values to be computed from variables.
|
|
|
|
#
|
|
|
|
# This module contains code that handles the parsing and evaluation of SassScript.
|
2008-10-12 19:03:06 -07:00
|
|
|
module Script
|
2009-04-23 17:29:06 -07:00
|
|
|
# The regular expression used to parse variables.
|
2010-01-17 16:46:21 -08:00
|
|
|
# @private
|
2010-03-26 17:24:02 -07:00
|
|
|
MATCH = /^[!\$](#{Sass::SCSS::RX::IDENT})\s*((?:\|\|)?[:=])\s*(.+)/
|
2008-10-12 19:03:06 -07:00
|
|
|
|
2009-04-23 17:29:06 -07:00
|
|
|
# The regular expression used to validate variables without matching.
|
2010-01-17 16:46:21 -08:00
|
|
|
# @private
|
2010-03-06 15:21:14 -08:00
|
|
|
VALIDATE = /^[!\$]#{Sass::SCSS::RX::IDENT}$/
|
2008-10-12 19:03:06 -07:00
|
|
|
|
2009-04-23 17:29:06 -07:00
|
|
|
# Parses a string of SassScript
|
|
|
|
#
|
|
|
|
# @param value [String] The SassScript
|
|
|
|
# @param line [Fixnum] The number of the line on which the SassScript appeared.
|
|
|
|
# Used for error reporting
|
|
|
|
# @param offset [Fixnum] The number of characters in on `line` that the SassScript started.
|
|
|
|
# Used for error reporting
|
2009-12-01 18:00:35 -08:00
|
|
|
# @param options [{Symbol => Object}] An options hash;
|
|
|
|
# see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
|
2009-04-25 02:00:36 -07:00
|
|
|
# @return [Script::Node] The root node of the parse tree
|
2009-12-01 18:00:35 -08:00
|
|
|
def self.parse(value, line, offset, options = {})
|
|
|
|
Parser.parse(value, line, offset, options)
|
2008-10-12 19:03:06 -07:00
|
|
|
rescue Sass::SyntaxError => e
|
2009-09-13 15:52:59 -07:00
|
|
|
e.message << ": #{value.inspect}." if e.message == "SassScript error"
|
2009-12-01 18:00:35 -08:00
|
|
|
e.modify_backtrace(:line => line, :filename => options[:filename])
|
2008-10-12 19:03:06 -07:00
|
|
|
raise e
|
|
|
|
end
|
2010-03-06 17:17:51 -08:00
|
|
|
|
|
|
|
# @private
|
|
|
|
def self.var_warning(varname, line, offset, filename)
|
2010-03-29 20:01:16 -07:00
|
|
|
Haml::Util.haml_warn <<MESSAGE
|
2010-03-06 17:17:51 -08:00
|
|
|
DEPRECATION WARNING:
|
|
|
|
On line #{line}, character #{offset}#{" of '#{filename}'" if filename}
|
|
|
|
Variables with ! have been deprecated and will be removed in version 3.2.
|
|
|
|
Use \"$#{varname}\" instead.
|
2010-03-27 17:02:37 -07:00
|
|
|
MESSAGE
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.equals_warning(types, name, val, line, offset, filename)
|
2010-03-29 20:01:16 -07:00
|
|
|
Haml::Util.haml_warn <<MESSAGE
|
2010-03-27 17:02:37 -07:00
|
|
|
DEPRECATION WARNING:
|
|
|
|
On line #{line}#{", character #{offset}" if offset}#{" of '#{filename}'" if filename}
|
|
|
|
Setting #{types} with = has been deprecated and will be removed in version 3.2.
|
2010-03-29 19:00:24 -07:00
|
|
|
Use "#{name}: #{val}" instead.
|
2010-03-06 17:17:51 -08:00
|
|
|
MESSAGE
|
|
|
|
end
|
2008-10-12 19:03:06 -07:00
|
|
|
end
|
|
|
|
end
|