1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Pass options through the lexer and parser.

This commit is contained in:
Nathan Weizenbaum 2009-12-01 18:00:35 -08:00
parent 4466cadd5f
commit b686ddd176
5 changed files with 23 additions and 18 deletions

View file

@ -470,7 +470,8 @@ LONG
raise SyntaxError.new("Invalid mixin \"#{line.text[1..-1]}\".") if name.nil?
offset = line.offset + line.text.size - arg_string.size
args = Script::Parser.new(arg_string.strip, @line, offset).parse_mixin_definition_arglist
args = Script::Parser.new(arg_string.strip, @line, offset, @options).
parse_mixin_definition_arglist
default_arg_found = false
Tree::MixinDefNode.new(name, args)
end
@ -480,7 +481,8 @@ LONG
raise SyntaxError.new("Invalid mixin include \"#{line.text}\".") if name.nil?
offset = line.offset + line.text.size - arg_string.size
args = Script::Parser.new(arg_string.strip, @line, offset).parse_mixin_include_arglist
args = Script::Parser.new(arg_string.strip, @line, offset, @options).
parse_mixin_include_arglist
raise SyntaxError.new("Illegal nesting: Nothing may be nested beneath mixin directives.",
:line => @line + 1) unless line.children.empty?
Tree::MixinNode.new(name, args)
@ -489,7 +491,7 @@ LONG
def parse_script(script, options = {})
line = options[:line] || @line
offset = options[:offset] || 0
Script.parse(script, line, offset, @options[:filename])
Script.parse(script, line, offset, @options)
end
end
end

View file

@ -28,14 +28,14 @@ module Sass
# 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
# @param options [{Symbol => Object}] An options hash;
# see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
# @return [Script::Node] The root node of the parse tree
def self.parse(value, line, offset, filename = nil)
Parser.parse(value, line, offset, filename)
def self.parse(value, line, offset, options = {})
Parser.parse(value, line, offset, options)
rescue Sass::SyntaxError => e
e.message << ": #{value.inspect}." if e.message == "SassScript error"
e.modify_backtrace(:line => line, :filename => filename)
e.modify_backtrace(:line => line, :filename => options[:filename])
raise e
end
end

View file

@ -85,11 +85,13 @@ module Sass
# Used for error reporting
# @param offset [Fixnum] The number of characters in on which the SassScript appears.
# Used for error reporting
def initialize(str, line, offset, filename)
# @param options [{Symbol => Object}] An options hash;
# see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
def initialize(str, line, offset, options)
@scanner = str.is_a?(StringScanner) ? str : StringScanner.new(str)
@line = line
@offset = offset
@filename = filename
@options = options
@interpolation_stack = []
@prev = nil
end

View file

@ -10,11 +10,11 @@ module Sass
# Used for error reporting
# @param offset [Fixnum] The number of characters in on which the SassScript appears.
# Used for error reporting
# @param filename [String] The name of the file in which the SassScript appears.
# Used for error reporting
def initialize(str, line, offset, filename = nil)
@filename = filename
@lexer = Lexer.new(str, line, offset, filename)
# @param options [{Symbol => Object}] An options hash;
# see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
def initialize(str, line, offset, options = {})
@options = options
@lexer = Lexer.new(str, line, offset, options)
end
# Parses a SassScript expression within an interpolated segment (`#{}`).
@ -138,9 +138,10 @@ RUBY
return paren unless name = try_tok(:ident)
# An identifier without arguments is just a string
unless try_tok(:lparen)
filename = @options[:filename]
warn(<<END)
DEPRECATION WARNING:
On line #{name.line}, character #{name.offset}#{" of '#{@filename}'" if @filename}
On line #{name.line}, character #{name.offset}#{" of '#{filename}'" if filename}
Implicit strings have been deprecated and will be removed in version 2.4.
'#{name.value}' was not quoted. Please add double quotes (e.g. "#{name.value}").
END

View file

@ -288,8 +288,8 @@ WARN
def eval(str, opts = {}, environment = env)
munge_filename opts
Sass::Script.parse(str, opts[:line] || 1,
opts[:offset] || 0, opts[:filename]).perform(environment)
Sass::Script.parse(str, opts.delete(:line) || 1,
opts.delete(:offset) || 0, opts).perform(environment)
end
def render(sass, options = {})