kata/calculator/calculator/ast/visit/visitor.py
Bruno BELANYI 5ea82de840 calculator: add initial AST implementation
The AST's class hierarchy is defined inside the `calculator.ast` module.

An abstract visitor is defined inside the `calculator.ast.visit`
package.
2019-11-30 15:21:04 +01:00

29 lines
589 B
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from calculator.ast import BinOp, Constant, Node, UnaryOp
class Visitor(ABC):
"""
Abstract Visitor class for the AST class hierarchy.
"""
def visit(self, n: Node) -> None:
n.accept(self)
@abstractmethod
def visit_constant(self, c: Constant) -> None:
pass
@abstractmethod
def visit_binop(self, b: BinOp) -> None:
pass
@abstractmethod
def visit_unaryop(self, b: UnaryOp) -> None:
pass