summaryrefslogtreecommitdiff
path: root/src/xkbcomp/rules.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2013-03-14 14:31:55 +0200
committerDaniel Stone <daniel@fooishbar.org>2013-04-01 18:20:54 +0100
commit99f6e6fc28d91907203f9a19feb4d48878f28cad (patch)
treea2cbc67af4a595dd3c11cfb8918815bcd7775daf /src/xkbcomp/rules.c
parent27a11762abbf0dbeb6d406fee4eee89229b6a660 (diff)
Add scanner-utils.h for common scanner functions
We want to share the same functions for another scanner. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/xkbcomp/rules.c')
-rw-r--r--src/xkbcomp/rules.c96
1 files changed, 1 insertions, 95 deletions
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index 3f71760..ec4a7aa 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -57,6 +57,7 @@
#include "xkbcomp-priv.h"
#include "rules.h"
#include "include.h"
+#include "scanner-utils.h"
/*
* The rules file
@@ -138,25 +139,6 @@
/* Scanner / Lexer */
-/* Point to some substring in the file; used to avoid copying. */
-struct sval {
- const char *start;
- unsigned int len;
-};
-typedef darray(struct sval) darray_sval;
-
-static inline bool
-svaleq(struct sval s1, struct sval s2)
-{
- return s1.len == s2.len && strncmp(s1.start, s2.start, s1.len) == 0;
-}
-
-static inline bool
-svaleq_prefix(struct sval s1, struct sval s2)
-{
- return s1.len <= s2.len && strncmp(s1.start, s2.start, s1.len) == 0;
-}
-
/* Values returned with some tokens, like yylval. */
union lvalue {
struct sval string;
@@ -170,15 +152,6 @@ struct location {
int line, column;
};
-struct scanner {
- const char *s;
- size_t pos;
- size_t len;
- int line, column;
- const char *file_name;
- struct xkb_context *ctx;
-};
-
enum rules_token {
TOK_END_OF_FILE = 0,
TOK_END_OF_LINE,
@@ -190,18 +163,6 @@ enum rules_token {
TOK_ERROR
};
-static void
-scanner_init(struct scanner *s, struct xkb_context *ctx,
- const char *string, size_t len, const char *file_name)
-{
- s->s = string;
- s->len = len;
- s->pos = 0;
- s->line = s->column = 1;
- s->file_name = file_name;
- s->ctx = ctx;
-}
-
/* C99 is stupid. Just use the 1 variant when there are no args. */
#define scanner_error1(scanner, loc, msg) \
log_warn(scanner->ctx, "rules/%s:%d:%d: " msg "\n", \
@@ -210,61 +171,6 @@ scanner_init(struct scanner *s, struct xkb_context *ctx,
log_warn(scanner->ctx, "rules/%s:%d:%d: " fmt "\n", \
scanner->file_name, loc->line, loc->column, __VA_ARGS__)
-static char
-peek(struct scanner *s)
-{
- return s->pos < s->len ? s->s[s->pos] : '\0';
-}
-
-static bool
-eof(struct scanner *s)
-{
- return peek(s) == '\0';
-}
-
-static bool
-eol(struct scanner *s)
-{
- return peek(s) == '\n';
-}
-
-static char
-next(struct scanner *s)
-{
- if (eof(s))
- return '\0';
- if (eol(s)) {
- s->line++;
- s->column = 1;
- }
- else {
- s->column++;
- }
- return s->s[s->pos++];
-}
-
-static bool
-chr(struct scanner *s, char ch)
-{
- if (peek(s) != ch)
- return false;
- s->pos++; s->column++;
- return true;
-}
-
-static bool
-str(struct scanner *s, const char *string, size_t len)
-{
- if (s->len - s->pos < len)
- return false;
- if (strncasecmp(s->s + s->pos, string, len) != 0)
- return false;
- s->pos += len; s->column += len;
- return true;
-}
-
-#define lit(s, literal) str(s, literal, sizeof(literal) - 1)
-
static enum rules_token
lex(struct scanner *s, union lvalue *val, struct location *loc)
{