Mapytex/mapytex/calculus/core/typing/__init__.py

45 lines
884 B
Python

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2017 lafrite <lafrite@Poivre>
#
# Distributed under terms of the MIT license.
"""
Computing with MO
"""
from .exceptions import TypingError
# from .add import add
# from .minus import minus
# from .multiply import multiply
from .divide import divide
OPERATIONS = {
# "+": add,
# "-": minus,
# "*": multiply,
"/": divide,
}
def typing(node, left_v, right_v):
"""
Typing a try base on his root node
:example:
>>> from ..MO.mo import MOnumber
"""
try:
operation = OPERATIONS[node]
except KeyError:
raise TypingError(f"Unknown operation ({node})")
return operation(left_v, right_v)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del