Scan all kjv worked; had files that were not delimited.
This commit is contained in:
parent
16ce24452f
commit
ccdee8a779
|
@ -16,16 +16,15 @@
|
||||||
|
|
||||||
static int scan(union date32 date, const char *const buffer,
|
static int scan(union date32 date, const char *const buffer,
|
||||||
struct kjv *const kj) {
|
struct kjv *const kj) {
|
||||||
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3,
|
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1;
|
||||||
*s0, *s1, *t0, *t1, *line_start, *line_end;
|
|
||||||
enum kjv_book book = Revelation;
|
enum kjv_book book = Revelation;
|
||||||
uint32_t chapter = 0, verse = 0, verse_end = 0;
|
uint32_t chapter = 0, verse = 0, verse_end = 0;
|
||||||
enum YYCONDTYPE condition = yycline;
|
enum YYCONDTYPE condition = yycline;
|
||||||
size_t line = 1;
|
size_t line = 1;
|
||||||
char datestr[12] = {0};
|
char datestr[12] = {0};
|
||||||
int is_found = 0;
|
const char *why = "unexpected";
|
||||||
assert(buffer && kj);
|
assert(buffer && kj);
|
||||||
YYCURSOR = YYMARKER = yyt1 = line_start = buffer;
|
YYCURSOR = YYMARKER = yyt1 = buffer;
|
||||||
/*!re2c /**/
|
/*!re2c /**/
|
||||||
re2c:define:YYCTYPE = char;
|
re2c:define:YYCTYPE = char;
|
||||||
re2c:yyfill:enable = 0;
|
re2c:yyfill:enable = 0;
|
||||||
|
@ -39,17 +38,19 @@ static int scan(union date32 date, const char *const buffer,
|
||||||
glyph = [^] \ ("\x00" | "\n" | unix_control | ws);
|
glyph = [^] \ ("\x00" | "\n" | unix_control | ws);
|
||||||
natural = [1-9][0-9]*;
|
natural = [1-9][0-9]*;
|
||||||
engage = ws+ "--" ws+;
|
engage = ws+ "--" ws+;
|
||||||
lookat = ws* natural ":" natural [ab]?
|
/* (natural ":")? Don't use for memorizing and use for reading, I think? */
|
||||||
("-" (natural ":")? natural [ab]?)? engage;
|
/*("``"|"\"") This is not in the next book. */
|
||||||
|
lookat = ws* natural ":" natural [ab]? ("-" natural [ab]?)? engage;
|
||||||
first = ("I" | "1") " "?;
|
first = ("I" | "1") " "?;
|
||||||
second = ("II" | "2") " "?;
|
second = ("II" | "2") " "?;
|
||||||
third = ("III" | "3") " "?;
|
third = ("III" | "3") " "?;
|
||||||
*/
|
*/
|
||||||
for( ; ; ) { /*!re2c /**/
|
for( ; ; ) { /*!re2c /**/
|
||||||
<skip, book> * { goto catch; }
|
<skip> [^\n\x00] { continue; }
|
||||||
|
<skip> "\x00" { why = "no newline at end of file"; goto catch; }
|
||||||
|
<skip> "\n" => line { line++; continue; }
|
||||||
<line> "\x00" { return 1; }
|
<line> "\x00" { return 1; }
|
||||||
<line> "\n" @line_start
|
<line> "\n" { line++; continue; }
|
||||||
{ fprintf(stderr, "%4zu\n", line); line++; continue; }
|
|
||||||
<line> * :=> skip /* Guess it can't be simplified? */
|
<line> * :=> skip /* Guess it can't be simplified? */
|
||||||
<line> "Genesis" / lookat => book { book = Genesis; continue; }
|
<line> "Genesis" / lookat => book { book = Genesis; continue; }
|
||||||
<line> "Exodus" / lookat => book { book = Exodus; continue; }
|
<line> "Exodus" / lookat => book { book = Exodus; continue; }
|
||||||
|
@ -126,28 +127,35 @@ static int scan(union date32 date, const char *const buffer,
|
||||||
<line> third "John" / lookat => book { book = IIIJohn; continue; }
|
<line> third "John" / lookat => book { book = IIIJohn; continue; }
|
||||||
<line> "Jude" / lookat => book { book = Jude; continue; }
|
<line> "Jude" / lookat => book { book = Jude; continue; }
|
||||||
<line> "Revelation" / lookat => book { book = Revelation; continue; }
|
<line> "Revelation" / lookat => book { book = Revelation; continue; }
|
||||||
|
<book> * { why = "default unrecognized"; goto catch; }
|
||||||
|
/* 19:15a, just ignore the a. */
|
||||||
<book> ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? {
|
<book> ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? {
|
||||||
if(chapter || verse || verse_end
|
if(chapter || verse || verse_end)
|
||||||
|| !helper_natural(s0, s1, &chapter)
|
{ why = "reference unrecognized"; goto catch; }
|
||||||
|| !helper_natural(t0, t1, &verse)) goto catch;
|
if(!helper_natural(s0, s1, &chapter)
|
||||||
|
|| !helper_natural(t0, t1, &verse))
|
||||||
|
{ why = "reference numerical error"; goto catch; }
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
<book> "-" @s0 natural @s1 [ab]? { /* Verse range. */
|
<book> "-" @s0 natural @s1 [ab]? { /* Verse range. */
|
||||||
if(!chapter || !verse || verse_end
|
if(!chapter || !verse || verse_end)
|
||||||
|| !helper_natural(s0, s1, &verse_end)) goto catch;
|
{ why = "range unrecognized"; goto catch; }
|
||||||
|
if(!helper_natural(s0, s1, &verse_end))
|
||||||
|
{ why = "range numerical error"; goto catch; }
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
<book> engage => skip {
|
<book> engage => skip {
|
||||||
const size_t old_set_words = kj->set_words;
|
const size_t old_set_words = kj->set_words;
|
||||||
char citestr[12];
|
char citestr[12];
|
||||||
if(!chapter || !verse || verse_end && verse_end <= verse)
|
if(!chapter || !verse) { why = "missing information"; goto catch; }
|
||||||
goto catch;
|
if(verse_end && verse_end <= verse)
|
||||||
|
{ why = "interval error"; goto catch; }
|
||||||
union kjvcite cite
|
union kjvcite cite
|
||||||
= { .book = book, .chapter = chapter, .verse = verse };
|
= { .book = book, .chapter = chapter, .verse = verse };
|
||||||
if(!datestr[0]) date32_to_string(date, &datestr); /* Only once. */
|
if(!datestr[0]) date32_to_string(date, &datestr); /* Only once. */
|
||||||
kjvcite_to_string(cite, &citestr);
|
kjvcite_to_string(cite, &citestr);
|
||||||
for( ; ; verse++, cite.verse++) {
|
for( ; ; verse++, cite.verse++) {
|
||||||
if(!kjv_add(kj, cite)) goto catch;
|
if(!kjv_add(kj, cite)) { why = "add to set"; goto catch; }
|
||||||
if(!verse_end || verse_end <= verse) break;
|
if(!verse_end || verse_end <= verse) break;
|
||||||
}
|
}
|
||||||
if(verse_end) {
|
if(verse_end) {
|
||||||
|
@ -158,26 +166,15 @@ static int scan(union date32 date, const char *const buffer,
|
||||||
datestr, old_set_words, kj->set_words, citestr);
|
datestr, old_set_words, kj->set_words, citestr);
|
||||||
}
|
}
|
||||||
book = Revelation, chapter = 0, verse = 0, verse_end = 0;
|
book = Revelation, chapter = 0, verse = 0, verse_end = 0;
|
||||||
is_found = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
<skip> [^\n\x00]* @line_end "\n" @s0 => line {
|
|
||||||
const size_t size = (size_t)(line_end - line_start);
|
|
||||||
int intsize = size > 40 ? 40 : (int)size;
|
|
||||||
fprintf(stderr, "%s%4zu: %.*s%s\n", is_found ? "\033[1;35m" : "",
|
|
||||||
line, intsize, line_start, is_found ? "\033[0m" : "");
|
|
||||||
line_start = s0, is_found = 0;
|
|
||||||
line++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*/ }
|
*/ }
|
||||||
|
assert(0); /* Never gets here. */
|
||||||
catch:
|
catch:
|
||||||
if(!errno) errno = EILSEQ;
|
if(!errno) errno = EILSEQ;
|
||||||
{
|
date32_to_string(date, &datestr);
|
||||||
char a[12];
|
fprintf(stderr, "%s\n"
|
||||||
date32_to_string(date, &a);
|
"%s line %zu: %s.\n", buffer, datestr, line, why);
|
||||||
fprintf(stderr, "%s line %zu: unexpected.\n", a, line);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,6 +189,8 @@ int main(void) {
|
||||||
/*scan((union date32){.year=2000, .month=1, .day=1}, "\n\n\n"
|
/*scan((union date32){.year=2000, .month=1, .day=1}, "\n\n\n"
|
||||||
"Romans 3:23 -- ``For all have sinned, "
|
"Romans 3:23 -- ``For all have sinned, "
|
||||||
"and come short of the glory of God.''\n", &kj);*/
|
"and come short of the glory of God.''\n", &kj);*/
|
||||||
|
/* FIXME: have a column with the number so we can see how much uniqueness
|
||||||
|
makes a difference. */
|
||||||
j = journal();
|
j = journal();
|
||||||
if(!journal_is_valid(&j)) goto catch;
|
if(!journal_is_valid(&j)) goto catch;
|
||||||
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
|
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
|
||||||
|
@ -201,14 +200,14 @@ int main(void) {
|
||||||
"# date\told\tnew / %zu\n", kj.total_words);
|
"# date\told\tnew / %zu\n", kj.total_words);
|
||||||
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v)) {
|
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v)) {
|
||||||
if(!scan(k, v->text, &kj)) goto catch;
|
if(!scan(k, v->text, &kj)) goto catch;
|
||||||
if(++i > 32) break;
|
/*if(++i > 32) break;*/
|
||||||
}
|
}
|
||||||
printf("EOD\n"
|
printf("EOD\n"
|
||||||
"set monochrome\n"
|
"set monochrome\n"
|
||||||
"set xdata time\n"
|
"set xdata time\n"
|
||||||
"set timefmt \"%%Y-%%m-%%d\"\n"
|
"set timefmt \"%%Y-%%m-%%d\"\n"
|
||||||
"set xtics format \"%%Y-%%m-%%d\" rotate by -30\n"
|
"set xtics format \"%%Y-%%m-%%d\" rotate by -30\n"
|
||||||
"set ylabel \"KJV memorized\"\n"
|
"set ylabel \"words\"\n"
|
||||||
"set format y \"%%g%%%%\"\n"
|
"set format y \"%%g%%%%\"\n"
|
||||||
"unset key #set key bottom right\n"
|
"unset key #set key bottom right\n"
|
||||||
"set grid\n"
|
"set grid\n"
|
||||||
|
|
Loading…
Reference in New Issue