Skip to content

Commit ae844d1

Browse files
committed
Add option to parse arguments to hole rule
This reverts the default behaviour that was changed in 16adacd. Now, the flag `--parse-hole-args` can be used to get the new behaviour.
1 parent fdd8ac7 commit ae844d1

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

carcara/src/elaborator/hole.rs

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ fn parse_and_check_solver_proof(
149149
expand_lets: true,
150150
allow_int_real_subtyping: true,
151151
strict: false,
152+
parse_hole_args: false,
152153
};
153154

154155
let (problem, proof) = parser::parse_instance_with_pool(problem, proof, config, pool)?;

carcara/src/elaborator/lia_generic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ fn parse_and_check_solver_proof(
136136
expand_lets: true,
137137
allow_int_real_subtyping: true,
138138
strict: false,
139+
parse_hole_args: false,
139140
};
140141
let (problem, proof) = parser::parse_instance_with_pool(problem, proof, config, pool)?;
141142

carcara/src/parser/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub struct Config {
4545
/// - Unary `and`, `or` and `xor` terms are not allowed
4646
/// - Anchor arguments using the old syntax (i.e., `(:= <symbol> <term>)`) are not allowed
4747
pub strict: bool,
48+
49+
/// If `true`, the parser will parse arguments to the `hole` rule, expecting them to be valid
50+
/// terms.
51+
pub parse_hole_args: bool,
4852
}
4953

5054
impl Config {
@@ -910,7 +914,16 @@ impl<'a, R: BufRead> Parser<'a, R> {
910914
let args = if self.current_token == Token::Keyword("args".into()) {
911915
self.next_token()?;
912916
self.expect_token(Token::OpenParen)?;
913-
self.parse_sequence(Self::parse_term, true)?
917+
918+
// If the rule is `hole` and `--parse-hole-args` is not enabled, we want to allow any
919+
// invalid arguments, so we read the rest of the `:args` attribute without trying to
920+
// parse anything
921+
if rule == "hole" && !self.config.parse_hole_args {
922+
self.ignore_until_close_parens()?;
923+
Vec::new()
924+
} else {
925+
self.parse_sequence(Self::parse_term, true)?
926+
}
914927
} else {
915928
Vec::new()
916929
};

carcara/src/parser/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const TEST_CONFIG: Config = Config {
1313
expand_lets: false,
1414
allow_int_real_subtyping: false,
1515
strict: false,
16+
parse_hole_args: false,
1617
};
1718

1819
pub fn parse_terms<const N: usize>(

cli/src/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ struct ParsingOptions {
129129
/// When this flag is enabled: unary `and`, `or` and `xor` terms are not allowed;
130130
#[clap(short, long = "strict-parsing")]
131131
strict: bool,
132+
133+
/// If `true`, Carcara will parse arguments to the `hole` rule, expecting them to be valid
134+
/// terms. In the future, this will be the default behaviour.
135+
#[clap(long)]
136+
parse_hole_args: bool,
132137
}
133138

134139
impl From<ParsingOptions> for parser::Config {
@@ -138,6 +143,7 @@ impl From<ParsingOptions> for parser::Config {
138143
expand_lets: val.expand_let_bindings,
139144
allow_int_real_subtyping: val.allow_int_real_subtyping,
140145
strict: val.strict,
146+
parse_hole_args: val.parse_hole_args,
141147
}
142148
}
143149
}

0 commit comments

Comments
 (0)