Commit 44ce38dd authored by Niels Möller's avatar Niels Möller
Browse files

(config_tokenizer_eolp): New function.

Rev: src/tokenize_config.c:1.3
Rev: src/tokenize_config.h:1.3
parent 4af86c90
...@@ -47,14 +47,10 @@ config_tokenizer_init(struct config_tokenizer *self, ...@@ -47,14 +47,10 @@ config_tokenizer_init(struct config_tokenizer *self,
self->lineno = 1; self->lineno = 1;
} }
enum config_token_type
config_tokenizer_next(struct config_tokenizer *self)
{
static const char char_class[0x100] = static const char char_class[0x100] =
{ {
/* HT, LF, VT, FF, CR */ /* HT, LF, VT, FF, CR */
0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,1,4,1,1,1,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* SPACE */ /* SPACE */
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
...@@ -66,8 +62,13 @@ config_tokenizer_next(struct config_tokenizer *self) ...@@ -66,8 +62,13 @@ config_tokenizer_next(struct config_tokenizer *self)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
}; };
#define IS_SPACE(c) (char_class[c] & 1) #define IS_SPACE(c) (char_class[c] & 5)
#define IS_SEPARATOR(c) (char_class[c] & 3) #define IS_SPACE_NOT_LF(c) (char_class[c] & 1)
#define IS_SEPARATOR(c) (char_class[c] & 7)
enum config_token_type
config_tokenizer_next(struct config_tokenizer *self)
{
for (;;) for (;;)
{ {
while (LEFT && IS_SPACE(*HERE)) while (LEFT && IS_SPACE(*HERE))
...@@ -113,6 +114,30 @@ config_tokenizer_next(struct config_tokenizer *self) ...@@ -113,6 +114,30 @@ config_tokenizer_next(struct config_tokenizer *self)
} }
} }
/* Skips to end of line, and returns 1 if there's only space and
comments, otherwise zero.*/
int
config_tokenizer_eolp(struct config_tokenizer *self)
{
int res;
/* Skip space within the line. */
while (LEFT && IS_SPACE_NOT_LF(*HERE))
ADVANCE(1);
/* End of file counts as an end of line */
if (!LEFT)
return 1;
res = (*HERE == '\n' || *HERE == '#');
/* Skip rest of line */
while (LEFT && *HERE != '\n')
ADVANCE(1);
return res;
}
void void
config_tokenizer_error(struct config_tokenizer *self, const char *msg) config_tokenizer_error(struct config_tokenizer *self, const char *msg)
{ {
......
...@@ -56,6 +56,9 @@ config_tokenizer_init(struct config_tokenizer *self, ...@@ -56,6 +56,9 @@ config_tokenizer_init(struct config_tokenizer *self,
enum config_token_type enum config_token_type
config_tokenizer_next(struct config_tokenizer *self); config_tokenizer_next(struct config_tokenizer *self);
int
config_tokenizer_eolp(struct config_tokenizer *self);
void void
config_tokenizer_error(struct config_tokenizer *self, const char *msg); config_tokenizer_error(struct config_tokenizer *self, const char *msg);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment