Commit 710a2271 authored by Daniel Salzman's avatar Daniel Salzman

yparser: fix comment processing

parent 1e0f45bf
......@@ -26,20 +26,23 @@
// Include parser static data (Ragel internals).
static const char _yparser_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 6, 1, 7, 1,
8, 1, 9, 1, 10, 1, 13, 2,
1, 0, 2, 2, 3, 2, 4, 0,
2, 5, 6, 2, 10, 11, 2, 12,
10, 3, 1, 5, 6, 3, 1, 10,
11, 3, 1, 12, 10
0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 5, 1, 7, 1, 8, 1,
9, 1, 10, 1, 11, 1, 14, 2,
1, 0, 2, 1, 2, 2, 3, 4,
2, 5, 0, 2, 6, 7, 2, 11,
12, 2, 13, 11, 3, 1, 2, 0,
3, 1, 6, 7, 3, 1, 11, 12,
3, 1, 13, 11, 4, 1, 2, 6,
7, 4, 1, 2, 11, 12, 4, 1,
2, 13, 11
};
static const unsigned char _yparser_key_offsets[] = {
0, 0, 10, 11, 12, 19, 28, 30,
31, 41, 51, 54, 57, 59, 68, 70,
72, 83, 93, 101, 104, 106, 109, 112,
121, 131
31, 41, 51, 60, 62, 64, 75, 78,
80, 83, 84, 94, 102, 105, 107, 110,
113, 122, 132, 142
};
static const char _yparser_trans_keys[] = {
......@@ -49,39 +52,41 @@ static const char _yparser_trans_keys[] = {
65, 90, 97, 122, 32, 58, 32, 32,
33, 34, 92, 36, 43, 45, 90, 94,
126, 10, 32, 33, 92, 36, 43, 45,
90, 94, 126, 10, 32, 35, 34, 32,
126, 10, 32, 32, 45, 58, 48, 57,
90, 94, 126, 32, 45, 58, 48, 57,
65, 90, 97, 122, 32, 58, 10, 32,
10, 32, 34, 35, 91, 33, 43, 45,
92, 94, 126, 32, 33, 34, 92, 36,
43, 45, 90, 94, 126, 32, 33, 44,
93, 36, 90, 92, 126, 32, 44, 93,
10, 32, 34, 32, 126, 32, 44, 93,
32, 45, 58, 48, 57, 65, 90, 97,
122, 10, 32, 35, 45, 48, 57, 65,
90, 97, 122, 10, 32, 35, 45, 48,
57, 65, 90, 97, 122, 0
92, 94, 126, 34, 32, 126, 10, 32,
10, 32, 35, 10, 32, 33, 34, 92,
36, 43, 45, 90, 94, 126, 32, 33,
44, 93, 36, 90, 92, 126, 32, 44,
93, 10, 32, 34, 32, 126, 32, 44,
93, 32, 45, 58, 48, 57, 65, 90,
97, 122, 10, 32, 35, 45, 48, 57,
65, 90, 97, 122, 10, 32, 35, 45,
48, 57, 65, 90, 97, 122, 10, 32,
35, 45, 48, 57, 65, 90, 97, 122,
0
};
static const char _yparser_single_lengths[] = {
0, 4, 1, 1, 1, 3, 2, 1,
4, 4, 3, 1, 2, 3, 2, 2,
5, 4, 4, 3, 2, 1, 3, 3,
4, 4
4, 4, 3, 2, 2, 5, 1, 2,
3, 1, 4, 4, 3, 2, 1, 3,
3, 4, 4, 4
};
static const char _yparser_range_lengths[] = {
0, 3, 0, 0, 3, 3, 0, 0,
3, 3, 0, 1, 0, 3, 0, 0,
3, 3, 2, 0, 0, 1, 0, 3,
3, 3
3, 3, 3, 0, 0, 3, 1, 0,
0, 0, 3, 2, 0, 0, 1, 0,
3, 3, 3, 3
};
static const unsigned char _yparser_index_offsets[] = {
0, 0, 8, 10, 12, 17, 24, 27,
29, 37, 45, 49, 52, 55, 62, 65,
68, 77, 85, 92, 96, 99, 102, 106,
113, 121
29, 37, 45, 52, 55, 58, 67, 70,
73, 77, 79, 87, 94, 98, 101, 104,
108, 115, 123, 131
};
static const char _yparser_indicies[] = {
......@@ -90,43 +95,46 @@ static const char _yparser_indicies[] = {
0, 8, 9, 10, 9, 9, 9, 0,
11, 12, 0, 13, 0, 13, 14, 15,
14, 14, 14, 14, 0, 16, 17, 18,
18, 18, 18, 18, 0, 1, 19, 3,
0, 21, 20, 0, 16, 17, 0, 22,
23, 24, 23, 23, 23, 0, 25, 26,
0, 1, 27, 0, 1, 27, 15, 3,
28, 14, 14, 14, 0, 28, 29, 30,
29, 29, 29, 29, 0, 31, 32, 33,
34, 32, 32, 0, 35, 28, 36, 0,
1, 19, 0, 38, 37, 0, 31, 33,
34, 0, 39, 40, 41, 40, 40, 40,
0, 1, 2, 3, 4, 42, 42, 42,
0, 43, 44, 45, 46, 47, 47, 47,
0, 0
18, 18, 18, 18, 0, 19, 20, 21,
20, 20, 20, 0, 22, 23, 0, 24,
25, 0, 24, 25, 15, 26, 27, 14,
14, 14, 0, 29, 28, 0, 16, 17,
0, 24, 30, 26, 0, 24, 26, 27,
31, 32, 31, 31, 31, 31, 0, 33,
34, 35, 36, 34, 34, 0, 37, 27,
38, 0, 24, 30, 0, 40, 39, 0,
33, 35, 36, 0, 41, 42, 43, 42,
42, 42, 0, 1, 2, 3, 4, 44,
44, 44, 0, 45, 46, 47, 48, 49,
49, 49, 0, 50, 51, 52, 53, 54,
54, 54, 0, 0
};
static const char _yparser_trans_targs[] = {
0, 25, 1, 2, 3, 13, 4, 5,
6, 5, 7, 6, 7, 8, 9, 11,
25, 10, 9, 10, 11, 12, 14, 13,
15, 14, 15, 16, 17, 18, 21, 19,
18, 17, 20, 19, 20, 21, 22, 14,
23, 15, 23, 25, 1, 2, 3, 23
0, 26, 1, 2, 3, 24, 4, 5,
6, 5, 7, 6, 7, 8, 9, 14,
27, 16, 9, 11, 10, 12, 11, 12,
27, 13, 17, 18, 14, 15, 16, 19,
22, 20, 19, 18, 21, 20, 21, 22,
23, 11, 24, 12, 10, 26, 1, 2,
3, 10, 26, 1, 2, 3, 10
};
static const char _yparser_trans_actions[] = {
21, 1, 35, 0, 38, 32, 19, 32,
17, 11, 17, 0, 0, 0, 26, 5,
29, 9, 7, 0, 7, 0, 15, 11,
15, 0, 0, 0, 0, 26, 5, 9,
7, 9, 9, 0, 0, 7, 0, 13,
11, 13, 32, 23, 45, 3, 49, 41
21, 1, 38, 0, 41, 35, 19, 35,
17, 11, 17, 0, 0, 0, 29, 5,
32, 9, 7, 13, 11, 13, 0, 0,
1, 0, 0, 0, 7, 0, 0, 29,
5, 9, 7, 9, 9, 0, 0, 7,
0, 15, 11, 15, 35, 44, 65, 26,
70, 60, 23, 52, 3, 56, 48
};
static const char _yparser_eof_actions[] = {
0, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21,
0, 3
21, 0, 26, 3
};
......@@ -134,7 +142,7 @@ static const char _yparser_eof_actions[] = {
int _yp_start_state =
24
25
;
int _yp_parse(
......@@ -254,10 +262,16 @@ _match:
break;
case 2:
{
parser->data_len = 0;
indent = 0;
id_pos = 0;
}
break;
case 3:
{
parser->data_len = 0;
}
break;
case 4:
{
if (parser->data_len >= sizeof(parser->data) - 1) {
return KNOT_ESPACE;
......@@ -265,7 +279,7 @@ _match:
parser->data[parser->data_len++] = (*p);
}
break;
case 4:
case 5:
{
// Return if a value parsed.
parser->data[parser->data_len] = '\0';
......@@ -274,7 +288,7 @@ _match:
{p++; goto _out; }
}
break;
case 5:
case 6:
{
if (indent > 0 && parser->indent > 0 &&
indent != parser->indent) {
......@@ -286,7 +300,7 @@ _match:
parser->event = YP_ENULL;
}
break;
case 6:
case 7:
{
if (parser->key_len >= sizeof(parser->key) - 1) {
return KNOT_ESPACE;
......@@ -294,21 +308,21 @@ _match:
parser->key[parser->key_len++] = (*p);
}
break;
case 7:
case 8:
{
parser->key[parser->key_len] = '\0';
parser->indent = 0;
parser->event = YP_EKEY0;
}
break;
case 8:
case 9:
{
parser->key[parser->key_len] = '\0';
parser->indent = indent;
parser->event = YP_EKEY1;
}
break;
case 9:
case 10:
{
parser->key[parser->key_len] = '\0';
parser->indent = indent;
......@@ -316,17 +330,17 @@ _match:
parser->event = YP_EID;
}
break;
case 10:
case 11:
{
indent++;
}
break;
case 11:
case 12:
{
id_pos++;
}
break;
case 12:
case 13:
{
if (id_pos > 0 && parser->id_pos > 0 &&
id_pos != parser->id_pos) {
......@@ -335,7 +349,7 @@ _match:
parser->indent = 0;
}
break;
case 13:
case 14:
{
return KNOT_EPARSEFAIL;
}
......@@ -362,7 +376,13 @@ _again:
parser->processed = false;
}
break;
case 13:
case 2:
{
indent = 0;
id_pos = 0;
}
break;
case 14:
{
return KNOT_EPARSEFAIL;
}
......
......@@ -42,14 +42,19 @@
# Comment processing.
comment_char = '#';
comment = comment_char . (^newline_char)*;
comment = comment_char . (^newline_char)*;
# White space processing.
sep_char = ' ';
sep = sep_char+;
blank = (sep? :> comment?). newline_char;
rest = ((sep :> comment) | sep?). newline_char;
action _blank_exit {
indent = 0;
id_pos = 0;
}
blank = ( sep? . comment? ) . newline_char %_blank_exit;
rest = ((sep :> comment) | sep?) . newline_char;
# Data processing.
action _item_data_init {
......@@ -69,8 +74,8 @@
fbreak;
}
quote_char = '\"';
list_char = [\[,\]];
data_char =
list_char = [\[,\]];
data_char =
(ascii - space - cntrl - quote_char - sep_char -
comment_char - list_char
) $_item_data;
......
......@@ -23,6 +23,8 @@
#include "libknot/libknot.h"
const char *syntax_ok =
"#comment\n"
" # comment\n"
"a:\n"
"a :\n"
"a : #comment\n"
......@@ -53,7 +55,9 @@ const char *syntax_ok =
"e: \"a#b' c[d,]\"\n"
"\n"
"zone:\n"
" - domain: example.\n"
"#comment\n"
" # comment\n"
" - domain: example. # comment\n"
" master: bind\n"
" - domain: example.\n"
" master: bind\n";
......@@ -88,7 +92,7 @@ int main(int argc, char *argv[])
ret = yp_set_input_string(yp, syntax_ok, strlen(syntax_ok));
ok(ret == KNOT_EOK, "set input string");
line = 1;
line = 3;
for (int i = 0; i < 3; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse %i. key0", i);
......@@ -97,7 +101,7 @@ int main(int argc, char *argv[])
yp->line_count == line + i, "compare %i. key0", i);
}
line = 5;
line = 7;
for (int i = 0; i < 6; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse %i. key0 with value", i);
......@@ -107,7 +111,7 @@ int main(int argc, char *argv[])
"compare %i. key0 with value", i);
}
line = 12;
line = 14;
for (int i = 0; i < 6; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse %i. key1 with value", i);
......@@ -117,7 +121,7 @@ int main(int argc, char *argv[])
"compare %i. key1 with value", i);
}
line = 19;
line = 21;
for (int i = 0; i < 5; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse %i. key0 with first value", i);
......@@ -134,7 +138,7 @@ int main(int argc, char *argv[])
"compare %i. key0 with second value", i);
}
line = 25;
line = 27;
for (int i = 0; i < 2; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse %i. id", i);
......@@ -144,7 +148,7 @@ int main(int argc, char *argv[])
"compare %i. id", i);
}
line = 28;
line = 30;
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key0 with quoted value");
ok(yp->key_len == 1 && yp->key[0] == 'e' && yp->data_len == 10 &&
......@@ -152,7 +156,7 @@ int main(int argc, char *argv[])
yp->event == YP_EKEY0 && yp->line_count == line,
"compare key0 with quoted value");
line = 30;
line = 32;
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key0");
ok(yp->key_len == 4 && strcmp(yp->key, "zone") == 0 &&
......@@ -160,7 +164,7 @@ int main(int argc, char *argv[])
yp->event == YP_EKEY0 && yp->line_count == line,
"compare key0 value");
line = 31;
line = 35;
for (int i = 0; i < 2; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse %i. id", i);
......
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