GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Fork of nex3/haml
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/chriseppstein/haml.git
Fix error line reporting.

Syntax errors involving a line being improperly indented
were detected on the previous line,
and thus had their line numbers wrong.

Conflicts:

  lib/haml/precompiler.rb
nex3 (author)
Thu Apr 17 18:12:27 -0700 2008
commit  b767fd1419a5d4cb7f87913a7ac4337e13fe7449
tree    a5f307f4235a193fae8f4333f43a8cb5dc7d53f8
parent  188d27eb03223dd4e336608f707430a0ba10d14c
...
74
75
76
77
 
78
79
80
...
74
75
76
 
77
78
79
80
0
@@ -74,7 +74,7 @@ END
0
 
0
       precompile
0
     rescue Haml::Error
0
- $!.backtrace.unshift "#{@options[:filename]}:#{@index}" if @index
0
+ $!.backtrace.unshift "#{@options[:filename]}:#{@index + $!.line_offset}" if @index
0
       raise
0
     end
0
 
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
...
1
2
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1,6 +1,20 @@
0
 module Haml
0
   # The abstract type of exception raised by Haml code.
0
- class Error < StandardError; end
0
+ class Error < StandardError
0
+ # :stopdoc:
0
+
0
+ # By default, an error is taken to refer to the line of the template
0
+ # that was being processed when the exception was raised.
0
+ # However, if line_offset is non-zero, it's added to that line number
0
+ # to get the line to report for the error.
0
+ attr_reader :line_offset
0
+
0
+ def initialize(message = nil, line_offset = 0)
0
+ super(message)
0
+ @line_offset = line_offset
0
+ end
0
+ # :startdoc:
0
+ end
0
 
0
   # SyntaxError is the type of exception raised when Haml encounters an
0
   # ill-formatted document.
...
158
159
160
161
 
162
163
164
...
166
167
168
169
 
170
171
172
...
293
294
295
296
 
297
298
299
...
518
519
520
521
522
523
524
 
 
 
 
525
526
527
...
569
570
571
572
 
573
574
575
...
590
591
592
593
 
594
595
596
...
661
662
663
664
 
665
666
667
...
158
159
160
 
161
162
163
164
...
166
167
168
 
169
170
171
172
...
293
294
295
 
296
297
298
299
...
518
519
520
 
 
 
 
521
522
523
524
525
526
527
...
569
570
571
 
572
573
574
575
...
590
591
592
 
593
594
595
596
...
661
662
663
 
664
665
666
667
0
@@ -158,7 +158,7 @@ END
0
         end
0
 
0
         if old_line.spaces != old_line.tabs * 2
0
- raise SyntaxError.new("Illegal Indentation: Only two space characters are allowed as tabulation.")
0
+ raise SyntaxError.new("Illegal Indentation: Only two space characters are allowed as tabulation.", 1)
0
         end
0
 
0
         unless old_line.text.empty? || @haml_comment
0
@@ -166,7 +166,7 @@ END
0
         end
0
 
0
         if !flat? && line.tabs - old_line.tabs > 1
0
- raise SyntaxError.new("Illegal Indentation: Indenting more than once per line is illegal.")
0
+ raise SyntaxError.new("Illegal Indentation: Indenting more than once per line is illegal.", 1)
0
         end
0
         old_line = line
0
         newline
0
@@ -293,7 +293,7 @@ END
0
     # Renders a block of text as plain text.
0
     # Also checks for an illegally opened block.
0
     def push_plain(text)
0
- raise SyntaxError.new("Illegal Nesting: Nesting within plain text is illegal.") if @block_opened
0
+ raise SyntaxError.new("Illegal Nesting: Nesting within plain text is illegal.", 1) if @block_opened
0
       push_text text
0
     end
0
 
0
@@ -518,10 +518,10 @@ END
0
       attributes = parse_class_and_id(attributes)
0
       Buffer.merge_attrs(attributes, static_attributes) if static_attributes
0
 
0
- raise SyntaxError.new("Illegal Nesting: Nesting within an atomic tag is illegal.") if @block_opened && atomic
0
- raise SyntaxError.new("Illegal Nesting: Content can't be both given on the same line as %#{tag_name} and nested within it.") if @block_opened && !value.empty?
0
- raise SyntaxError.new("Tag has no content.") if parse && value.empty?
0
- raise SyntaxError.new("Atomic tags can't have content.") if atomic && !value.empty?
0
+ raise SyntaxError.new("Illegal Nesting: Nesting within an atomic tag is illegal.", 1) if @block_opened && atomic
0
+ raise SyntaxError.new("Illegal Nesting: Content can't be both given on the same line as %#{tag_name} and nested within it.", 1) if @block_opened && !value.empty?
0
+ raise SyntaxError, "Tag has no content." if parse && value.empty?
0
+ raise SyntaxError, "Atomic tags can't have content." if atomic && !value.empty?
0
 
0
       atomic = true if !@block_opened && value.empty? && @options[:autoclose].include?(tag_name)
0
 
0
@@ -569,7 +569,7 @@ END
0
       conditional << ">" if conditional
0
 
0
       if @block_opened && !content.empty?
0
- raise SyntaxError.new('Illegal Nesting: Nesting within a tag that already has content is illegal.')
0
+ raise SyntaxError.new('Illegal Nesting: Nesting within a tag that already has content is illegal.', 1)
0
       end
0
 
0
       open = "<!--#{conditional} "
0
@@ -590,7 +590,7 @@ END
0
 
0
     # Renders an XHTML doctype or XML shebang.
0
     def render_doctype(line)
0
- raise SyntaxError.new("Illegal Nesting: Nesting within a header command is illegal.") if @block_opened
0
+ raise SyntaxError.new("Illegal Nesting: Nesting within a header command is illegal.", 1) if @block_opened
0
       push_text text_for_doctype(line)
0
     end
0
 
0
@@ -661,7 +661,7 @@ END
0
       spaces = line.index(/([^ ]|$)/)
0
       if line[spaces] == ?\t
0
         return nil if line.strip.empty?
0
- raise SyntaxError.new("Illegal Indentation: Only two space characters are allowed as tabulation.")
0
+ raise SyntaxError.new("Illegal Indentation: Only two space characters are allowed as tabulation.", 2)
0
       end
0
       [spaces, spaces/2]
0
     end
...
216
217
218
219
 
220
221
222
...
216
217
218
 
219
220
221
222
0
@@ -216,7 +216,7 @@ class EngineTest < Test::Unit::TestCase
0
     render("a\nb\n!!!\n c\nd")
0
   rescue Haml::SyntaxError => e
0
     assert_equal(e.message, "Illegal Nesting: Nesting within a header command is illegal.")
0
- assert_equal("(haml):3", e.backtrace[0])
0
+ assert_equal("(haml):4", e.backtrace[0])
0
   rescue Exception => e
0
     assert(false, '"a\nb\n!!!\n c\nd" doesn\'t produce a Haml::SyntaxError')
0
   else

Comments

    No one has commented yet.