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

[Sass] Report context information for Sass::CSS parsing errors.

This commit is contained in:
Nathan Weizenbaum 2009-06-19 13:36:49 -07:00
parent 7d1f21d508
commit 1a879c909e

View file

@ -181,13 +181,26 @@ module Sass
#
# @param re [Regexp] The regular expression to assert
def assert_match(re)
if !@template.scan(re)
line = @template.string[0..@template.pos].count "\n"
# Display basic regexps as plain old strings
expected = re.source == Regexp.escape(re.source) ? "\"#{re.source}\"" : re.inspect
raise Exception.new("Invalid CSS on line #{line + 1}: expected #{expected}")
if @template.scan(re)
whitespace
return
end
whitespace
line = @template.string[0..@template.pos].count "\n"
pos = @template.pos
after = @template.string[pos - 15...pos]
after = "..." + after if pos >= 15
# Display basic regexps as plain old strings
expected = re.source == Regexp.escape(re.source) ? "\"#{re.source}\"" : re.inspect
was = @template.rest[0...15]
was += "..." if @template.rest.size >= 15
raise Exception.new(<<MESSAGE)
Invalid CSS on line #{line + 1} after #{after.inspect}:
expected #{expected}, was #{was.inspect}
MESSAGE
end
# Transform