From b52da476f0f4b9874f16c36d7f9fff797704396f Mon Sep 17 00:00:00 2001 From: Chris Mounce Date: Fri, 9 May 2025 21:40:45 -0700 Subject: [PATCH] Flesh out grammar for parsing labels --- src/labels/labels.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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)) }