mie: parse: add mie_file_span to record character span locations within files
This commit is contained in:
23
mie/include/mie/parse/file-span.h
Normal file
23
mie/include/mie/parse/file-span.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef MIE_PARSE_FILE_SPAN_H_
|
||||||
|
#define MIE_PARSE_FILE_SPAN_H_
|
||||||
|
|
||||||
|
#include <mie/misc.h>
|
||||||
|
|
||||||
|
struct mie_token;
|
||||||
|
|
||||||
|
/* a single row/column pair, representing a location within a file.
|
||||||
|
* both values are 1-based (i.e. the first character in a file is at c_row=1,
|
||||||
|
* c_col=1*/
|
||||||
|
struct mie_file_cell {
|
||||||
|
unsigned int c_row, c_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* represents a span of characters within a file.
|
||||||
|
* used for diagnostic reporting */
|
||||||
|
struct mie_file_span {
|
||||||
|
struct mie_file_cell s_start, s_end;
|
||||||
|
};
|
||||||
|
|
||||||
|
MIE_API void mie_file_span_init(struct mie_file_span *span, struct mie_token *tok);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <blue/core/queue.h>
|
#include <blue/core/queue.h>
|
||||||
#include <mie/misc.h>
|
#include <mie/misc.h>
|
||||||
|
#include <mie/parse/file-span.h>
|
||||||
|
|
||||||
#define MIE_TOKEN_TYPE(tok) ((tok) ? (tok)->tok_type : MIE_TOK_NONE)
|
#define MIE_TOKEN_TYPE(tok) ((tok) ? (tok)->tok_type : MIE_TOK_NONE)
|
||||||
#define MIE_TOKEN_IS(tok, type) ((tok) && ((tok)->tok_type & (type)) != 0)
|
#define MIE_TOKEN_IS(tok, type) ((tok) && ((tok)->tok_type & (type)) != 0)
|
||||||
@@ -72,12 +73,8 @@ enum mie_token_symbol {
|
|||||||
MIE_SYM_OTHER,
|
MIE_SYM_OTHER,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mie_token_location {
|
|
||||||
unsigned int c_row, c_col;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct mie_token {
|
struct mie_token {
|
||||||
struct mie_token_location tok_start, tok_end;
|
struct mie_file_span tok_location;
|
||||||
enum mie_token_type tok_type;
|
enum mie_token_type tok_type;
|
||||||
enum mie_token_value_type tok_value_type;
|
enum mie_token_value_type tok_value_type;
|
||||||
b_queue_entry tok_entry;
|
b_queue_entry tok_entry;
|
||||||
|
|||||||
7
mie/parse/file-span.c
Normal file
7
mie/parse/file-span.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <mie/parse/file-span.h>
|
||||||
|
#include <mie/parse/token.h>
|
||||||
|
|
||||||
|
void mie_file_span_init(struct mie_file_span *span, struct mie_token *tok)
|
||||||
|
{
|
||||||
|
*span = tok->tok_location;
|
||||||
|
}
|
||||||
@@ -324,10 +324,10 @@ static void set_token_end(struct mie_lex *lex)
|
|||||||
|
|
||||||
static enum mie_status push_token(struct mie_lex *lex, struct mie_token *tok)
|
static enum mie_status push_token(struct mie_lex *lex, struct mie_token *tok)
|
||||||
{
|
{
|
||||||
tok->tok_start.c_row = lex->lex_token_start_row;
|
tok->tok_location.s_start.c_row = lex->lex_token_start_row;
|
||||||
tok->tok_start.c_col = lex->lex_token_start_col;
|
tok->tok_location.s_start.c_col = lex->lex_token_start_col;
|
||||||
tok->tok_end.c_row = lex->lex_token_end_row;
|
tok->tok_location.s_end.c_row = lex->lex_token_end_row;
|
||||||
tok->tok_end.c_col = lex->lex_token_end_col;
|
tok->tok_location.s_end.c_col = lex->lex_token_end_col;
|
||||||
|
|
||||||
b_queue_push_back(&lex->lex_queue, &tok->tok_entry);
|
b_queue_push_back(&lex->lex_queue, &tok->tok_entry);
|
||||||
return MIE_SUCCESS;
|
return MIE_SUCCESS;
|
||||||
|
|||||||
@@ -409,11 +409,14 @@ static bool parse_generic_op(
|
|||||||
struct mie_parser *ctx, struct mie_name_map *names, struct mie_op *dest)
|
struct mie_parser *ctx, struct mie_name_map *names, struct mie_op *dest)
|
||||||
{
|
{
|
||||||
b_string *str = b_string_create();
|
b_string *str = b_string_create();
|
||||||
if (!mie_parser_parse_opname(ctx, str)) {
|
struct mie_file_span loc;
|
||||||
|
if (!mie_parser_parse_opname(ctx, str, &loc)) {
|
||||||
|
b_string_unref(str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dest->op_name = b_string_steal(str);
|
dest->op_name = b_string_steal(str);
|
||||||
|
b_string_unref(str);
|
||||||
|
|
||||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_PAREN)) {
|
if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_PAREN)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user