Skip to content

Commit c2b63f5

Browse files
committed
Defines parser errors
1 parent 784b0fb commit c2b63f5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/syntactes/parser/exception.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class ParserError(Exception): ...
2+
3+
4+
class UnexpectedTokenError(ParserError):
5+
"""
6+
A token was received that does not map to an action. The stream of tokens
7+
is syntactically invalid.
8+
"""
9+
10+
def __init__(self, received_token, expected_tokens):
11+
self.received_token = received_token
12+
self.expected_tokens = expected_tokens
13+
msg = f"Received token: {received_token}; expected one of: {[str(e) for e in expected_tokens]}"
14+
super().__init__(msg)
15+
16+
17+
class NotAcceptedError(ParserError):
18+
"""
19+
The parser did not receive an accept action. The stream of tokens is
20+
syntactically invalid.
21+
"""

0 commit comments

Comments
 (0)