|
1 | 1 | use crate::ast::{ |
2 | | - BinaryOp, BindX, Binder, BinderX, Binders, Command, CommandX, Commands, Constant, Decl, DeclX, |
3 | | - Decls, Expr, ExprX, Exprs, Ident, MultiOp, Qid, Quant, QueryX, Relation, Stmt, StmtX, Stmts, |
4 | | - Trigger, Triggers, Typ, TypX, UnaryOp, |
| 2 | + Axiom, BinaryOp, BindX, Binder, BinderX, Binders, Command, CommandX, Commands, Constant, Decl, |
| 3 | + DeclX, Decls, Expr, ExprX, Exprs, Ident, MultiOp, Qid, Quant, QueryX, Relation, Stmt, StmtX, |
| 4 | + Stmts, Trigger, Triggers, Typ, TypX, UnaryOp, |
5 | 5 | }; |
6 | 6 | use crate::def::mk_skolem_id; |
7 | 7 | use crate::messages::ArcDynMessageLabel; |
@@ -444,6 +444,28 @@ impl Parser { |
444 | 444 | } |
445 | 445 | } |
446 | 446 |
|
| 447 | + fn nodes_to_named(&self, nodes: &[Node]) -> Result<Option<Ident>, String> { |
| 448 | + let mut named = None; |
| 449 | + let mut consume_named = false; |
| 450 | + |
| 451 | + for node in nodes { |
| 452 | + match node { |
| 453 | + Node::Atom(s) if s.to_string() == ":named" => { |
| 454 | + consume_named = true; |
| 455 | + } |
| 456 | + Node::Atom(s) if consume_named && named.is_none() => { |
| 457 | + named = Some(Arc::new(s.clone())); |
| 458 | + consume_named = false; |
| 459 | + } |
| 460 | + _ => { |
| 461 | + return Err(format!("expected :named; found {}", node_to_string(node))); |
| 462 | + } |
| 463 | + } |
| 464 | + } |
| 465 | + |
| 466 | + Ok(named) |
| 467 | + } |
| 468 | + |
447 | 469 | fn node_to_quant_or_lambda_expr( |
448 | 470 | &self, |
449 | 471 | quantchooselambda: QuantOrChooseOrLambda, |
@@ -621,9 +643,19 @@ impl Parser { |
621 | 643 | let typ = self.node_to_typ(t)?; |
622 | 644 | Ok(Arc::new(DeclX::Var(Arc::new(x.clone()), typ))) |
623 | 645 | } |
624 | | - [Node::Atom(s), e] if s.to_string() == "axiom" => { |
| 646 | + [Node::Atom(s), axiom_node] if s.to_string() == "axiom" => { |
| 647 | + let (e, named) = match &axiom_node { |
| 648 | + Node::List(nodes) if nodes.len() >= 2 => match &nodes[0] { |
| 649 | + Node::Atom(s) if s.to_string() == "!" => { |
| 650 | + let named = self.nodes_to_named(&nodes[2..])?; |
| 651 | + (&nodes[1], named) |
| 652 | + } |
| 653 | + _ => (axiom_node, None), |
| 654 | + }, |
| 655 | + _ => (axiom_node, None), |
| 656 | + }; |
625 | 657 | let expr = self.node_to_expr(e)?; |
626 | | - Ok(Arc::new(DeclX::Axiom(expr))) |
| 658 | + Ok(Arc::new(DeclX::Axiom(Axiom { named, expr }))) |
627 | 659 | } |
628 | 660 | _ => Err(format!("expected declaration, found: {}", node_to_string(node))), |
629 | 661 | }, |
|
0 commit comments