From 333fd74db169b81b3aa0f5c2e278feec545b8259 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Thu, 3 Apr 2025 19:19:17 +0200 Subject: [PATCH] parse indexes --- src/parser.rs | 44 +++++++++++++++++++++++++++++++++----------- test/parsetest.rush | 4 +++- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index d3f1273..a1fc725 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,4 +1,4 @@ -use chumsky::{error::{EmptyErr, Rich, Simple}, prelude::{any, choice, end, just, none_of, one_of, recursive}, text, IterParser, Parser}; +use chumsky::{error::{EmptyErr, Rich, Simple}, prelude::{any, choice, end, just, none_of, one_of, recursive, Recursive}, text, IterParser, Parser}; #[derive(Debug, Clone)] @@ -171,6 +171,37 @@ pub fn parse<'a>() -> impl Parser<'a, &'a str, Vec, chumsky::extra::D string.map(Primitive::String), )); + let group = expr.clone() + .delimited_by(just('('), just(')')) + .map(|v| Value::Group(v)); + + let value = choice(( + group, + primitive.clone().map(Value::Primitive), + // index.map(|i| Value::Primitive(Primitive::Index(i))), + )); + + let index = value.clone() + .foldl( + value + .clone() + .padded_by(text::inline_whitespace()) + .delimited_by(just('['), just(']')) + .repeated(), + |value, index| Value::Primitive(Primitive::Index(Index { + value: Box::new(value.clone()), + index: Box::new(index) + }))); + + let value = choice(( + index, + value, + )); + // let value = recursive(|newvalue: Recursive>| { + + // value + // }); + let bindable = primitive.clone().map(Bindable::Primitive); let bindable_group = bindable @@ -179,20 +210,11 @@ pub fn parse<'a>() -> impl Parser<'a, &'a str, Vec, chumsky::extra::D .separated_by(just(",")) .collect() .delimited_by(just('('), just(')')); - - let group = expr.clone() - .delimited_by(just('('), just(')')) - .map(|v| Value::Group(v)); - + let block = expr.clone() .or(empty.to(vec![])) .delimited_by(just('{'), just('}')); - let value = choice(( - group, - primitive.map(Value::Primitive), - )); - let cmdname = value.clone() .and_is(choice(( just("set"), diff --git a/test/parsetest.rush b/test/parsetest.rush index 1aff35c..097238e 100644 --- a/test/parsetest.rush +++ b/test/parsetest.rush @@ -15,4 +15,6 @@ loop {} return 1 break -continue \ No newline at end of file +continue + +return $thing[property] \ No newline at end of file