devalang_core/core/parser/handler/identifier/
synth.rs1use std::collections::HashMap;
2
3use crate::core::{
4 lexer::token::Token,
5 parser::{
6 driver::Parser,
7 statement::{Statement, StatementKind},
8 },
9 shared::value::Value,
10 store::global::GlobalStore,
11};
12
13pub fn parse_synth_token(
14 parser: &mut Parser,
15 _current_token: Token,
16 _global_store: &mut GlobalStore,
17) -> Statement {
18 parser.advance(); let Some(synth_token) = parser.previous_clone() else {
21 return Statement::unknown();
22 };
23
24 let Some(identifier_token) = parser.peek_clone() else {
26 return Statement::error(synth_token, "Expected identifier after 'synth'".to_string());
27 };
28
29 let synth_waveform = identifier_token.lexeme.clone();
30
31 parser.advance(); let parameters = if let Some(params) = parser.parse_map_value() {
35 if let Value::Map(map) = params {
37 map
38 } else {
39 return Statement::error(
40 synth_token,
41 "Expected a map for synth parameters".to_string(),
42 );
43 }
44 } else {
45 HashMap::new()
47 };
48
49 Statement {
50 kind: StatementKind::Synth,
51 value: Value::Map(HashMap::from([
52 ("entity".to_string(), Value::String("synth".to_string())),
53 (
54 "value".to_string(),
55 Value::Map(HashMap::from([
56 ("waveform".to_string(), Value::String(synth_waveform)),
57 ("parameters".to_string(), Value::Map(parameters)),
58 ])),
59 ),
60 ])),
61 indent: synth_token.indent,
62 line: synth_token.line,
63 column: synth_token.column,
64 }
65}