aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-07 09:14:28 +0100
committerJonas Maier <>2026-03-07 09:14:28 +0100
commit79c4e340d6c0a598f5d9cd0115a7e5ac0304d459 (patch)
treec05dd743a34e4b8f59bec7dbd5dfcb5ca7b04bc4
parentbc7f1d9875d62412ad70280bd74636c6ca39f3cc (diff)
downloadpish-79c4e340d6c0a598f5d9cd0115a7e5ac0304d459.tar.gz
variable assignments
-rw-r--r--src/parse.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/parse.rs b/src/parse.rs
index 2902633..cbc37bf 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -27,14 +27,14 @@ pub trait Expander {
#[derive(Debug, Clone)]
pub enum Ast<T: Stage> {
- AssignVar(AssignVar),
+ VarAssign(VarAssign),
Pipes(Pipes<T>),
}
impl Ast<PreExpansion> {
pub fn expand<E: Expander>(self, e: &mut E) -> Res<Ast<PostExpansion>, E::Error> {
match self {
- Ast::AssignVar(_) => todo!(),
+ Ast::VarAssign(_) => todo!(),
Ast::Pipes(pipes) => Ok(Ast::Pipes(pipes.expand(e)?)),
}
}
@@ -100,9 +100,32 @@ pub struct VarDecl<S: Stage> {
}
#[derive(Debug, Clone)]
-pub struct AssignVar {
- pub to: String,
- // TODO: body
+pub struct VarAssign<S: Stage> {
+ pub var: S::Str,
+ pub val: S::Str,
+}
+
+impl Parse for VarAssign<PreExpansion> {
+ fn parse(b: &mut Cursor<'_>) -> Result<Self> {
+ if !b.buf.starts_with(b"set ") && !b.buf.starts_with(b"set\t") {
+ return Err(ParseError::NotAVarAssign);
+ }
+ b.advance(4);
+ b.spaces();
+ let var = ExpString::parse(b)?;
+ b.spaces();
+
+ if b.is_empty() {
+ return Err(ParseError::Eof);
+ }
+ let eq = b.adv();
+ if eq != b'=' {
+ return Err(ParseError::Expected('='));
+ }
+ let val = ExpString::parse(b)?;
+
+ Ok(Self { var, val })
+ }
}
#[derive(Debug, Clone)]
@@ -364,6 +387,8 @@ pub enum ParseError {
NotAString,
NotAFunDecl,
+
+ NotAVarAssign,
}
type Result<T> = std::result::Result<T, ParseError>;