Fixed bug where negative consts were not valid slang, revised build script to build the workshop folder to the release folder.

This commit is contained in:
2025-12-06 19:56:05 -07:00
parent d6548502cd
commit 0ea58e4921
7 changed files with 104 additions and 4 deletions

View File

@@ -1349,11 +1349,24 @@ impl<'a> Parser<'a> {
}
fn literal(&mut self) -> Result<Literal, Error> {
let current_token = self.current_token.as_ref().ok_or(Error::UnexpectedEOF)?;
let current_token = self.current_token.clone().ok_or(Error::UnexpectedEOF)?;
let literal = match current_token.token_type {
TokenType::Number(num) => Literal::Number(num),
TokenType::String(ref string) => Literal::String(string.clone()),
TokenType::Boolean(boolean) => Literal::Boolean(boolean),
TokenType::Symbol(Symbol::Minus) => match self.get_next()? {
Some(Token {
token_type: TokenType::Number(num),
..
}) => Literal::Number(-*num),
Some(wrong_token) => {
return Err(Error::UnexpectedToken(
Self::token_to_span(wrong_token),
wrong_token.clone(),
));
}
None => return Err(Error::UnexpectedEOF),
},
_ => {
return Err(Error::UnexpectedToken(
self.current_span(),

View File

@@ -151,3 +151,12 @@ fn test_const_hash_expression() -> Result<()> {
assert_eq!("(const i = hash(\"item\"))", expr.to_string());
Ok(())
}
#[test]
fn test_negative_literal_const() -> Result<()> {
let expr = parser!(r#"const i = -123"#).parse()?.unwrap();
assert_eq!("(const i = -123)", expr.to_string());
Ok(())
}