diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/fspec/dump.c | 43 | ||||
-rw-r--r-- | src/fspec/ragel/lexer-expr.rl | 6 | ||||
-rw-r--r-- | src/fspec/ragel/lexer.rl | 2 |
3 files changed, 45 insertions, 6 deletions
diff --git a/src/bin/fspec/dump.c b/src/bin/fspec/dump.c index 07a6757..8ca53b2 100644 --- a/src/bin/fspec/dump.c +++ b/src/bin/fspec/dump.c @@ -14,6 +14,7 @@ #include <fspec/bcode.h> #include <fspec/lexer.h> #include <fspec/validator.h> +#include "fspec/ragel/lexer-expr.h" #include "util/membuf.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -756,6 +757,29 @@ fopen_or_die(const char *path, const char *mode) #define container_of(ptr, type, member) ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member))) +struct expr { + struct fspec_expr expr; + struct membuf output; + FILE *file; +}; + +static size_t +fspec_expr_write(struct fspec_expr *expr, const void *output, const size_t size, const size_t nmemb) +{ + assert(expr && output); + // struct expr *l = container_of(expr, struct expr, expr); + (void)expr, (void)size, (void)nmemb; + return nmemb; +} + +static size_t +fspec_expr_read(struct fspec_expr *expr, void *input, const size_t size, const size_t nmemb) +{ + assert(expr && input); + struct expr *l = container_of(expr, struct expr, expr); + return fread(input, size, nmemb, l->file); +} + struct lexer { struct fspec_lexer lexer; struct membuf output; @@ -803,6 +827,25 @@ main(int argc, const char *argv[]) { char input[4096]; + struct expr l = { + .expr = { + .ops.read = fspec_expr_read, + .ops.write = fspec_expr_write, + .mem.input = { .data = input, .len = sizeof(input) }, + }, + .file = fopen_or_die(argv[1], "rb"), + .output.mem = { .data = output, .len = sizeof(output) }, + }; + + if (!fspec_expr_parse(&l.expr, argv[1])) + exit(EXIT_FAILURE); + + fclose(l.file); + // bcode = l.expr.mem.output; + } + + { + char input[4096]; struct lexer l = { .lexer = { .ops.read = fspec_lexer_read, diff --git a/src/fspec/ragel/lexer-expr.rl b/src/fspec/ragel/lexer-expr.rl index 2975043..0f1f83d 100644 --- a/src/fspec/ragel/lexer-expr.rl +++ b/src/fspec/ragel/lexer-expr.rl @@ -66,11 +66,7 @@ pop(char cur, char *mstack, size_t open) bitwise_operators = '&' | '|' | '^' | '<<' | '>>'; main := |* - '+' => op; - '/' => op; - '*' => op; - '-' => op; - '^' => op; + calc_operators => op; stack_num => { mstack[open++] = fc;}; '(' => { }; ')' => { }; diff --git a/src/fspec/ragel/lexer.rl b/src/fspec/ragel/lexer.rl index b4a21dc..8354bc0 100644 --- a/src/fspec/ragel/lexer.rl +++ b/src/fspec/ragel/lexer.rl @@ -128,7 +128,7 @@ newline = '\n'; valid = ^cntrl; comment = '//' <: valid* :>> newline; - type = ('u8' | 's8') %r8 | ('u16' | 's16') %r16 | ('u32' | 's32') %r32 | ('u64' | 's32') %r64; + type = ('u8' | 's8') %r8 | ('u16' | 's16') %r16 | ('u32' | 's32') %r32 | ('u64' | 's64') %r64; visual = 'nul' %vnul | 'dec' %vdec | 'hex' %vhex | 'str' %vstr; # Catchers |