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') ||
106 (ch1 ==
'\n' && ch2 ==
'\r');
109 static inline int newline_size(
const char *array)
111 if (strncmp(array,
"\r\n", 2) == 0 || strncmp(array,
"\n\r", 2) == 0)
113 else if (*array ==
'\r' || *array ==
'\n')
143 static inline void base_token_clear(
struct base_token *t)
148 static inline void base_token_copy(
struct base_token *dst,
157 #define LEX_WARNING 1
166 static inline void error_item_init(
struct error_item *ei)
171 static inline void error_item_free(
struct error_item *ei)
177 static inline void error_item_array_free(
struct error_item *array,
size_t num)
180 for (i = 0; i < num; i++)
181 error_item_free(array+i);
190 static inline void error_data_init(
struct error_data *data)
195 static inline void error_data_free(
struct error_data *data)
197 error_item_array_free(data->errors.array, data->errors.num);
204 return ed->errors.array+idx;
212 static inline size_t error_data_type_count(
struct error_data *ed,
216 for (i = 0; i < ed->errors.num; i++) {
217 if (ed->errors.array[i].level == type)
224 static inline bool error_data_has_errors(
struct error_data *ed)
227 for (i = 0; i < ed->errors.num; i++)
228 if (ed->errors.array[i].level ==
LEX_ERROR)
241 static inline void lexer_init(
struct lexer *lex)
243 memset(lex, 0,
sizeof(
struct lexer));
246 static inline void lexer_free(
struct lexer *lex)
252 static inline void lexer_start(
struct lexer *lex,
const char *text)
255 lex->
text = bstrdup(text);
259 static inline void lexer_start_move(
struct lexer *lex,
char *text)
266 static inline void lexer_reset(
struct lexer *lex)
EXPORT char * error_data_buildstring(struct error_data *ed)
#define LEX_ERROR
Definition: lexer.h:156
size_t len
Definition: lexer.h:32
uint32_t row
Definition: lexer.h:162
unsigned uint32_t
Definition: vc_stdint.h:31
uint32_t column
Definition: lexer.h:162
char * error
Definition: lexer.h:160
EXPORT int strref_cmp_strref(const struct strref *str1, const struct strref *str2)
const char * offset
Definition: lexer.h:238
bool passed_whitespace
Definition: lexer.h:140
int level
Definition: lexer.h:163
const char * file
Definition: lexer.h:161
DARRAY(struct error_item) errors
EXPORT int strref_cmpi_strref(const struct strref *str1, const struct strref *str2)
#define EXPORT
Definition: c99defs.h:49
enum base_token_type type
Definition: lexer.h:139
EXPORT void lexer_getstroffset(const struct lexer *lex, const char *str, uint32_t *row, uint32_t *col)
struct strref text
Definition: lexer.h:138
base_token_type
Definition: lexer.h:129
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:456
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:271
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:237
#define da_init(v)
Definition: darray.h:454
EXPORT void bfree(void *ptr)
EXPORT bool lexer_getbasetoken(struct lexer *lex, struct base_token *t, enum ignore_whitespace iws)