Compilation errors solved

This commit is contained in:
2025-11-30 16:11:54 -07:00
parent 15603f8bbe
commit c5c4cfdc64
5 changed files with 150 additions and 93 deletions

View File

@@ -934,7 +934,7 @@ impl<'a> Parser<'a> {
));
}
let mut arguments = Vec::<Expression>::new();
let mut arguments = Vec::<Spanned<Expression>>::new();
while !token_matches!(
self.get_next()?.ok_or(Error::UnexpectedEOF)?,
@@ -949,7 +949,7 @@ impl<'a> Parser<'a> {
));
}
arguments.push(expression.node);
arguments.push(expression);
if !self_matches_peek!(self, TokenType::Symbol(Symbol::Comma))
&& !self_matches_peek!(self, TokenType::Symbol(Symbol::RParen))
@@ -1308,7 +1308,7 @@ impl<'a> Parser<'a> {
fn syscall(&mut self) -> Result<SysCall, Error> {
fn check_length(
parser: &Parser,
arguments: &[Expression],
arguments: &[Spanned<Expression>],
length: usize,
) -> Result<(), Error> {
if arguments.len() != length {
@@ -1323,10 +1323,18 @@ impl<'a> Parser<'a> {
macro_rules! literal_or_variable {
($iter:expr) => {
match $iter {
Some(Expression::Literal(literal)) => {
LiteralOrVariable::Literal(literal.node.clone())
}
Some(Expression::Variable(ident)) => LiteralOrVariable::Variable(ident),
Some(expr) => match &expr.node {
Expression::Literal(literal) => {
LiteralOrVariable::Literal(literal.node.clone())
}
Expression::Variable(ident) => LiteralOrVariable::Variable(ident.clone()),
_ => {
return Err(Error::UnexpectedToken(
self.current_span(),
self.current_token.clone().unwrap(),
))
}
},
_ => {
return Err(Error::UnexpectedToken(
self.current_span(),
@@ -1360,18 +1368,8 @@ impl<'a> Parser<'a> {
}
"sleep" => {
check_length(self, &invocation.arguments, 1)?;
// arguments is Vec<Expression>.
let mut arg = invocation.arguments.into_iter();
let expr = arg.next().unwrap();
// We need to wrap `expr` into a `Box<Spanned<Expression>>`?
// Wait, System::Sleep takes Box<Expression>.
// Expression variants are Spanned.
// But Expression IS NOT Spanned<Expression>.
// Expression enum contains Spanned<BinaryExpression>, etc.
// But `Expression` itself is the node.
// The issue: `expr` is `Expression` (which is Spanned internally).
// `System::Sleep(Box<Expression>)`.
Ok(SysCall::System(System::Sleep(boxed!(expr))))
}
"hash" => {
@@ -1396,8 +1394,16 @@ impl<'a> Parser<'a> {
let next_arg = args.next();
let variable = match next_arg {
Some(Expression::Literal(spanned_lit)) => match spanned_lit.node {
Literal::String(s) => s,
Some(expr) => match expr.node {
Expression::Literal(spanned_lit) => match spanned_lit.node {
Literal::String(s) => s,
_ => {
return Err(Error::UnexpectedToken(
self.current_span(),
self.current_token.clone().unwrap(),
));
}
},
_ => {
return Err(Error::UnexpectedToken(
self.current_span(),
@@ -1431,11 +1437,35 @@ impl<'a> Parser<'a> {
boxed!(variable),
)))
}
// Fallback for brevity in this response
_ => Err(Error::UnsupportedKeyword(
self.current_span(),
self.current_token.clone().unwrap(),
)),
"setOnDeviceBatched" => {
check_length(self, &invocation.arguments, 3)?;
let mut args = invocation.arguments.into_iter();
let device_hash = literal_or_variable!(args.next());
let logic_type = get_arg!(Literal, literal_or_variable!(args.next()));
let variable = args.next().unwrap();
Ok(SysCall::System(sys_call::System::SetOnDeviceBatched(
device_hash,
Literal::String(logic_type.to_string().replace("\"", "")),
boxed!(variable),
)))
}
_ => {
// For Math functions or unknown functions
if SysCall::is_syscall(&invocation.name.node) {
// Attempt to parse as math if applicable, or error if strict
// Here we are falling back to simple handling or error.
// Since Math isn't fully expanded in this snippet, we return Unsupported.
Err(Error::UnsupportedKeyword(
self.current_span(),
self.current_token.clone().unwrap(),
))
} else {
Err(Error::UnsupportedKeyword(
self.current_span(),
self.current_token.clone().unwrap(),
))
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
use crate::tree_node::{Expression, Literal};
use crate::tree_node::{Expression, Literal, Spanned};
use super::LiteralOrVariable;
@@ -102,7 +102,7 @@ pub enum System {
/// Represents a function that can be called to sleep for a certain amount of time.
/// ## In Game
/// `sleep a(r?|num)`
Sleep(Box<Expression>),
Sleep(Box<Spanned<Expression>>),
/// Gets the in-game hash for a specific prefab name.
/// ## In Game
/// `HASH("prefabName")`
@@ -120,7 +120,12 @@ pub enum System {
/// lbn r? deviceHash nameHash logicType batchMode
/// ## Examples
/// lbn r0 HASH("StructureWallLight") HASH("wallLight") On Minimum
LoadBatchNamed(LiteralOrVariable, Box<Expression>, Literal, Literal),
LoadBatchNamed(
LiteralOrVariable,
Box<Spanned<Expression>>,
Literal,
Literal,
),
/// Loads a LogicType from all connected network devices, aggregating them via a
/// batchMode
/// ## In Game
@@ -133,14 +138,14 @@ pub enum System {
/// `s d? logicType r?`
/// ## Example
/// `s d0 Setting r0`
SetOnDevice(LiteralOrVariable, Literal, Box<Expression>),
SetOnDevice(LiteralOrVariable, Literal, Box<Spanned<Expression>>),
/// Represents a function which stores a setting to all devices that match
/// the given deviceHash
/// ## In Game
/// `sb deviceHash logicType r?`
/// ## Example
/// `sb HASH("Doors") Lock 1`
SetOnDeviceBatched(LiteralOrVariable, Literal, Box<Expression>),
SetOnDeviceBatched(LiteralOrVariable, Literal, Box<Spanned<Expression>>),
/// Represents a function which stores a setting to all devices that match
/// both the given deviceHash AND the given nameHash
/// ## In Game
@@ -151,7 +156,7 @@ pub enum System {
LiteralOrVariable,
LiteralOrVariable,
Literal,
Box<Expression>,
Box<Spanned<Expression>>,
),
}
@@ -224,3 +229,4 @@ impl SysCall {
)
}
}

View File

@@ -127,7 +127,7 @@ impl std::fmt::Display for BlockExpression {
#[derive(Debug, PartialEq, Eq)]
pub struct InvocationExpression {
pub name: Spanned<String>,
pub arguments: Vec<Expression>,
pub arguments: Vec<Spanned<Expression>>,
}
impl std::fmt::Display for InvocationExpression {