working on polymorphic <<>>

This commit is contained in:
2023-05-05 22:15:15 -07:00
parent 72385093bd
commit 9c2edcb9eb
2 changed files with 28 additions and 7 deletions

View File

@@ -96,6 +96,7 @@ struct scan {
struct pairmap_table map;
struct linemap_tree dates;
} scores;
struct source_array documents;
struct glider_tree gliders;
struct flight_tree flights;
struct kjv_tree kjvs;

View File

@@ -130,17 +130,22 @@ static int scan_day(struct scan *const scan, union date32 date,
ws = [ \t];
glyph = [^\x00-\x20\x7f] | [\x80-\xff]; // [^\x00\n\t ] + all weird
semitext = glyph \ ";";
labelchar = glyph \ [;]; // perhaps?
label_mbra = labelchar \ [[\]];
label_mpar = labelchar \ [()];
label_in = label_mbra+ (" " label_mbra+)*; // "[label in; ...]"
label_out = (label_mpar labelchar*) (" " labelchar+)*; // "() label out"
keyword = [A-Za-z0-9][A-Za-z0-9_-]*;
natural = [1-9][0-9]*;
zero_natural = [0-9]+;
decimal = "-"? zero_natural ("." zero_natural?)?;
uint = [0-9]+;
keyword = [A-Za-z0-9][A-Za-z0-9_-]*;
labelchar = glyph \ [;]; // perhaps?
labelchar0 = labelchar \ [()]; // because conflicts
label = (labelchar0 labelchar*) (" " labelchar+)*;
date = natural "-" [0-1][0-9] "-" [0-3][0-9];
minutes = [0-5][0-9];
airport = [A-Z0-9]{4,4};
kjvlookat = ws* natural ":" natural [ab]? ("-" natural [ab]?)? ws+ "--" ws+;
first = ("I" | "1") " "?;
second = ("II" | "2") " "?;
@@ -158,10 +163,26 @@ static int scan_day(struct scan *const scan, union date32 date,
<line> "::" / [^:] :=> score
<line> "[glider]" :=> glider_type
<line> "[flight]" :=> flight_type
<line> "[" :=> bracket
<bracket> * { fail = "bracket unrecognized"; goto catch; }
<bracket> "document: " :=> document_title
// "<<\ntext\n>>" or "text\n" used by several.
<text> * { fail = "text"; goto catch; }
<text> ws+ :=> text
<text> glyph+ {
}
<document_title> * { fail = "document title"; goto catch; }
<document_title> @s0 label_in @s1 "]" => text {
const struct pair label = pair(s0, s1);
fprintf(stderr, "document: <<%.*s>>?\n", (int)(s1 - s0), s0);
continue;
}
<place> * { fail = "place unrecognized"; goto catch; }
<place> @s0 label @s1 / "\n" => skip { also_place: {
<place> @s0 label_out @s1 / "\n" => skip { also_place: {
const struct pair keyword = pair(s0, s1);
const union line64 key = { { (uint32_t)line, date } };
size_t i, *pi;
@@ -179,7 +200,7 @@ static int scan_day(struct scan *const scan, union date32 date,
datestr, line, (int)(s1 - s0), s0);
} continue; }
<place> "(" @t0 decimal "," @t1 decimal ")"
ws+ @s0 label @s1 / "\n" => skip {
ws+ @s0 label_out @s1 / "\n" => skip {
const struct pair keyword = pair(s0, s1);
const double x = strtod(t0, 0), y = strtod(t1, 0); /* Safe? */
size_t *idx;
@@ -216,7 +237,6 @@ static int scan_day(struct scan *const scan, union date32 date,
}
<source> * { fail = "source unrecognized"; goto catch; }
<source> @s0 keyword @s1 / "\n" => skip { also_source: {
const struct pair keyword = pair(s0, s1);