Skip to content

Commit

Permalink
Add option to parse arguments to hole rule
Browse files Browse the repository at this point in the history
This reverts the default behaviour that was changed in
16adacd. Now, the flag
`--parse-hole-args` can be used to get the new behaviour.
  • Loading branch information
bpandreotti committed Oct 18, 2024
1 parent fdd8ac7 commit ae844d1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions carcara/src/elaborator/hole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn parse_and_check_solver_proof(
expand_lets: true,
allow_int_real_subtyping: true,
strict: false,
parse_hole_args: false,
};

let (problem, proof) = parser::parse_instance_with_pool(problem, proof, config, pool)?;
Expand Down
1 change: 1 addition & 0 deletions carcara/src/elaborator/lia_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn parse_and_check_solver_proof(
expand_lets: true,
allow_int_real_subtyping: true,
strict: false,
parse_hole_args: false,
};
let (problem, proof) = parser::parse_instance_with_pool(problem, proof, config, pool)?;

Expand Down
15 changes: 14 additions & 1 deletion carcara/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub struct Config {
/// - Unary `and`, `or` and `xor` terms are not allowed
/// - Anchor arguments using the old syntax (i.e., `(:= <symbol> <term>)`) are not allowed
pub strict: bool,

/// If `true`, the parser will parse arguments to the `hole` rule, expecting them to be valid
/// terms.
pub parse_hole_args: bool,
}

impl Config {
Expand Down Expand Up @@ -910,7 +914,16 @@ impl<'a, R: BufRead> Parser<'a, R> {
let args = if self.current_token == Token::Keyword("args".into()) {
self.next_token()?;
self.expect_token(Token::OpenParen)?;
self.parse_sequence(Self::parse_term, true)?

// If the rule is `hole` and `--parse-hole-args` is not enabled, we want to allow any
// invalid arguments, so we read the rest of the `:args` attribute without trying to
// parse anything
if rule == "hole" && !self.config.parse_hole_args {
self.ignore_until_close_parens()?;
Vec::new()
} else {
self.parse_sequence(Self::parse_term, true)?
}
} else {
Vec::new()
};
Expand Down
1 change: 1 addition & 0 deletions carcara/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TEST_CONFIG: Config = Config {
expand_lets: false,
allow_int_real_subtyping: false,
strict: false,
parse_hole_args: false,
};

pub fn parse_terms<const N: usize>(
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ struct ParsingOptions {
/// When this flag is enabled: unary `and`, `or` and `xor` terms are not allowed;
#[clap(short, long = "strict-parsing")]
strict: bool,

/// If `true`, Carcara will parse arguments to the `hole` rule, expecting them to be valid
/// terms. In the future, this will be the default behaviour.
#[clap(long)]
parse_hole_args: bool,
}

impl From<ParsingOptions> for parser::Config {
Expand All @@ -138,6 +143,7 @@ impl From<ParsingOptions> for parser::Config {
expand_lets: val.expand_let_bindings,
allow_int_real_subtyping: val.allow_int_real_subtyping,
strict: val.strict,
parse_hole_args: val.parse_hole_args,
}
}
}
Expand Down

0 comments on commit ae844d1

Please sign in to comment.