-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing classes to track issues #26
Changes from 2 commits
6e3bce9
d5f2a68
6b2ee8d
1ffec00
bb7c4c5
293a63f
8ddcf05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,8 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi | |
class Result: | ||
root: Node | ||
issues: List[Issue] = field(default_factory=list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this extend WithIssues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I am just not sure of how the field definition works with inheritance, but I made the change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid having to repeat the property for each subclass, we could change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree that
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, then each subclass should be responsible of explicitly invoking the EDIT: I think we should go for the solution proposed by @alessiostalla - i.e. adding |
||
|
||
|
||
class WithIssues: | ||
"""Many classes have the necessity of tracking issues""" | ||
issues: List[Issue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FirstStageResult
should have anissues: List[Issue] = default_factory(list)
property to avoid adataclass
missing field error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the
issues
list here would not be required if following the comment concerningWithIssues
below