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
|
|
|
|
# The character that begins a variable.
|
|
|
|
VARIABLE_CHAR = ?!
|
|
|
|
|
2009-04-23 17:29:06 -07:00
|
|
|
# The regular expression used to parse variables.
|
2009-03-22 02:57:40 -07:00
|
|
|
MATCH = /^!([a-zA-Z_]\w*)\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.
|
2009-03-22 02:57:40 -07:00
|
|
|
VALIDATE = /^![a-zA-Z_]\w*$/
|
2008-10-12 19:03:06 -07:00
|
|
|
|
2009-04-23 17:29:06 -07:00
|
|
|
# Parses and evaluates 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
|
|
|
|
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
|
|
|
# @return [String] The string result of evaluating the SassScript
|
2008-12-09 12:09:34 -08:00
|
|
|
def self.resolve(value, line, offset, environment)
|
|
|
|
parse(value, line, offset).perform(environment).to_s
|
2008-10-12 19:03:06 -07:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
# @param filename [String] The path to the file in which the SassScript appeared.
|
|
|
|
# Used for error reporting
|
2009-04-25 02:00:36 -07:00
|
|
|
# @return [Script::Node] The root node of the parse tree
|
2008-12-10 01:05:30 -08:00
|
|
|
def self.parse(value, line, offset, filename = nil)
|
|
|
|
Parser.parse(value, line, offset, filename)
|
2008-10-12 19:03:06 -07:00
|
|
|
rescue Sass::SyntaxError => e
|
|
|
|
if e.message == "SassScript error"
|
|
|
|
e.instance_eval do
|
|
|
|
@message += ": #{value.dump}."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
e.sass_line = line
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|