-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_handling.py
61 lines (35 loc) · 1.77 KB
/
error_handling.py
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
# Reserved javascript keywords
reserved_words = ['break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
'else', 'export', 'extends', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
'new', 'return', 'super', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while',
'with', 'yield']
# syntax error are handled with Python SyntaxError exception
class JavaScriptSyntaxError(SyntaxError):
def __str__(self): # taken from lark documentation
context, line, column = self.args
return '%s at line %s, column %s.\n\n%s' % (self.label, line, column, context)
class UnmatchedParenthesisError(JavaScriptSyntaxError):
pass
class MissingClosingParenthesisAfterCondition(UnmatchedParenthesisError):
label = 'Syntax Error: Missing ) after condition'
class MissingClosingParenthesisAfterElementList(UnmatchedParenthesisError):
label = 'Syntax Error: Missing ] after element list'
class MissingClosingParenthesisAfterFunctionBody(UnmatchedParenthesisError):
label = 'Syntax Error: Missing } after function body'
class MissingEqualInConstDeclaration(JavaScriptSyntaxError):
label = 'Syntax Error: Missing = in const declaration'
class UnexpectedEndOfInput(JavaScriptSyntaxError):
label = 'Syntax Error: Unexpected end of input'
class IdentifierAlreadyDeclared(JavaScriptSyntaxError):
pass
class ReservedWordAsIdentifier(JavaScriptSyntaxError):
pass
# semantic error are handled with Python Exception class
class JavaScriptSemanticError(Exception):
pass
class ReferenceError(JavaScriptSemanticError):
pass
class IsNotAFunction(JavaScriptSemanticError):
pass
class ConstAssignmentTypeError(JavaScriptSemanticError):
pass