From 12d3250bc4a95f790510932906650486eaf3ec86 Mon Sep 17 00:00:00 2001 From: afonya2 <adamhir@freemail.hu> Date: Wed, 11 Jun 2025 17:00:22 +0200 Subject: [PATCH] added multiline tables --- src/compiler.rs | 1 - src/parser.rs | 15 +++++++++++++-- test.asl | 7 +++++-- test2.asl | 2 -- 4 files changed, 18 insertions(+), 7 deletions(-) delete mode 100644 test2.asl diff --git a/src/compiler.rs b/src/compiler.rs index fbbec53..ec7eb7d 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -641,7 +641,6 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va process::exit(1); } } - }, _ => {} } diff --git a/src/parser.rs b/src/parser.rs index 8bd1103..3a09491 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -369,15 +369,23 @@ fn read_function(input: &Vec<Token>, pos: &mut usize, with_args: bool, ctx: &Con fn read_table(input: &Vec<Token>, pos: &mut usize, ctx: &Context) -> ASTPart { let start_pos = input[*pos].pos; let key_ends: Vec<Token> = vec![ - Token { typ: TokenType::SEPARATOR, value: String::from("]"), pos: 0 } + Token { typ: TokenType::SEPARATOR, value: String::from("]"), pos: 0 }, ]; let ends: Vec<Token> = vec![ Token { typ: TokenType::SEPARATOR, value: String::from("}"), pos: 0 }, - Token { typ: TokenType::SEPARATOR, value: String::from(","), pos: 0 } + Token { typ: TokenType::SEPARATOR, value: String::from(","), pos: 0 }, + Token { typ: TokenType::OPEND, value: String::from("\n"), pos: 0 }, ]; let mut tbl: Vec<TableValue> = vec![]; let mut key = 0; while *pos < input.len() { + if input[*pos].typ == TokenType::OPEND && input[*pos].value == "\n" { + *pos += 1; + continue; + } else if input[*pos].typ == TokenType::SEPARATOR && input[*pos].value == "}" { + *pos += 1; + break; + } if input[*pos].typ == TokenType::SEPARATOR && input[*pos].value == "[" { *pos += 1; let keyy = read_exp(pos, input, &key_ends, &key_ends, ctx); @@ -419,6 +427,9 @@ fn read_table(input: &Vec<Token>, pos: &mut usize, ctx: &Context) -> ASTPart { } else if input[*pos].typ == TokenType::SEPARATOR && input[*pos].value == "," { *pos += 1; continue; + } else if input[*pos].typ == TokenType::OPEND && input[*pos].value == "\n" { + *pos += 1; + continue; } else { let err = create_error(&format!("Unexpected end of table"), input[*pos].pos, ErrorType::SyntaxError, ErrorSubType::UnexpectedEnd); print_error(&err, &ctx); diff --git a/test.asl b/test.asl index 23571b9..13e0870 100644 --- a/test.asl +++ b/test.asl @@ -1,2 +1,5 @@ -hámozd test be szaft"test2.asl"szaft -ugass(test) \ No newline at end of file +gethelj a = { + [szaft"test"szaft] = szaft"test"szaft, + [szaft"teher"szaft] = szaft"teher"szaft +} +ugass(a) \ No newline at end of file diff --git a/test2.asl b/test2.asl deleted file mode 100644 index 6be1869..0000000 --- a/test2.asl +++ /dev/null @@ -1,2 +0,0 @@ -ugass(szaft"Hell yeah!"szaft) -reti 1 \ No newline at end of file