Implement String structure and update Location/Token to use it
This commit is contained in:
+7
-6
@@ -93,13 +93,14 @@ static size_t get_line_length(const char* line_start) {
|
||||
static Token create_token(TokenStream* ts, TokenType type, const char* text, size_t length, int line, int column, const char* line_start) {
|
||||
Token t;
|
||||
t.token = type;
|
||||
t.text = (char*)text;
|
||||
t.text_length = length;
|
||||
t.text.data = (char*)text;
|
||||
t.text.length = length;
|
||||
t.location.filename = (char*)ts->filename;
|
||||
t.location.line = line;
|
||||
t.location.column = column;
|
||||
t.location.line_text = (char*)line_start;
|
||||
t.location.line_text_length = get_line_length(line_start);
|
||||
t.location.column_start = column;
|
||||
t.location.column_end = column + (int)length - 1;
|
||||
t.location.line_text.data = (char*)line_start;
|
||||
t.location.line_text.length = get_line_length(line_start);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -192,6 +193,6 @@ Token tokenstream_next(TokenStream* ts) {
|
||||
|
||||
/* Unknown character */
|
||||
Token t = create_token(ts, TOKEN_UNKNOWN, start_text, 1, start_line, start_column, line_start);
|
||||
log_on_line(&t.location, t.location.column, "unexpected token '%c'", c);
|
||||
log_on_line(&t.location, t.location.column_end, "unexpected token '%c'", c);
|
||||
return t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user