7#ifndef PRINTLINES_ALLOWED
8#define PRINTLINES_ALLOWED 0
11static const char *FNAME =
"kest_tokenizer.c";
17 return ((
'A' <= c && c <=
'Z') || (
'a' <= c && c <=
'z'));
22 return (
'0' <= c && c <=
'9');
32 return (c ==
'(' || c ==
'[' || c ==
'{'
33 || c ==
')' || c ==
']' || c ==
'}');
55 return (str && str[0] == c && str[1] == 0);
72 if (!(
'0' <= token[pos] && token[pos] <=
'9'))
85 int len = strlen(token);
87 char allowed_chars[27] =
".0123456789\0\0\0abcdefABCDEF\0";
94 allowed_chars[11] =
'b';
95 allowed_chars[12] =
'x';
97 else if (token[0] ==
'.')
99 allowed_chars[0] =
'0';
105 for (
int i = 1; i < len; i++)
111 allowed_chars[0] =
'0';
115 if (token[i] ==
'x' || token[i] ==
'b')
117 allowed_chars[11] =
'0';
118 allowed_chars[12] =
'0';
124 allowed_chars[3] = 0;
126 allowed_chars[13] =
'0';
139 if (strcmp(token,
",") == 0)
142 if (strcmp(token,
"\n") == 0)
145 if (strcmp(token,
";") == 0)
153 if (
'0' <= c && c <=
'9')
154 return (
float)(c -
'0');
155 else if (
'a' <= c && c <=
'f')
156 return (
float)(c -
'a');
157 else if (
'A' <= c && c <=
'F')
158 return (
float)(c -
'A');
168 int len = strlen(token);
177 if (len > 2 && token[0] ==
'0')
184 else if (token[1] ==
'x')
193 if (token[pos] ==
'.')
220 int len = strlen(token);
225 for (
int i = 0; i < len; i++)
245 *list = (*list)->
next;
255 while (current && current->
data)
259 if (current->
data[0] ==
'\n' || current->
data[0] ==
' ' || current->
data[0] ==
'\t')
265 current = current->
next;
283 while (current && current->
data)
287 if (current->
data[0] ==
'\n' || current->
data[0] ==
' ' || current->
data[0] ==
'\t')
293 current = current->
next;
320 while (current->
next)
321 current = current->
next;
323 current->
next = node;
352 while (current->
next)
353 current = current->
next;
355 current->
next = node;
370 int state = *state_ptr;
372 if (c == 0 || c == EOF)
494 if (c ==
'0' || c ==
'1' || c ==
'.')
523 buf[0] = ps->
content[file_pos++];
524 buf[1] = ps->
content[file_pos++];
525 buf[2] = ps->
content[file_pos++];
526 buf[3] = ps->
content[file_pos++];
531 KEST_PRINTF(
"'%c' (%d), '%c' (%d), '%c' (%d), '%c' (%d)\n", buf[0], buf[0], buf[1], buf[1], buf[2], buf[2], buf[3], buf[3]);
566 token_index += buf_pos;
583 token_index += buf_pos;
633 while (current && current != end)
636 current = current->
next;
void * kest_alloc(size_t size)
char * kest_parser_strndup(const char *str, int n)
void * kest_parser_alloc(size_t size)
void kest_parser_error_at_line(kest_eff_parsing_state *ps, int line, const char *msg,...)
#define IMPLEMENT_LINKED_PTR_LIST(X)
int kest_token_ll_safe_aappend(kest_token_ll **list_ptr, char *x, int line, int index)
int char_is_in_string(char c, const char *str)
int token_is_newline(char *str)
int kest_token_ll_safe_append(kest_token_ll **list_ptr, char *x, int line, int index)
int token_is_int(char *token)
int char_is_bracket(char c)
float digit_to_float(char c)
int char_is_number(char c)
float token_to_float(char *token)
int token_is_name(char *token)
int token_is_dict_entry_seperator(char *token)
int kest_token_ll_advance(kest_token_ll **list)
int token_is_char(char *str, char c)
int char_is_alphanumeric(char c)
int kest_tokenize_content(kest_eff_parsing_state *ps)
int tokenizer_policy(char c, int *state_ptr)
int kest_token_ll_skip_ws(kest_token_ll **list)
kest_token_ll * kest_token_span_to_ll(kest_token_ll *start, kest_token_ll *end)
int char_is_letter(char c)
int token_is_number(char *token)
#define TOKENIZER_STATE_DONE
#define TOKENIZER_STATE_NAME
#define TOKENIZER_STATE_IDLE
#define TOKENIZER_STATE_NUMBER_BIN
#define TOKENIZER_POLICY_DISCARD
#define TOKENIZER_STATE_STRESC
#define TOKENIZER_POLICY_COMPLAIN
#define TOKENIZER_POLICY_END_ACCEPT
#define TOKENIZER_POLICY_SINGULAR
#define TOKENIZER_STATE_LEADING_ZERO
#define TOKENIZER_POLICY_BEGIN
#define TOKENIZER_POLICY_ACCEPT
#define TOKENIZER_POLICY_END_DISCARD
#define TOKENIZER_STATE_NUMBER
#define TOKENIZER_STATE_STRING
#define TOKENIZER_STATE_NUMBER_HEX
struct kest_token_ll * next