From 4ef1e63ee4a7c0499641f4a3029766609db101c6 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 12 May 2023 01:30:02 +0200 Subject: [PATCH] nodes: add PseudoNode to store fake nodes used to improve diagnostics --- compiler/nodes.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/compiler/nodes.py b/compiler/nodes.py index e5a6b2f..ac79886 100644 --- a/compiler/nodes.py +++ b/compiler/nodes.py @@ -6,7 +6,7 @@ from typing import Any, Iterable from beartype import beartype -from . import ir, semantic +from . import ir, semantic, tokenizer from .errors import SemanticAnalysisError, OverrideMandatoryError from .logger import Logger from .source import SourceLocation @@ -111,6 +111,22 @@ class Literal(Node, ABC): return result +class PseudoNode(Literal): + """ + Only used for better diagnostics + """ + + def __init__(self, token: tokenizer.Token): + super().__init__(token.loc, token.value) + self.token = token + + def intermediate_representation(self) -> list[ir.IRItem]: + return [] + + def semantic_analysis(self, context: semantic.Context): + pass + + class Sum(Node): def intermediate_representation(self) -> list[ir.IRItem]: result: list[ir.IRAction] = []