Skip to content

Commit

Permalink
Base expressions on dataclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Jul 18, 2023
1 parent 6e9c0a4 commit 08b9e4f
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 422 deletions.
14 changes: 7 additions & 7 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ You can also easily define your own objects to use inside an expression:

.. doctest::

>>> from pymbolic.primitives import Expression
>>> class FancyOperator(Expression):
... def __init__(self, operand):
... self.operand = operand
...
... def __getinitargs__(self):
... return (self.operand,)
>>> from pymbolic.primitives import Expression, augment_expression_dataclass
>>> from dataclasses import dataclass
>>>
>>> @augment_expression_dataclass
... @dataclass(frozen=True)
... class FancyOperator(Expression):
... operand: Expression
...
... mapper_method = "map_fancy_operator"
...
Expand Down
4 changes: 3 additions & 1 deletion pymbolic/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
THE SOFTWARE.
"""

import immutables
import pytools.lex
from pytools import memoize_method
from sys import intern
Expand Down Expand Up @@ -330,7 +331,8 @@ def parse_postfix(self, pstate, min_precedence, left_exp):
args, kwargs = self.parse_arglist(pstate)

if kwargs:
left_exp = primitives.CallWithKwargs(left_exp, args, kwargs)
left_exp = primitives.CallWithKwargs(
left_exp, args, immutables.Map(kwargs))
else:
left_exp = primitives.Call(left_exp, args)

Expand Down
Loading

0 comments on commit 08b9e4f

Please sign in to comment.