Flesh out grammar for parsing labels
This commit is contained in:
+16
-3
@@ -1,12 +1,25 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
preprocess::peg::{EOF, Rule, Star},
|
preprocess::peg::{Alt, And, Dot, EOF, Not, Opt, Rule, Star},
|
||||||
star,
|
star,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn parse_program() -> impl Rule {
|
fn parse_program() -> impl Rule {
|
||||||
(star!(parse_line), EOF)
|
(Opt((parse_line, star!(("\n", parse_line)))), EOF)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_line() -> impl Rule {
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user