Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiostalla committed Oct 10, 2023
2 parents 7821a79 + b3a06ae commit e1b21f0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ __pycache__
/.token
/antlr-*.jar
.DS_Store
.coverage
37 changes: 37 additions & 0 deletions pylasu/parsing/results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from dataclasses import dataclass
from typing import List

from antlr4 import ParserRuleContext, Token

from pylasu.model import Source
from pylasu.validation.validation import WithIssues, IssueType, Issue


@dataclass
class FirstStageResult(WithIssues):
parse_tree: ParserRuleContext


@dataclass
class LexingResult(WithIssues):
tokens: List[Token]


@dataclass
class IssuesErrorListener:
"""This Error Listener should be used with ANTLR lexers and parsers to capture issues"""
type: IssueType
source: Source
issues: WithIssues

def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
self.issues.append(Issue(type=self.type, message=msg))

def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
pass

def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
pass

def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
pass
9 changes: 7 additions & 2 deletions pylasu/validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi


@dataclass
class Result:
class WithIssues:
"""Many classes have the necessity of tracking issues"""
issues: List[Issue] = field(default_factory=list, init=False)


@dataclass
class Result(WithIssues):
root: Node
issues: List[Issue] = field(default_factory=list)

0 comments on commit e1b21f0

Please sign in to comment.