parser: use LocatingSlice<&str> instead of &str#560
parser: use LocatingSlice<&str> instead of &str#560GuillaumeGomez merged 4 commits intoaskama-rs:masterfrom
LocatingSlice<&str> instead of &str#560Conversation
This will enable better span getting in subsequent PRs.
| let three_chars = take(3usize).verify_map(|head: &str| { | ||
| if let Ok(head) = head.as_bytes().try_into() | ||
| && THREE_CHARS.contains(head) | ||
| { | ||
| Some(()) | ||
| } else { | ||
| None | ||
| } | ||
| }); | ||
| let two_chars = take(2usize).verify_map(|head: &str| { | ||
| if let Ok(head) = head.as_bytes().try_into() | ||
| && TWO_CHARS.contains(head) | ||
| { | ||
| Some(()) | ||
| } else { | ||
| None | ||
| } | ||
| }); | ||
| let one_char = any.verify_map(|head: char| { | ||
| if let Ok(head) = head.try_into() | ||
| && ONE_CHAR.contains(&head) | ||
| { | ||
| Some(()) | ||
| } else { | ||
| None | ||
| } | ||
| }); | ||
|
|
||
| // need to check long to short | ||
| *i = if let Some((head, tail)) = i.split_at_checked(3) | ||
| && let Ok(head) = head.as_bytes().try_into() | ||
| && THREE_CHARS.contains(head) | ||
| { | ||
| tail | ||
| } else if let Some((head, tail)) = i.split_at_checked(2) | ||
| && let Ok(head) = head.as_bytes().try_into() | ||
| && TWO_CHARS.contains(&head) | ||
| { | ||
| tail | ||
| } else if let Some((head, tail)) = i.split_at_checked(1) | ||
| && let [head] = head.as_bytes() | ||
| && ONE_CHAR.contains(head) | ||
| { | ||
| tail | ||
| } else { | ||
| return fail(i); | ||
| }; | ||
| Ok(()) |
There was a problem hiding this comment.
This function had to be replaced for the most part. It's logic is still the same.
|
|
||
| type HashSet<T> = std::collections::hash_set::HashSet<T, FxBuildHasher>; | ||
|
|
||
| #[cfg(not(windows))] |
There was a problem hiding this comment.
Only the Path formatting tests are platform specific.
| i: &mut InputStream<'a>, | ||
| s: &State<'_, '_>, | ||
| ) -> ParseResult<'a, Vec<Box<Self>>> { | ||
| let start = *i; | ||
| let result = match (|i: &mut _| Self::many(i, s)).parse_next(i) { | ||
| Ok(result) => result, | ||
| Err(err) => { | ||
| if let ErrMode::Backtrack(err) | ErrMode::Cut(err) = &err | ||
| && err.message.is_none() | ||
| { | ||
| *i = start; | ||
| if let Some(mut span) = err.span.as_suffix_of(i) { | ||
| opt(|i: &mut _| unexpected_tag(i, s)).parse_next(&mut span)?; | ||
| } | ||
| } | ||
| return Err(err); | ||
| } | ||
| }; |
There was a problem hiding this comment.
I moved the logic of this part into its own function, because cut_node works the same. No need to have the same code twice.
| | ^^^^^^^^ | ||
|
|
||
| error: invalid character | ||
| error: cannot have multiple characters in a character literal, use `"..."` to write a string |
There was a problem hiding this comment.
I think this could help users that come from Jinja. Being pythonic, strings can be written with '...'.
|
With this PR, we can use For every derived @GuillaumeGomez, do you want to implement these subsequent PRs to make the underlining work? The feature could even allow debug stepping through a template file! |
|
Thanks a lot for this huge improvement!
I can if you don't have time for it, but seems like you already started quite strongly on it. 😆 |
|
Will keep working on it. :) |
|
Gonna work on other stuff then. 😉 Can't wait to see what next step will be! |
This will enable better span getting in subsequent PRs.