mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
added nice syntax errors
This commit is contained in:
parent
1590713576
commit
1eec05d23a
6 changed files with 56 additions and 8 deletions
19
lib/coffee_script/parse_error.rb
Normal file
19
lib/coffee_script/parse_error.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
module CoffeeScript
|
||||
|
||||
class ParseError < Racc::ParseError
|
||||
|
||||
def initialize(token_id, value, stack)
|
||||
@token_id, @value, @stack = token_id, value, stack
|
||||
end
|
||||
|
||||
def message(source_file=nil)
|
||||
line = @value.respond_to?(:line) ? @value.line : "END"
|
||||
line_part = source_file ? "#{source_file}:#{line}:" : "line #{line}:"
|
||||
id_part = @token_id != @value.inspect ? ", unexpected #{@token_id.downcase}" : ""
|
||||
"#{line_part} syntax error for '#{@value.to_s}'#{id_part}"
|
||||
end
|
||||
alias_method :inspect, :message
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue