summaryrefslogtreecommitdiff
path: root/modules/language/python/exceptions.scm
blob: 9d51116a8c556cb1b1e809f08cf419e5dc05996c (about) (plain)
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
57
58
59
60
61
62
63
(define-module (language python exceptions)
  #:use-module (oop pf-objects)
  #:use-module (oop goops)
  #:export (StopIteration GeneratorExit RuntimeError
                          Exception ValueError TypeError
                          IndexError KeyError AttributeError  ArgumentError
                          SyntaxError SystemException
                          OSError ProcessLookupError PermissionError
                          None NotImplemented NotImplementedError
			  RunTimeError AssertionError ImportError
                          ModuleNotFoundError BlockingIOError))

(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))

(define-python-class Exception ()
  (define __init__
    (case-lambda
      ((self)
       (values))
      ((self val . l)
       (set self 'value val))))
                 
  (define __repr__
    (lambda (self)
      (aif it (ref self 'value #f)
           (format #f "~a:~a"
                   (ref self '__name__) it)
           (format #f "~a"
                   (ref self '__name__))))))

(define-syntax define-er
  (syntax-rules ()
    ((_ nm k)
     (define-python-class nm (Exception)))
    ((_ nm w k)
     (define-python-class nm w))))

(define StopIteration          'StopIteration)
(define GeneratorExit          'GeneratorExit)
(define-er SystemException     'SystemException)
(define-er RuntimeError        'RuntimeError)
(define-er IndexError          'IndexError)
(define-er ArgumentError       'IndexError)
(define-er ValueError          'ValueError)
(define None                   'None)
(define-er KeyError            'KeyError)
(define-er TypeError           'TypeError)
(define-er AttributeError      'AttributeError)
(define-er SyntaxError         'SyntaxError)
(define-er OSError             'OSError)
(define-er ProcessLookupError  'ProcessLookupError)
(define-er PermissionError     'PermissionError)
(define-er NotImplementedError 'NotImplementedError)
(define-er RunTimeError        'RunTimeError)
(define AssertionError         'AssertionError)
(define-er ImportError         'ImportError)      
(define-er ModuleNotFoundError (ImportError) 'ModuleNotFoundError)
(define-er BlockingIOError     'BlockingIOError)

(define NotImplemented (list 'NotImplemented))