pub struct Parser { /* private fields */ }Implementations§
Source§impl Parser
impl Parser
pub fn new(src: String) -> Self
Sourcepub fn wrap_parens_safely(src: String) -> String
pub fn wrap_parens_safely(src: String) -> String
This is used when a lisp expression is within a fmt or eval call. We need to wrap it in parentheses to ensure it’s treated as a single expression. Else will simply get back the first token or equivalent. Caller’s responsibility to ensure the string is a valid Caller must call wrap_parens before the .parse() method. This also prevents imho the rather ugly redundant and repeated parens like so: fmt((expr)) when you can simply write fmt(expr) NOTE: does not check for balances parenthesis
pub fn append_tokens(&mut self, src: String)
Sourcepub fn tokenize(src: &str) -> Vec<String>
pub fn tokenize(src: &str) -> Vec<String>
This regular expression is used for tokenizing a Lisp-like language.
It matches and captures different types of tokens, including:
-
Whitespace and commas (
[\s,]*)- These are ignored as separators.
-
Special symbols (
~@|[\[\]{}()'~^@]`)- Matches Lisp syntax elements like
(,),[,],{,},',`,~,@,^, and~@.
- Matches Lisp syntax elements like
-
String literals (
"(?:\\.|[^\\"])*"?)- Matches double-quoted strings, allowing for escaped characters (e.g.,
"hello","escaped \" quote"). - The trailing
"?allows capturing an incomplete string (e.g.,"unterminated).
- Matches double-quoted strings, allowing for escaped characters (e.g.,
-
Comments (
;.*)- Matches Lisp-style comments starting with
;and continuing to the end of the line.
- Matches Lisp-style comments starting with
-
Identifiers and other tokens (
[^\s\[\]{}('",;)]*`)- Matches symbols, numbers, and variable names, ensuring they don’t include special characters.
pub fn parse(&mut self) -> LispExpr
pub fn ast(&self) -> Vec<LispExpr>
pub fn source(&self) -> &str
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnsafeUnpin for Parser
impl UnwindSafe for Parser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more