Skip to content

Commit 1b35125

Browse files
committed
fix(argus-parser): correctly type variables under relationals
Also accept unicode symbols for temporal operations
1 parent f6b26b6 commit 1b35125

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

argus-parser/examples/dump_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
.with_color(Color::Yellow)
2424
}))
2525
.finish()
26-
.print(sources([(src.clone(), src.clone())]))
26+
.eprint(sources([(src.clone(), src.clone())]))
2727
.unwrap()
2828
});
2929
}

argus-parser/src/lexer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ pub fn lexer<'src>() -> impl Parser<'src, &'src str, Output<'src>, Error<'src>>
151151
just("=").to(Token::Assign),
152152
));
153153

154+
let temporal_op = choice((
155+
just("\u{25cb}").to(Token::Next), // ○
156+
just("\u{25ef}").to(Token::Next), // ◯
157+
just("\u{25c7}").to(Token::Eventually), // ◇
158+
just("\u{25a1}").to(Token::Always), // □
159+
));
160+
154161
// A parser for strings
155162
// Strings in our grammar are identifiers too
156163
let quoted_ident = just('"')
@@ -178,7 +185,7 @@ pub fn lexer<'src>() -> impl Parser<'src, &'src str, Output<'src>, Error<'src>>
178185
});
179186

180187
// A single token can be one of the above
181-
let token = choice((op, ctrl, quoted_ident, ident, number));
188+
let token = choice((op, temporal_op, ctrl, quoted_ident, ident, number)).boxed();
182189

183190
let comment = just("//").then(any().and_is(just('\n').not()).repeated()).padded();
184191

argus-parser/src/parser.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum UnaryOps {
5151
}
5252

5353
impl UnaryOps {
54-
fn default_type(&self) -> Type {
54+
fn default_args_type(&self) -> Type {
5555
match self {
5656
UnaryOps::Neg => Type::Float,
5757
_ => Type::Bool,
@@ -80,9 +80,18 @@ pub enum BinaryOps {
8080
}
8181

8282
impl BinaryOps {
83-
fn default_type(&self) -> Type {
83+
fn default_args_type(&self) -> Type {
8484
match self {
85-
BinaryOps::Add | BinaryOps::Sub | BinaryOps::Mul | BinaryOps::Div => Type::Float,
85+
BinaryOps::Add
86+
| BinaryOps::Sub
87+
| BinaryOps::Mul
88+
| BinaryOps::Div
89+
| BinaryOps::Lt
90+
| BinaryOps::Le
91+
| BinaryOps::Gt
92+
| BinaryOps::Ge
93+
| BinaryOps::Eq
94+
| BinaryOps::Neq => Type::Float,
8695
_ => Type::Bool,
8796
}
8897
}
@@ -124,12 +133,12 @@ impl<'src> Expr<'src> {
124133
op,
125134
interval: _,
126135
arg: _,
127-
} => op.default_type(),
136+
} => op.default_args_type(),
128137
Expr::Binary {
129138
op,
130139
interval: _,
131140
args: _,
132-
} => op.default_type(),
141+
} => op.default_args_type(),
133142
}
134143
}
135144

@@ -142,7 +151,7 @@ impl<'src> Expr<'src> {
142151
}
143152

144153
fn unary_op(op: UnaryOps, arg: Spanned<Self>, interval: Option<Spanned<Interval<'src>>>) -> Self {
145-
let arg = Box::new((arg.0.make_typed(op.default_type()), arg.1));
154+
let arg = Box::new((arg.0.make_typed(op.default_args_type()), arg.1));
146155
Self::Unary { op, interval, arg }
147156
}
148157

@@ -156,7 +165,7 @@ impl<'src> Expr<'src> {
156165

157166
let common_type = lhs.get_type().get_common_cast(rhs.get_type());
158167
let common_type = if Type::Unknown == common_type {
159-
op.default_type()
168+
op.default_args_type()
160169
} else {
161170
common_type
162171
};

0 commit comments

Comments
 (0)