Worked on token_string and memory errors
This commit is contained in:
parent
2a03107e94
commit
3a61e250a9
|
|
@ -743,7 +743,17 @@ static LexerResult parse_token_string(LexerInfo *lexer_info, char c, size_t star
|
||||||
return (LexerResult){SLS_ERROR, .error = (SlsError){SLS_STR("Unknown Error."), 1}};
|
return (LexerResult){SLS_ERROR, .error = (SlsError){SLS_STR("Unknown Error."), 1}};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current->type == SLS_ERROR || current->result.type == TOKEN_EOF) break;
|
if (current->type == SLS_ERROR) {
|
||||||
|
LexerResult e = (LexerResult){SLS_RESULT, .result = &(LexerTokenResult){
|
||||||
|
.type = SLS_ERROR,
|
||||||
|
.error = (SlsError){sls_str_cpy(current->error.message), 1},
|
||||||
|
.file_info = current->file_info,
|
||||||
|
.next = NULL
|
||||||
|
}};
|
||||||
|
clean_token_result(head);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
if (current->result.type == TOKEN_EOF) break;
|
||||||
|
|
||||||
c = peek(lexer_info);
|
c = peek(lexer_info);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -494,9 +494,41 @@ Boolean test_array_struct_inline_value(LexerTest *test, LexerResult result, size
|
||||||
static LexerResult token_string_to_lexer_result(TokenString token_string, FileInfo file_info) {
|
static LexerResult token_string_to_lexer_result(TokenString token_string, FileInfo file_info) {
|
||||||
LexerTokenResult *new, *head;
|
LexerTokenResult *new, *head;
|
||||||
head = 0;
|
head = 0;
|
||||||
for (size_t i = 0; i < token_string.length; i++) {
|
for (size_t i = token_string.length; i > 0; i--) {
|
||||||
new = (LexerTokenResult *)malloc(sizeof(LexerTokenResult));
|
new = (LexerTokenResult *)malloc(sizeof(LexerTokenResult));
|
||||||
*new = (LexerTokenResult) { .type = SLS_RESULT, .result = token_string.tokens[i], .file_info = file_info, .next = head };
|
if (new == 0) return (LexerResult) { .type = SLS_ERROR, .error = (SlsError){SLS_STR("Out Of Memory Error."), 1} };
|
||||||
|
if (token_string.tokens[i-1].type == TOKEN_STRING) {
|
||||||
|
*new = (LexerTokenResult) {
|
||||||
|
.type = SLS_RESULT,
|
||||||
|
.result = (Token){
|
||||||
|
.type = TOKEN_STRING,
|
||||||
|
.string_literal = sls_str_cpy(token_string.tokens[i-1].string_literal)
|
||||||
|
},
|
||||||
|
.file_info = file_info,
|
||||||
|
.next = head
|
||||||
|
};
|
||||||
|
} else if (token_string.tokens[i-1].type == TOKEN_TOKEN_STRING) {
|
||||||
|
*new = (LexerTokenResult) {
|
||||||
|
.type = SLS_RESULT,
|
||||||
|
.result = (Token){
|
||||||
|
.type = TOKEN_TOKEN_STRING,
|
||||||
|
.token_string = (TokenString){
|
||||||
|
.length = token_string.tokens[i-1].token_string.length,
|
||||||
|
.tokens = (Token *)malloc(sizeof(Token) * token_string.tokens[i-1].token_string.length),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.file_info = file_info,
|
||||||
|
.next = head
|
||||||
|
};
|
||||||
|
memcpy(new->result.token_string.tokens, token_string.tokens[i-1].token_string.tokens, token_string.tokens[i-1].token_string.length);
|
||||||
|
} else {
|
||||||
|
*new = (LexerTokenResult) {
|
||||||
|
.type = SLS_RESULT,
|
||||||
|
.result = token_string.tokens[i-1],
|
||||||
|
.file_info = file_info,
|
||||||
|
.next = head
|
||||||
|
};
|
||||||
|
}
|
||||||
head = new;
|
head = new;
|
||||||
}
|
}
|
||||||
return (LexerResult) { .type = SLS_RESULT, .result = head };
|
return (LexerResult) { .type = SLS_RESULT, .result = head };
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue