Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/python-wasm
Path: blob/main/python/pylang/src/errors.py
1396 views
1
# mypy
2
from __python__ import hash_literals, Error # type: ignore
3
4
5
class SyntaxError(Error):
6
def __init__(self, message, filename, line: int, col: int, pos: int,
7
is_eof: bool):
8
self.stack = Error().stack
9
self.message = message
10
self.line = line
11
self.col = col
12
self.pos = pos
13
self.is_eof = is_eof
14
self.filename = filename
15
# The "standard" form for these error attributes
16
self.lineNumber = line
17
self.fileName = filename
18
19
def toString(self):
20
ans = self.message + " (line: " + self.line + ", col: " + self.col + ", pos: " + self.pos + ")"
21
if self.filename:
22
ans = self.filename + ':' + ans
23
if self.stack:
24
ans += "\n\n" + self.stack
25
return ans
26
27
28
class ImportError(SyntaxError):
29
pass
30
31
32
class EOFError(Error):
33
pass
34
35
36
class RuntimeError(Error):
37
def __init__(self, message):
38
self.message = message
39
40
def __call__(self, message):
41
return RuntimeError(message)
42
43