Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell the user what rule is missing action code. #456

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lrpar/src/lib/ctbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ where
if let Some(YaccKind::Original(YaccOriginalActionKind::UserAction) | YaccKind::Grmtools) =
self.yacckind
{
outs.push_str(&self.gen_user_actions(grm));
outs.push_str(&self.gen_user_actions(grm)?);
}
outs.push_str(" mod _parser_ {\n");
outs.push_str(
Expand Down Expand Up @@ -1107,7 +1107,7 @@ where
}

/// Generate the user action functions (if any).
fn gen_user_actions(&self, grm: &YaccGrammar<StorageT>) -> String {
fn gen_user_actions(&self, grm: &YaccGrammar<StorageT>) -> Result<String, Box<dyn Error>> {
let mut outs = String::new();

if let Some(s) = grm.programs() {
Expand Down Expand Up @@ -1179,7 +1179,12 @@ where

// Iterate over all $-arguments and replace them with their respective
// element from the argument vector (e.g. $1 is replaced by args[0]).
let pre_action = grm.action(pidx).as_ref().unwrap();
let pre_action = grm.action(pidx).as_ref().ok_or_else(|| {
format!(
"Rule {} has a production which is missing action code",
grm.rule_name_str(grm.prod_to_rule(pidx))
)
})?;
let mut last = 0;
loop {
match pre_action[last..].find('$') {
Expand Down Expand Up @@ -1217,7 +1222,7 @@ where

outs.push_str("\n }\n\n");
}
outs
Ok(outs)
}

/// Return the `RIdx` of the %start rule in the grammar (which will not be the same as
Expand Down