Skip to content

synt.expr.wrapped ¤

wrapped module-attribute ¤

wrapped = Wrapped

Alias Wrapped.

wrap module-attribute ¤

wrap = Wrapped

Alias Wrapped.

par module-attribute ¤

par = Wrapped

Alias Wrapped.

Wrapped ¤

Bases: Expression

A wrapped expression, aka ( expr ), which is always an atomic expression.

Examples:

wp = wrapped(litint(1) + litint(2)) * litint(3)
assert wp.into_code() == "(1 + 2) * 3"
Notes

Most plain expressions have their own expression precedence, and will be wrapped automatically by Synt. However, for those atomic expressions, some of them does have different parser precedence which is hard to represent beforehand. Thus, you must explicitly wrap them manually.

Source code in synt/expr/wrapped.py
class Wrapped(expr.Expression):
    r"""A wrapped expression, aka `( expr )`, which is always an atomic expression.

    Examples:
        ```python
        wp = wrapped(litint(1) + litint(2)) * litint(3)
        assert wp.into_code() == "(1 + 2) * 3"
        ```

    Notes:
        Most plain expressions have their own expression precedence, and will be wrapped
        automatically by Synt.
        However, for those atomic expressions, some of them does have different parser precedence
        which is hard to represent beforehand. Thus, you must explicitly wrap them manually.
    """

    inner: expr.Expression
    """Inner expression."""

    precedence = expr.ExprPrecedence.Atom
    expr_type = expr.ExprType.Wrapped

    def __init__(self, inner: expr.IntoExpression):
        """Initialize a wrapped expression.

        Args:
            inner: Inner expression.
        """
        self.inner = inner.into_expression()

    def into_code(self) -> str:
        return f"({self.inner.into_code()})"

precedence class-attribute instance-attribute ¤

precedence = Atom

expr_type class-attribute instance-attribute ¤

expr_type = Wrapped

inner instance-attribute ¤

inner: Expression = into_expression()

Inner expression.

__init__ ¤

__init__(inner: IntoExpression)

Initialize a wrapped expression.

Parameters:

Name Type Description Default
inner IntoExpression

Inner expression.

required
Source code in synt/expr/wrapped.py
def __init__(self, inner: expr.IntoExpression):
    """Initialize a wrapped expression.

    Args:
        inner: Inner expression.
    """
    self.inner = inner.into_expression()

into_code ¤

into_code() -> str
Source code in synt/expr/wrapped.py
def into_code(self) -> str:
    return f"({self.inner.into_code()})"