2018-01-21 08:26:34 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim:fenc=utf-8
|
|
|
|
#
|
|
|
|
# Copyright © 2017 lafrite <lafrite@Poivre>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
|
2018-03-10 05:44:01 +00:00
|
|
|
__all__ = ["OperatorError", "OPERATORS", "is_operator"]
|
|
|
|
|
2019-05-14 04:55:56 +00:00
|
|
|
|
2018-03-07 13:26:06 +00:00
|
|
|
class OperatorError(Exception):
|
|
|
|
pass
|
|
|
|
|
2019-05-14 04:55:56 +00:00
|
|
|
|
2018-01-21 08:26:34 +00:00
|
|
|
OPERATORS = {
|
2019-05-14 04:55:56 +00:00
|
|
|
"+": {"repr": "+", "arity": 2, "precedence": 0},
|
|
|
|
"-": {"repr": "-", "arity": 1, "precedence": 1},
|
|
|
|
"*": {"repr": "*", "arity": 2, "precedence": 2},
|
|
|
|
"/": {"repr": "/", "arity": 2, "precedence": 3},
|
|
|
|
"^": {"repr": "^", "arity": 2, "precedence": 4},
|
2018-01-21 08:26:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 04:55:56 +00:00
|
|
|
|
2018-02-02 15:02:42 +00:00
|
|
|
def is_operator(string):
|
|
|
|
""" Return whether a string is an operator or not
|
|
|
|
|
|
|
|
:param string: string to test
|
|
|
|
:returns: boolean
|
|
|
|
|
|
|
|
:example:
|
|
|
|
|
|
|
|
>>> is_operator("+")
|
|
|
|
True
|
|
|
|
>>> is_operator("i")
|
|
|
|
False
|
|
|
|
|
|
|
|
"""
|
|
|
|
return string in OPERATORS.keys()
|
|
|
|
|
2018-01-21 08:26:34 +00:00
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|