File: error.rb

package info (click to toggle)
mikutter 5.0.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,700 kB
  • sloc: ruby: 21,307; sh: 181; makefile: 19
file content (56 lines) | stat: -rw-r--r-- 1,337 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
module MIKU


  class MikuException < Exception
  end

  class ExceptionDelegator < Exception
    def initialize(msg, exceptionclass)
      @exceptionclass = exceptionclass
      super(msg)
    end

    def fire(scan)
      puts self.backtrace.join("\n")
      raise @exceptionclass.new(to_s, scan)
    end
  end

  class SyntaxError < MikuException
    def initialize(msg, scan)
      super(msg + " #{scan.staticcode_file} in line #{scan.staticcode_line}\n  #{MIKU.unparse(scan)}")
    end
  end

  class ArgumentError < MikuException
    def initialize(msg, scan)
      super(msg + " #{scan.staticcode_file} in line #{scan.staticcode_line}\n  #{MIKU.unparse(scan)}")
    end
  end

  class TypeError < MikuException
    def initialize(msg, scan)
      super(msg + " #{scan.staticcode_file} in line #{scan.staticcode_line}\n  #{MIKU.unparse(scan)}")
    end
  end

  def parse_caller(at)
    if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
      file = $1
      line = $2.to_i
      method = $3
      [file, line, method]
    end
  end

  class NoMithodError < MikuException
    def initialize(name, scan)
      super("undefined function '#{name.inspect}' #{scan.staticcode_file rescue '?'} in line #{scan.staticcode_line rescue '?'}\n  #{MIKU.unparse(scan)}")
    end
  end

  class EndofFile < MikuException
  end

end