From 6e3bce97457e4243a738bb70ed1e125ef002656c Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 27 Sep 2023 13:29:55 +0200 Subject: [PATCH 1/7] introducing classes to track issues --- pylasu/parsing/results.py | 37 +++++++++++++++++++++++++++++++++ pylasu/validation/validation.py | 5 +++++ 2 files changed, 42 insertions(+) create mode 100644 pylasu/parsing/results.py diff --git a/pylasu/parsing/results.py b/pylasu/parsing/results.py new file mode 100644 index 0000000..22dbda4 --- /dev/null +++ b/pylasu/parsing/results.py @@ -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 \ No newline at end of file diff --git a/pylasu/validation/validation.py b/pylasu/validation/validation.py index 9616de0..c8d9de7 100644 --- a/pylasu/validation/validation.py +++ b/pylasu/validation/validation.py @@ -39,3 +39,8 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi class Result: root: Node issues: List[Issue] = field(default_factory=list) + + +class WithIssues: + """Many classes have the necessity of tracking issues""" + issues: List[Issue] From d5f2a68576d6edbf3137b6a7a2d9ae2840c33c02 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 27 Sep 2023 13:33:32 +0200 Subject: [PATCH 2/7] adding missing newline --- pylasu/parsing/results.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylasu/parsing/results.py b/pylasu/parsing/results.py index 22dbda4..17c9fda 100644 --- a/pylasu/parsing/results.py +++ b/pylasu/parsing/results.py @@ -34,4 +34,4 @@ def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, co pass def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs): - pass \ No newline at end of file + pass From 6b2ee8d281bb8cd38989eb35dfb492e3b1c519a7 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 27 Sep 2023 16:20:53 +0200 Subject: [PATCH 3/7] making Result extend WithIssues --- pylasu/validation/validation.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pylasu/validation/validation.py b/pylasu/validation/validation.py index c8d9de7..3892957 100644 --- a/pylasu/validation/validation.py +++ b/pylasu/validation/validation.py @@ -35,12 +35,11 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi return Issue(IssueType.SEMANTIC, message, severity, position) -@dataclass -class Result: - root: Node +class WithIssues: + """Many classes have the necessity of tracking issues""" issues: List[Issue] = field(default_factory=list) -class WithIssues: - """Many classes have the necessity of tracking issues""" - issues: List[Issue] +@dataclass +class Result(WithIssues): + root: Node From 1ffec00b1302ad24090e06270b94307fb82155e0 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Thu, 28 Sep 2023 08:41:39 +0200 Subject: [PATCH 4/7] making WithIssues a dataclass --- pylasu/parsing/results.py | 4 +++- pylasu/validation/validation.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pylasu/parsing/results.py b/pylasu/parsing/results.py index 17c9fda..856f8f4 100644 --- a/pylasu/parsing/results.py +++ b/pylasu/parsing/results.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import List from antlr4 import ParserRuleContext, Token @@ -10,11 +10,13 @@ @dataclass class FirstStageResult(WithIssues): parse_tree: ParserRuleContext + issues: List[Issue] = field(default_factory=list) @dataclass class LexingResult(WithIssues): tokens: List[Token] + issues: List[Issue] = field(default_factory=list) @dataclass diff --git a/pylasu/validation/validation.py b/pylasu/validation/validation.py index 3892957..e912891 100644 --- a/pylasu/validation/validation.py +++ b/pylasu/validation/validation.py @@ -35,11 +35,14 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi return Issue(IssueType.SEMANTIC, message, severity, position) +@dataclass class WithIssues: """Many classes have the necessity of tracking issues""" - issues: List[Issue] = field(default_factory=list) + issues: List[Issue] @dataclass class Result(WithIssues): root: Node + issues: List[Issue] = field(default_factory=list) + From bb7c4c5439d008ec2d9bc0671f0a494290db0cf3 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Thu, 28 Sep 2023 08:42:40 +0200 Subject: [PATCH 5/7] ignore .coverage report --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 33701b9..c18a447 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ __pycache__ /.token /antlr-*.jar .DS_Store +.coverage From 293a63f6f6172b158baf4c934675f4ffae1f5579 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Thu, 28 Sep 2023 08:45:50 +0200 Subject: [PATCH 6/7] linting --- pylasu/validation/validation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pylasu/validation/validation.py b/pylasu/validation/validation.py index e912891..e5270fb 100644 --- a/pylasu/validation/validation.py +++ b/pylasu/validation/validation.py @@ -45,4 +45,3 @@ class WithIssues: class Result(WithIssues): root: Node issues: List[Issue] = field(default_factory=list) - From 8ddcf05b28bdda2f0bfd2585f649f55857459e9b Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Fri, 29 Sep 2023 15:22:10 +0200 Subject: [PATCH 7/7] make WithIssues.issues not appear in constructor --- pylasu/parsing/results.py | 4 +--- pylasu/validation/validation.py | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pylasu/parsing/results.py b/pylasu/parsing/results.py index 856f8f4..17c9fda 100644 --- a/pylasu/parsing/results.py +++ b/pylasu/parsing/results.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass, field +from dataclasses import dataclass from typing import List from antlr4 import ParserRuleContext, Token @@ -10,13 +10,11 @@ @dataclass class FirstStageResult(WithIssues): parse_tree: ParserRuleContext - issues: List[Issue] = field(default_factory=list) @dataclass class LexingResult(WithIssues): tokens: List[Token] - issues: List[Issue] = field(default_factory=list) @dataclass diff --git a/pylasu/validation/validation.py b/pylasu/validation/validation.py index e5270fb..dc96734 100644 --- a/pylasu/validation/validation.py +++ b/pylasu/validation/validation.py @@ -38,10 +38,9 @@ def semantic(message: str, severity: IssueSeverity = IssueSeverity.ERROR, positi @dataclass class WithIssues: """Many classes have the necessity of tracking issues""" - issues: List[Issue] + issues: List[Issue] = field(default_factory=list, init=False) @dataclass class Result(WithIssues): root: Node - issues: List[Issue] = field(default_factory=list)