Skip to content

Commit

Permalink
Add warning for empty rule
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2a-42 committed Dec 31, 2024
1 parent fded3d8 commit 4e488d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/frontend/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub const UNUSED_RULE: &str = "W001";
pub const UNUSED_TOKEN: &str = "W002";
pub const UNUSED_OPEN_NODE: &str = "W003";
pub const REDUNDANT_ELISION: &str = "W004";
pub const EMPTY_RULE: &str = "W005";

pub trait LanguageErrors {
fn invalid_binding_pos(span: &Span) -> Self;
Expand Down Expand Up @@ -67,6 +68,7 @@ pub trait LanguageErrors {
fn redundant_elision(span: &Span) -> Self;
fn expected_rule(span: &Span) -> Self;
fn missing_node_name(span: &Span) -> Self;
fn empty_rule(span: &Span) -> Self;
}

impl LanguageErrors for Diagnostic {
Expand Down Expand Up @@ -359,4 +361,11 @@ impl LanguageErrors for Diagnostic {
.with_message("missing node name")
.with_labels(vec![Label::primary((), span.clone())])
}

fn empty_rule(span: &Span) -> Self {
Diagnostic::warning()
.with_code(EMPTY_RULE)
.with_message("empty rule")
.with_labels(vec![Label::primary((), span.clone())])
}
}
7 changes: 5 additions & 2 deletions src/frontend/sema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ impl<'a> GeneralCheck<'a> {
diags: &mut Vec<Diagnostic>,
sema: &mut SemanticData<'a>,
) {
rule.regex(cst)
.map(|regex| self.check_regex(cst, rule, regex, diags, sema, false, false));
if let Some(regex) = rule.regex(cst) {
self.check_regex(cst, rule, regex, diags, sema, false, false);
} else {
diags.push(Diagnostic::empty_rule(&rule.span(cst)));
}
self.check_recursive(cst, sema, rule, diags);
if let Some(regex) = rule.regex(cst) {
let mut open = HashSet::new();
Expand Down

0 comments on commit 4e488d2

Please sign in to comment.