286 lines
6.1 KiB
C
286 lines
6.1 KiB
C
#line 1 "control_parser.rl"
|
|
|
|
#include "control_parser.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
typedef control_parser_ctx context;
|
|
|
|
static void extract(context *ctx, char *fpc) {
|
|
gsize len = (fpc - ctx->buffer->str) - ctx->mark;
|
|
g_string_truncate(ctx->tmp, 0);
|
|
g_string_append_len(ctx->tmp, ctx->buffer->str + ctx->mark, len);
|
|
ctx->read += len;
|
|
}
|
|
|
|
static double extract_double(context *ctx, char *fpc) {
|
|
extract(ctx, fpc);
|
|
return strtod(ctx->tmp->str, NULL);
|
|
}
|
|
|
|
#line 62 "control_parser.rl"
|
|
|
|
|
|
|
|
#line 27 "control_parser.c"
|
|
static const char _control_parser_actions[] = {
|
|
0, 1, 0, 1, 1, 1, 2, 1,
|
|
3, 1, 4, 1, 5, 1, 6, 1,
|
|
7, 1, 8, 2, 1, 2, 2, 1,
|
|
3, 2, 1, 4, 2, 1, 5, 2,
|
|
1, 6, 2, 1, 7, 2, 1, 8
|
|
|
|
};
|
|
|
|
static const char _control_parser_key_offsets[] = {
|
|
0, 0, 1, 2, 6, 10, 14, 18,
|
|
22, 26, 30, 34, 35, 39, 43, 47,
|
|
51, 55, 59, 63
|
|
};
|
|
|
|
static const char _control_parser_trans_keys[] = {
|
|
73, 32, 32, 46, 48, 57, 32, 46,
|
|
48, 57, 32, 46, 48, 57, 32, 46,
|
|
48, 57, 32, 46, 48, 57, 32, 46,
|
|
48, 57, 32, 46, 48, 57, 32, 46,
|
|
48, 57, 59, 32, 46, 48, 57, 32,
|
|
46, 48, 57, 32, 46, 48, 57, 32,
|
|
46, 48, 57, 32, 46, 48, 57, 32,
|
|
46, 48, 57, 32, 46, 48, 57, 0
|
|
};
|
|
|
|
static const char _control_parser_single_lengths[] = {
|
|
0, 1, 1, 2, 2, 2, 2, 2,
|
|
2, 2, 2, 1, 2, 2, 2, 2,
|
|
2, 2, 2, 0
|
|
};
|
|
|
|
static const char _control_parser_range_lengths[] = {
|
|
0, 0, 0, 1, 1, 1, 1, 1,
|
|
1, 1, 1, 0, 1, 1, 1, 1,
|
|
1, 1, 1, 0
|
|
};
|
|
|
|
static const char _control_parser_index_offsets[] = {
|
|
0, 0, 2, 4, 8, 12, 16, 20,
|
|
24, 28, 32, 36, 38, 42, 46, 50,
|
|
54, 58, 62, 66
|
|
};
|
|
|
|
static const char _control_parser_trans_targs[] = {
|
|
2, 0, 3, 0, 4, 18, 18, 0,
|
|
5, 17, 17, 0, 6, 5, 5, 0,
|
|
7, 16, 16, 0, 8, 15, 15, 0,
|
|
9, 14, 14, 0, 10, 13, 13, 0,
|
|
11, 12, 12, 0, 19, 0, 11, 12,
|
|
12, 0, 10, 13, 13, 0, 9, 14,
|
|
14, 0, 8, 15, 15, 0, 7, 16,
|
|
16, 0, 5, 17, 17, 0, 4, 18,
|
|
18, 0, 0, 0
|
|
};
|
|
|
|
static const char _control_parser_trans_actions[] = {
|
|
0, 0, 0, 0, 19, 3, 3, 0,
|
|
22, 3, 3, 0, 0, 0, 0, 0,
|
|
25, 3, 3, 0, 28, 3, 3, 0,
|
|
31, 3, 3, 0, 34, 3, 3, 0,
|
|
37, 3, 3, 0, 1, 0, 17, 0,
|
|
0, 0, 15, 0, 0, 0, 13, 0,
|
|
0, 0, 11, 0, 0, 0, 9, 0,
|
|
0, 0, 7, 0, 0, 0, 5, 0,
|
|
0, 0, 0, 0
|
|
};
|
|
|
|
static const int control_parser_start = 1;
|
|
static const int control_parser_first_final = 19;
|
|
static const int control_parser_error = 0;
|
|
|
|
static const int control_parser_en_main = 1;
|
|
|
|
#line 65 "control_parser.rl"
|
|
|
|
static int control_parser_has_error(context *ctx) {
|
|
return ctx->cs == control_parser_error;
|
|
}
|
|
|
|
static int control_parser_is_finished(context *ctx) {
|
|
return ctx->cs >= control_parser_first_final;
|
|
}
|
|
|
|
void control_parser_new(trial *t) {
|
|
context *ctx = t->parse_ctx = g_slice_new(context);
|
|
|
|
#line 115 "control_parser.c"
|
|
{
|
|
( ctx->cs) = control_parser_start;
|
|
}
|
|
#line 77 "control_parser.rl"
|
|
ctx->buffer = g_string_sized_new(0);
|
|
ctx->tmp = g_string_sized_new(0);
|
|
}
|
|
|
|
void control_parser_reset(trial *t) {
|
|
context *ctx = t->parse_ctx;
|
|
|
|
#line 127 "control_parser.c"
|
|
{
|
|
( ctx->cs) = control_parser_start;
|
|
}
|
|
#line 84 "control_parser.rl"
|
|
g_string_truncate(ctx->tmp, 0);
|
|
}
|
|
|
|
void control_parser_free(trial *t) {
|
|
g_string_free(t->parse_ctx->buffer, TRUE);
|
|
g_string_free(t->parse_ctx->tmp, TRUE);
|
|
g_slice_free(context, t->parse_ctx);
|
|
}
|
|
|
|
run_t control_parse(trial *t) {
|
|
context *ctx = t->parse_ctx;
|
|
gsize wehave;
|
|
|
|
if (0 < (wehave = ctx->buffer->len - ctx->read)) {
|
|
char *p, *pe;
|
|
|
|
p = ctx->buffer->str + ctx->read;
|
|
pe = p + wehave;
|
|
|
|
|
|
#line 152 "control_parser.c"
|
|
{
|
|
int _klen;
|
|
unsigned int _trans;
|
|
const char *_acts;
|
|
unsigned int _nacts;
|
|
const char *_keys;
|
|
|
|
if ( p == pe )
|
|
goto _test_eof;
|
|
if ( ( ctx->cs) == 0 )
|
|
goto _out;
|
|
_resume:
|
|
_keys = _control_parser_trans_keys + _control_parser_key_offsets[( ctx->cs)];
|
|
_trans = _control_parser_index_offsets[( ctx->cs)];
|
|
|
|
_klen = _control_parser_single_lengths[( ctx->cs)];
|
|
if ( _klen > 0 ) {
|
|
const char *_lower = _keys;
|
|
const char *_mid;
|
|
const char *_upper = _keys + _klen - 1;
|
|
while (1) {
|
|
if ( _upper < _lower )
|
|
break;
|
|
|
|
_mid = _lower + ((_upper-_lower) >> 1);
|
|
if ( (*p) < *_mid )
|
|
_upper = _mid - 1;
|
|
else if ( (*p) > *_mid )
|
|
_lower = _mid + 1;
|
|
else {
|
|
_trans += (_mid - _keys);
|
|
goto _match;
|
|
}
|
|
}
|
|
_keys += _klen;
|
|
_trans += _klen;
|
|
}
|
|
|
|
_klen = _control_parser_range_lengths[( ctx->cs)];
|
|
if ( _klen > 0 ) {
|
|
const char *_lower = _keys;
|
|
const char *_mid;
|
|
const char *_upper = _keys + (_klen<<1) - 2;
|
|
while (1) {
|
|
if ( _upper < _lower )
|
|
break;
|
|
|
|
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
|
if ( (*p) < _mid[0] )
|
|
_upper = _mid - 2;
|
|
else if ( (*p) > _mid[1] )
|
|
_lower = _mid + 2;
|
|
else {
|
|
_trans += ((_mid - _keys)>>1);
|
|
goto _match;
|
|
}
|
|
}
|
|
_trans += _klen;
|
|
}
|
|
|
|
_match:
|
|
( ctx->cs) = _control_parser_trans_targs[_trans];
|
|
|
|
if ( _control_parser_trans_actions[_trans] == 0 )
|
|
goto _again;
|
|
|
|
_acts = _control_parser_actions + _control_parser_trans_actions[_trans];
|
|
_nacts = (unsigned int) *_acts++;
|
|
while ( _nacts-- > 0 )
|
|
{
|
|
switch ( *_acts++ )
|
|
{
|
|
case 0:
|
|
#line 26 "control_parser.rl"
|
|
{ {p++; goto _out; } }
|
|
break;
|
|
case 1:
|
|
#line 27 "control_parser.rl"
|
|
{ ctx->mark = p - ctx->buffer->str; }
|
|
break;
|
|
case 2:
|
|
#line 35 "control_parser.rl"
|
|
{ t->map.dx = extract_double(ctx, p); }
|
|
break;
|
|
case 3:
|
|
#line 36 "control_parser.rl"
|
|
{ t->map.dy = extract_double(ctx, p); }
|
|
break;
|
|
case 4:
|
|
#line 37 "control_parser.rl"
|
|
{ t->map.min_sensor = extract_double(ctx, p); }
|
|
break;
|
|
case 5:
|
|
#line 38 "control_parser.rl"
|
|
{ t->map.max_sensor = extract_double(ctx, p); }
|
|
break;
|
|
case 6:
|
|
#line 39 "control_parser.rl"
|
|
{ t->map.max_speed = extract_double(ctx, p); }
|
|
break;
|
|
case 7:
|
|
#line 40 "control_parser.rl"
|
|
{ t->map.max_turn = extract_double(ctx, p); }
|
|
break;
|
|
case 8:
|
|
#line 41 "control_parser.rl"
|
|
{ t->map.max_hard_turn = extract_double(ctx, p); }
|
|
break;
|
|
#line 261 "control_parser.c"
|
|
}
|
|
}
|
|
|
|
_again:
|
|
if ( ( ctx->cs) == 0 )
|
|
goto _out;
|
|
if ( ++p != pe )
|
|
goto _resume;
|
|
_test_eof: {}
|
|
_out: {}
|
|
}
|
|
#line 104 "control_parser.rl"
|
|
|
|
g_string_erase(ctx->buffer, 0, ctx->read);
|
|
ctx->mark -= ctx->read;
|
|
ctx->read = 0;
|
|
}
|
|
|
|
if (control_parser_has_error(ctx)) {
|
|
fprintf(stderr, "Parse error\n");
|
|
return RUN_ERROR;
|
|
}
|
|
if (control_parser_is_finished(ctx)) return RUN_DONE;
|
|
return RUN_GO_ON;
|
|
}
|