Skip to content

Commit e1b21f0

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 7821a79 + b3a06ae commit e1b21f0

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ __pycache__
1313
/.token
1414
/antlr-*.jar
1515
.DS_Store
16+
.coverage

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi
3636

3737

3838
@dataclass
39-
class Result:
39+
class WithIssues:
40+
"""Many classes have the necessity of tracking issues"""
41+
issues: List[Issue] = field(default_factory=list, init=False)
42+
43+
44+
@dataclass
45+
class Result(WithIssues):
4046
root: Node
41-
issues: List[Issue] = field(default_factory=list)

0 commit comments

Comments
 (0)