aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/formatting/prettyprint.py
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-19 03:20:59 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-19 15:25:07 +0200
commitef0dbc726749df434036b23480b89f01cbe67d44 (patch)
treeb7573b77a0662773ffe30b100d7537de3d56f21a /pyGHDL/dom/formatting/prettyprint.py
parent89f835733c4019c5cb087885a874f34cf4ff183d (diff)
downloadghdl-ef0dbc726749df434036b23480b89f01cbe67d44.tar.gz
ghdl-ef0dbc726749df434036b23480b89f01cbe67d44.tar.bz2
ghdl-ef0dbc726749df434036b23480b89f01cbe67d44.zip
Added handling of Parenthesis.
Diffstat (limited to 'pyGHDL/dom/formatting/prettyprint.py')
-rw-r--r--pyGHDL/dom/formatting/prettyprint.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py
index 8ee49275c..c10b7cf87 100644
--- a/pyGHDL/dom/formatting/prettyprint.py
+++ b/pyGHDL/dom/formatting/prettyprint.py
@@ -48,6 +48,7 @@ from pyGHDL.dom.Expression import (
NegationExpression,
ExponentiationExpression,
Aggregate,
+ ParenthesisExpression,
)
from pyGHDL.dom.Aggregates import (
SimpleAggregateElement,
@@ -70,18 +71,19 @@ ModeTranslation = {
}
UnaryExpressionTranslation = {
- IdentityExpression: " +",
- NegationExpression: " -",
- InverseExpression: "not ",
- AbsoluteExpression: "abs ",
+ IdentityExpression: (" +", ""),
+ NegationExpression: (" -", ""),
+ InverseExpression: ("not ", ""),
+ AbsoluteExpression: ("abs ", ""),
+ ParenthesisExpression: ("(", ")"),
}
BinaryExpressionTranslation = {
- AdditionExpression: " + ",
- SubtractionExpression: " - ",
- MultiplyExpression: " * ",
- DivisionExpression: " / ",
- ExponentiationExpression: "**",
+ AdditionExpression: ("", " + ", ""),
+ SubtractionExpression: ("", " - ", ""),
+ MultiplyExpression: ("", " * ", ""),
+ DivisionExpression: ("", " / ", ""),
+ ExponentiationExpression: ("", "**", ""),
}
@@ -401,8 +403,10 @@ class PrettyPrint:
except KeyError:
raise PrettyPrintException("Unhandled operator for unary expression.")
- return "{operator}{operand}".format(
- operand=self.formatExpression(expression.Operand), operator=operator
+ return "{leftOp}{operand}{rightOp}".format(
+ leftOp=operator[0],
+ rightOp=operator[1],
+ operand=self.formatExpression(expression.Operand),
)
elif isinstance(expression, BinaryExpression):
try:
@@ -410,10 +414,12 @@ class PrettyPrint:
except KeyError:
raise PrettyPrintException("Unhandled operator for binary expression.")
- return "{left}{operator}{right}".format(
- left=self.formatExpression(expression.LeftOperand),
- right=self.formatExpression(expression.RightOperand),
- operator=operator,
+ return "{leftOp}{leftExpr}{middleOp}{rightExpr}{rightOp}".format(
+ leftOp=operator[0],
+ middleOp=operator[1],
+ rightOp=operator[2],
+ leftExpr=self.formatExpression(expression.LeftOperand),
+ rightExpr=self.formatExpression(expression.RightOperand),
)
elif isinstance(expression, Aggregate):
return "({choices})".format(