Flesh out grammar for parsing labels

This commit is contained in:
2025-05-09 21:40:45 -07:00
parent 5d59f5b31f
commit b52da476f0
+16 -3
View File
@@ -1,12 +1,25 @@
use crate::{
preprocess::peg::{EOF, Rule, Star},
preprocess::peg::{Alt, And, Dot, EOF, Not, Opt, Rule, Star},
star,
};
fn parse_program() -> impl Rule {
(star!(parse_line), EOF)
(Opt((parse_line, star!(("\n", parse_line)))), EOF)
}
fn parse_line() -> impl Rule {
(star!("foo"), "\n")
Alt((parse_label_line, parse_any_line))
}
fn parse_any_line() -> impl Rule {
(star!(Not("\n"), Dot), eol)
}
fn parse_label_line() -> impl Rule {
let allowed = Alt(('A'..='Z', 'a'..='z', '0'..='9', "_", "@", "~"));
(":", star!(allowed), eol)
}
fn eol() -> impl Rule {
Alt((And("\n"), EOF))
}