File size: 760 Bytes
e6b283b
2f664d2
 
e6b283b
2f664d2
3f6412b
 
e6b283b
3f6412b
e6b283b
3f6412b
e6b283b
3f6412b
e6b283b
2f664d2
e6b283b
2f664d2
3f6412b
e6b283b
3f6412b
e6b283b
3f6412b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# AUTO: Imports a module used by this file.
import re

# AUTO: Sets `_REDUNDANT_PREFIX`.
_REDUNDANT_PREFIX = re.compile(r'^(Semantic Error|Syntax Error|Type Mismatch|Runtime Error)\s*:?\s*', re.IGNORECASE)


# AUTO: Defines class `SemanticError`.
class SemanticError(Exception):
    # AUTO: Defines function `__init__`.
    def __init__(self, message, line):
        # AUTO: Calls `super`.
        super().__init__(message)
        # AUTO: Sets `clean`.
        clean = _REDUNDANT_PREFIX.sub('', str(message)).strip()
        # AUTO: Sets `self.message`.
        self.message = f"SEMANTIC error line {line}: {clean}"

    # AUTO: Defines function `__str__`.
    def __str__(self):
        # AUTO: Returns this result to the caller.
        return self.message