From 67148a4aa41e9a8fdb6f49c65321af3e566aa321 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 18 Jan 2025 23:03:30 +0100 Subject: [PATCH] try to fix top level expr parsing by trimming the opening bracket --- edn/src/lib.rs | 2 +- edn/src/token.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/edn/src/lib.rs b/edn/src/lib.rs index 67ce1041..0e6880cd 100644 --- a/edn/src/lib.rs +++ b/edn/src/lib.rs @@ -91,7 +91,7 @@ pub(crate) use std::fmt::{Debug, Display, Formatter, Result as FormatResult, Err source: src, start: 0, length: src.len(), - value: Exp(0, TokenIter(src)) + value: Exp(0, TokenIter(&src[1..])) })); //panic!("{view:?}"); //panic!("{:#?}", expr); diff --git a/edn/src/token.rs b/edn/src/token.rs index 44f14f62..ee11928a 100644 --- a/edn/src/token.rs +++ b/edn/src/token.rs @@ -28,6 +28,9 @@ impl<'a> Token<'a> { pub const fn slice_source <'b> (&'a self, source: &'b str) -> &'b str { str_range(source, self.start, self.end()) } + pub const fn slice_source_exp <'b> (&'a self, source: &'b str) -> &'b str { + str_range(source, self.start + 1, self.end()) + } pub const fn value (&self) -> Value { self.value } @@ -56,7 +59,7 @@ impl<'a> Token<'a> { pub const fn grow_exp (self) -> Self { let mut token = self.grow(); if let Exp(depth, _) = token.value { - token.value = Exp(depth, TokenIter(token.slice_source(self.source))); + token.value = Exp(depth, TokenIter(token.slice_source_exp(self.source))); } else { unreachable!() }