35 static inline void strref_clear(
struct strref *dst)
41 static inline void strref_set(
struct strref *dst,
const char *array,
size_t len)
47 static inline void strref_copy(
struct strref *dst,
const struct strref *src)
53 static inline void strref_add(
struct strref *dst,
const struct strref *t)
61 static inline bool strref_is_empty(
const struct strref *str)
69 const struct strref *str2);
71 const struct strref *str2);
78 static inline bool valid_int_strref(
const struct strref *str)
83 static inline bool valid_float_strref(
const struct strref *str)
88 static inline bool is_whitespace(
char ch)
90 return ch ==
' ' || ch ==
'\r' || ch ==
'\t' || ch ==
'\n';
93 static inline bool is_newline(
char ch)
95 return ch ==
'\r' || ch ==
'\n';
98 static inline bool is_space_or_tab(
const char ch)
100 return ch ==
' ' || ch ==
'\t';
103 static inline bool is_newline_pair(
char ch1,
char ch2)
105 return (ch1 ==
'\r' && ch2 ==
'\n') || (ch1 ==
'\n' && ch2 ==
'\r');
108 static inline int newline_size(
const char *array)
110 if (strncmp(array,
"\r\n", 2) == 0 || strncmp(array,
"\n\r", 2) == 0)
112 else if (*array ==
'\r' || *array ==
'\n')
142 static inline void base_token_clear(
struct base_token *t)
147 static inline void base_token_copy(
struct base_token *dst,
156 #define LEX_WARNING 1 165 static inline void error_item_init(
struct error_item *ei)
170 static inline void error_item_free(
struct error_item *ei)
176 static inline void error_item_array_free(
struct error_item *array,
size_t num)
179 for (i = 0; i < num; i++)
180 error_item_free(array + i);
189 static inline void error_data_init(
struct error_data *data)
194 static inline void error_data_free(
struct error_data *data)
196 error_item_array_free(data->errors.array, data->errors.num);
203 return ed->errors.array + idx;
209 uint32_t
row, uint32_t
column,
const char *msg,
212 static inline size_t error_data_type_count(
struct error_data *ed,
int type)
215 for (i = 0; i < ed->errors.num; i++) {
216 if (ed->errors.array[i].level == type)
223 static inline bool error_data_has_errors(
struct error_data *ed)
226 for (i = 0; i < ed->errors.num; i++)
227 if (ed->errors.array[i].level ==
LEX_ERROR)
240 static inline void lexer_init(
struct lexer *lex)
242 memset(lex, 0,
sizeof(
struct lexer));
245 static inline void lexer_free(
struct lexer *lex)
251 static inline void lexer_start(
struct lexer *lex,
const char *text)
254 lex->
text = bstrdup(text);
258 static inline void lexer_start_move(
struct lexer *lex,
char *text)
265 static inline void lexer_reset(
struct lexer *lex)
276 uint32_t *row, uint32_t *col);
EXPORT char * error_data_buildstring(struct error_data *ed)
#define LEX_ERROR
Definition: lexer.h:155
size_t len
Definition: lexer.h:32
uint32_t row
Definition: lexer.h:161
uint32_t column
Definition: lexer.h:161
char * error
Definition: lexer.h:159
EXPORT int strref_cmp_strref(const struct strref *str1, const struct strref *str2)
const char * offset
Definition: lexer.h:237
bool passed_whitespace
Definition: lexer.h:139
int level
Definition: lexer.h:162
const char * file
Definition: lexer.h:160
DARRAY(struct error_item) errors
EXPORT int strref_cmpi_strref(const struct strref *str1, const struct strref *str2)
#define EXPORT
Definition: c99defs.h:37
enum base_token_type type
Definition: lexer.h:138
EXPORT void lexer_getstroffset(const struct lexer *lex, const char *str, uint32_t *row, uint32_t *col)
struct strref text
Definition: lexer.h:137
base_token_type
Definition: lexer.h:128
EXPORT int strref_cmpi(const struct strref *str1, const char *str2)
EXPORT bool valid_int_str(const char *str, size_t n)
#define da_free(v)
Definition: darray.h:467
EXPORT void error_data_add(struct error_data *ed, const char *file, uint32_t row, uint32_t column, const char *msg, int level)
ignore_whitespace
Definition: lexer.h:270
EXPORT bool valid_float_str(const char *str, size_t n)
EXPORT int strref_cmp(const struct strref *str1, const char *str2)
const char * array
Definition: lexer.h:31
char * text
Definition: lexer.h:236
#define da_init(v)
Definition: darray.h:465
EXPORT void bfree(void *ptr)
EXPORT bool lexer_getbasetoken(struct lexer *lex, struct base_token *t, enum ignore_whitespace iws)