Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanBrouwer committed Nov 5, 2023
1 parent d14d20b commit 25b7191
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion prism-compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {

let input = include_str!("../resources/program.pr");
let expr: Result<_, _> = run_parser_rule(&grammar, "block", input, |r| {
Expr::from_action_result(&r, input)
Expr::from_action_result(r, input)
});
let expr = match expr {
Ok(o) => o,
Expand Down
6 changes: 5 additions & 1 deletion prism-parser/src/core/adaptive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ pub struct RuleState<'b, 'grm> {
pub arg_names: &'b Vec<&'grm str>,
}

pub enum UpdateError {
ToposortCycle,
}

impl<'b, 'grm> RuleState<'b, 'grm> {
pub fn new_empty(name: &'grm str, arg_names: &'b Vec<&'grm str>) -> Self {
Self {
Expand All @@ -122,7 +126,7 @@ impl<'b, 'grm> RuleState<'b, 'grm> {
&mut self,
r: &'b Rule<'grm, RuleAction<'b, 'grm>>,
ctx: &Arc<HashMap<&'grm str, RuleId>>,
) -> Result<(), ()> {
) -> Result<(), UpdateError> {
self.order.update(r);

let order: HashMap<&'grm str, usize> = self
Expand Down
5 changes: 3 additions & 2 deletions prism-parser/src/core/toposet.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::core::adaptive::UpdateError;
use crate::grammar::Rule;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet, VecDeque};
Expand Down Expand Up @@ -46,7 +47,7 @@ impl<'grm> TopoSet<'grm> {
}
}

pub fn toposort(&self) -> Result<Vec<&'grm str>, ()> {
pub fn toposort(&self) -> Result<Vec<&'grm str>, UpdateError> {
let mut result = Vec::new();
let mut counts: HashMap<&'grm str, usize> = HashMap::new();

Expand Down Expand Up @@ -79,7 +80,7 @@ impl<'grm> TopoSet<'grm> {
if counts.is_empty() {
Ok(result)
} else {
Err(())
Err(UpdateError::ToposortCycle)
}
}
}
4 changes: 2 additions & 2 deletions prism-parser/src/grammar/from_action_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ fn parse_rule_expr<'b, 'grm, A>(
})
}

pub(crate) fn parse_identifier<'b, 'grm>(
r: &ActionResult<'b, 'grm>,
pub(crate) fn parse_identifier<'grm>(
r: &ActionResult<'_, 'grm>,
src: &'grm str,
) -> Option<&'grm str> {
match r {
Expand Down
2 changes: 1 addition & 1 deletion prism-parser/src/rule_action/from_action_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn parse_rule_action<'b, 'grm>(
parse_identifier(&b[0], src)?,
result_match! {
match &b[1].as_ref() => Construct(_, "List", subs),
create subs.iter().map(|sub| parse_rule_action(sub, src).map(|v| v)).collect::<Option<Vec<_>>>()?
create subs.iter().map(|sub| parse_rule_action(sub, src)).collect::<Option<Vec<_>>>()?
}?,
),
Construct(_, "InputLiteral", b) => RuleAction::InputLiteral(parse_string(&b[0], src)?),
Expand Down

0 comments on commit 25b7191

Please sign in to comment.