Skip to content

Commit f97d593

Browse files
committed
feat: expose parser in argus
1 parent 50d5a0a commit f97d593

File tree

7 files changed

+241
-66
lines changed

7 files changed

+241
-66
lines changed

argus-core/src/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ pub enum ExprRef<'a> {
119119
}
120120

121121
/// An expression (either [`BoolExpr`] or [`NumExpr`])
122-
#[derive(Clone, Debug, derive_more::From, derive_more::TryInto)]
122+
#[derive(Clone, Debug)]
123+
#[enum_dispatch(AnyExpr)]
123124
pub enum Expr {
124125
/// A reference to a [`BoolExpr`]
125126
Bool(BoolExpr),

pyargus/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ log = "0.4.20"
1818
paste = "1.0.14"
1919
pyo3 = "0.19.2"
2020
pyo3-log = "0.8.3"
21+
ariadne = "0.3.0"

pyargus/argus/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List, Optional, Tuple, Type, Union
44

55
from . import _argus
6-
from ._argus import dtype
6+
from ._argus import dtype, parse_expr
77
from .exprs import ConstBool, ConstFloat, ConstInt, ConstUInt, VarBool, VarFloat, VarInt, VarUInt
88
from .signals import BoolSignal, FloatSignal, IntSignal, Signal, UnsignedIntSignal
99

@@ -87,6 +87,7 @@ def signal(
8787

8888
__all__ = [
8989
"dtype",
90+
"parse_expr",
9091
"declare_var",
9192
"literal",
9293
"signal",

pyargus/argus/_argus.pyi

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
from typing import ClassVar, Literal, Protocol, TypeAlias, final
1+
from typing import ClassVar, Literal, TypeAlias, final
22

33
from typing_extensions import Self
44

5-
class NumExpr(Protocol):
5+
def parse_expr(expr_str: str) -> Expr: ...
6+
7+
class Expr: ...
8+
9+
class NumExpr(Expr):
610
def __ge__(self, other: Self) -> NumExpr: ...
711
def __gt__(self, other: Self) -> NumExpr: ...
812
def __le__(self, other: Self) -> NumExpr: ...
@@ -64,7 +68,7 @@ class Div(NumExpr):
6468
class Abs(NumExpr):
6569
def __init__(self, arg: NumExpr) -> None: ...
6670

67-
class BoolExpr(Protocol):
71+
class BoolExpr(Expr):
6872
def __and__(self, other: Self) -> BoolExpr: ...
6973
def __invert__(self) -> BoolExpr: ...
7074
def __or__(self, other: Self) -> BoolExpr: ...
@@ -192,5 +196,9 @@ class FloatSignal(Signal):
192196
@final
193197
class Trace: ...
194198

195-
def eval_bool_semantics(expr: BoolExpr, trace: Trace) -> BoolSignal: ...
196-
def eval_robust_semantics(expr: BoolExpr, trace: Trace) -> BoolSignal: ...
199+
def eval_bool_semantics(
200+
expr: BoolExpr, trace: Trace, *, interpolation_method: _InterpolationMethod = "linear"
201+
) -> BoolSignal: ...
202+
def eval_robust_semantics(
203+
expr: BoolExpr, trace: Trace, *, interpolation_method: _InterpolationMethod = "linear"
204+
) -> BoolSignal: ...

pyargus/argus/exprs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ConstUInt,
1111
Div,
1212
Eventually,
13+
Expr,
1314
Mul,
1415
Negate,
1516
Next,
@@ -46,4 +47,7 @@
4647
"VarFloat",
4748
"VarInt",
4849
"VarUInt",
50+
"Expr",
51+
"BoolExpr",
52+
"NumExpr",
4953
]

0 commit comments

Comments
 (0)