Skip to content

Commit 6e3bce9

Browse files
committed
introducing classes to track issues
1 parent 09fa127 commit 6e3bce9

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

pylasu/parsing/results.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from dataclasses import dataclass
2+
from typing import List
3+
4+
from antlr4 import ParserRuleContext, Token
5+
6+
from pylasu.model import Source
7+
from pylasu.validation.validation import WithIssues, IssueType, Issue
8+
9+
10+
@dataclass
11+
class FirstStageResult(WithIssues):
12+
parse_tree: ParserRuleContext
13+
14+
15+
@dataclass
16+
class LexingResult(WithIssues):
17+
tokens: List[Token]
18+
19+
20+
@dataclass
21+
class IssuesErrorListener:
22+
"""This Error Listener should be used with ANTLR lexers and parsers to capture issues"""
23+
type: IssueType
24+
source: Source
25+
issues: WithIssues
26+
27+
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
28+
self.issues.append(Issue(type=self.type, message=msg))
29+
30+
def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
31+
pass
32+
33+
def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
34+
pass
35+
36+
def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
37+
pass

pylasu/validation/validation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi
3939
class Result:
4040
root: Node
4141
issues: List[Issue] = field(default_factory=list)
42+
43+
44+
class WithIssues:
45+
"""Many classes have the necessity of tracking issues"""
46+
issues: List[Issue]

0 commit comments

Comments
 (0)