devalang_core/core/parser/handler/identifier/
spawn.rs1use crate::core::{
2 lexer::token::{ Token, TokenKind },
3 parser::{ statement::{ Statement, StatementKind }, driver::Parser },
4 shared::value::Value,
5 store::global::GlobalStore,
6};
7
8pub fn parse_spawn_token(
9 parser: &mut Parser,
10 current_token: Token,
11 _global_store: &mut GlobalStore
12) -> Statement {
13 parser.advance(); let name_token = match parser.peek_clone() {
17 Some(t) => t,
18 None => {
19 return Statement::error(
20 current_token,
21 "Expected function name after 'spawn'".to_string()
22 );
23 }
24 };
25
26 if name_token.kind != TokenKind::Identifier {
27 return Statement::error(
28 name_token,
29 "Expected function name to be an identifier".to_string()
30 );
31 }
32
33 let func_name = name_token.lexeme.clone();
34 parser.advance(); let mut args: Vec<Value> = Vec::new();
38 if let Some(open_paren) = parser.peek_clone() {
39 if open_paren.kind == TokenKind::LParen {
40 parser.advance(); while let Some(token) = parser.peek_clone() {
44 if token.kind == TokenKind::RParen {
45 parser.advance(); break;
47 }
48
49 match token.kind {
50 TokenKind::Number => {
51 if let Ok(num) = token.lexeme.parse::<f32>() {
52 args.push(Value::Number(num));
53 }
54 parser.advance();
55 }
56 TokenKind::String => {
57 args.push(Value::String(token.lexeme.clone()));
58 parser.advance();
59 }
60 TokenKind::Identifier => {
61 args.push(Value::Identifier(token.lexeme.clone()));
62 parser.advance();
63 }
64 TokenKind::Comma => {
65 parser.advance(); }
67 _ => {
68 return Statement::error(
69 token,
70 "Unexpected token in spawn arguments".to_string()
71 );
72 }
73 }
74 }
75 }
76 }
77
78 Statement {
79 kind: StatementKind::Spawn {
80 name: func_name,
81 args,
82 },
83 value: Value::Null,
84 indent: current_token.indent,
85 line: current_token.line,
86 column: current_token.column,
87 }
88}