aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/parser.c b/src/parser.c
index 098962a..a6f340f 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -26,7 +26,7 @@ static int tsl_parser_get_current_function_index(TslParser *self) {
static TslParseResult tsl_parser_parse_rhs(TslParser *self);
static TslParseResult tsl_parser_parse_expressions(TslParser *self, TslToken end_token);
-static int tsl_parser_init(TslParser *self, const char *code, size_t code_size) {
+static int tsl_parser_init(TslParser *self, char *code, size_t code_size) {
TslBytecode bytecode_writer;
int result1 = 1;
int result2 = 1;
@@ -216,7 +216,6 @@ static TslParseResult tsl_parser_parse_func_call(TslParser *self, int *num_args)
}
}
-/* TODO: Do not allow empty command */
/* TODO: Allow command inside another command */
/* COMMAND = '(' TSL_COMMAND_TOKEN_ARG* ')' */
static TslParseResult tsl_parser_parse_command(TslParser *self, int *num_args) {
@@ -328,8 +327,12 @@ TslParseResult tsl_parser_parse_rhs(TslParser *self) {
}
case TSL_TOKEN_DOLLAR_SIGN: {
int num_args;
- return tsl_parser_parse_command(self, &num_args) &&
- tsl_bytecode_add_ins1(get_function_bytecode(self), TSL_OPCODE_CALLC, num_args);
+ return_if_error(tsl_parser_parse_command(self, &num_args))
+ if(num_args == 0) {
+ fprintf(stderr, "Error: Command can't be empty\n");
+ return TSL_PARSE_RESULT_ERR;
+ }
+ return tsl_bytecode_add_ins1(get_function_bytecode(self), TSL_OPCODE_CALLC, num_args);
}
default:
fprintf(stderr, "Error: Expected variable, number, bool, null, map, list, function or command, got TODO (%d) (line: %d)\n", token, tsl_tokenizer_get_line_by_index(&self->tokenizer, self->tokenizer.prev_code_index));
@@ -365,7 +368,7 @@ TslParseResult tsl_parser_parse_expressions(TslParser *self, TslToken end_token)
return TSL_PARSE_RESULT_OK;
}
-TslParseResult tsl_parse(const char *code, size_t code_size, TslProgram *program_output) {
+TslParseResult tsl_parse(char *code, size_t code_size, TslProgram *program_output) {
TslParseResult result;
TslParser parser;