diff --git a/src/labels/labels.rs b/src/labels/labels.rs index 6a5412a..d3b9538 100644 --- a/src/labels/labels.rs +++ b/src/labels/labels.rs @@ -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)) }