lib/hotcell/errors.rb in hotcell-0.0.1 vs lib/hotcell/errors.rb in hotcell-0.1.0

- old
+ new

@@ -1,43 +1,52 @@ module Hotcell - class Errors - class ParseError < StandardError - def initialize line, column - @line, @column = line, column - end + class Error < StandardError + end + + class ParseError < Error + def initialize value, line, column + @value, @line, @column = value, line, column + super(compose_message) end + end - class UnexpectedSymbol < ParseError - def message - "Unexpected symbol at #{@line}:#{@column}" - end + class UnexpectedSymbol < ParseError + def compose_message + "Unexpected symbol `#{@value}` at #{@line}:#{@column}" end + end - class UnterminatedString < ParseError - def message - "Unterminated string starting at #{@line}:#{@column}" - end + class UnterminatedString < ParseError + def compose_message + "Unterminated string `#{@value}` starting at #{@line}:#{@column}" end + end - # class UnterminatedRegexp < ParseError - # def message - # "Unterminated regexp starting at: line #{@line}, column #{@column}" - # end - # end + # class UnterminatedRegexp < ParseError + # def compose_message + # "Unterminated regexp `#{@value}` starting at #{@line}:#{@column}" + # end + # end - class SyntaxError < StandardError - def initialize message, line = nil, column = nil - @message, @line, @column = message, line, column - end - - def message - "#{@message} at #{@line}:#{@column}" - end + class SyntaxError < Error + def initialize value, line, column + @value, @line, @column = value, line, column + super(compose_message) end - class BlockError < SyntaxError + def compose_message + "#{@value} at #{@line}:#{@column}" end + end - class ArgumentError < SyntaxError + class UnexpectedLexem < ParseError + def compose_message + "Unexpected #{@value} at #{@line}:#{@column}" end + end + + class BlockError < SyntaxError + end + + class ArgumentError < SyntaxError end end