WIP parsing sends

This commit is contained in:
2025-05-11 18:28:17 -07:00
parent b21fe8b5e3
commit d895bd27ab
+32 -2
View File
@@ -1,6 +1,6 @@
use crate::{ use crate::{
plus, plus,
preprocess::peg::{Alt, And, Dot, EOF, Not, Opt, Parser, Rule, Tag}, preprocess::peg::{Alt, And, Dot, EOF, NoCase, Not, Opt, Parser, Rule, Tag},
star, star,
world::Stat, world::Stat,
}; };
@@ -24,7 +24,11 @@ fn program() -> impl Rule {
} }
fn line() -> impl Rule { fn line() -> impl Rule {
Alt((label_line, any_line)) Alt((send, label_line, any_line))
}
fn send() -> impl Rule {
("#", w, NoCase("send"), ww, Tag("ref", label_name), w, eol)
} }
fn any_line() -> impl Rule { fn any_line() -> impl Rule {
@@ -52,8 +56,18 @@ fn eol() -> impl Rule {
Alt((And("\n"), EOF)) Alt((And("\n"), EOF))
} }
fn w() -> impl Rule {
star!(" ")
}
fn ww() -> impl Rule {
plus!(" ")
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use insta::assert_debug_snapshot;
use crate::preprocess::peg::Ref; use crate::preprocess::peg::Ref;
use super::*; use super::*;
@@ -83,4 +97,20 @@ mod test {
parse_err(&label_name, "foo~bar~baz"); parse_err(&label_name, "foo~bar~baz");
parse_err(&label_name, "~foo"); parse_err(&label_name, "~foo");
} }
#[test]
fn test_references() {
let mut p = Parser::new("#send foo");
assert!(program.parse(&mut p));
let result: Vec<_> = p
.iter()
.filter(|x| x.kind() == "ref")
.map(|x| x.text())
.collect();
assert_debug_snapshot!(result, @r#"
[
"foo",
]
"#);
}
} }