Hopefully we see some errors if the syntax.
This commit is contained in:
parent
8b0b851755
commit
e30293e66e
@ -6,6 +6,7 @@
|
||||
#include "../src/journal.h"
|
||||
#include "../src/kjv.h"
|
||||
#include "../src/helper.h"
|
||||
#include <inttypes.h> /* C99 */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
@ -15,14 +16,16 @@
|
||||
|
||||
static int scan(union date32 date, const char *const buffer,
|
||||
struct kjv *const kj) {
|
||||
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1;
|
||||
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3,
|
||||
*s0, *s1, *t0, *t1, *line_start, *line_end;
|
||||
enum kjv_book book = Revelation;
|
||||
uint32_t chapter, verse;
|
||||
uint32_t chapter = 0, verse = 0, verse_end = 0;
|
||||
enum YYCONDTYPE condition = yycline;
|
||||
size_t line = 1;
|
||||
char datestr[12] = {0};
|
||||
int is_found = 0;
|
||||
assert(buffer && kj);
|
||||
YYCURSOR = YYMARKER = yyt1 = buffer;
|
||||
YYCURSOR = YYMARKER = yyt1 = line_start = buffer;
|
||||
/*!re2c /**/
|
||||
re2c:define:YYCTYPE = char;
|
||||
re2c:yyfill:enable = 0;
|
||||
@ -35,14 +38,19 @@ static int scan(union date32 date, const char *const buffer,
|
||||
ws = [ \t];
|
||||
glyph = [^] \ ("\x00" | "\n" | unix_control | ws);
|
||||
natural = [1-9][0-9]*;
|
||||
engage = ws+ "--" ws+;
|
||||
lookat = ws* natural ":" natural [ab]?
|
||||
("-" (natural ":")? natural [ab]?)? ws* "--";
|
||||
("-" (natural ":")? natural [ab]?)? engage;
|
||||
*/
|
||||
for( ; ; ) { /*!re2c /**/
|
||||
<skip, book> * { goto catch; }
|
||||
<line> "\x00" { return 1; }
|
||||
<line> "\n" { line++; continue; }
|
||||
<line> * :=> skip
|
||||
<line> "\n" @line_start {
|
||||
fprintf(stderr, "\033[0;37m" "%4zu" "\033[0m" "\n", line);
|
||||
line++;
|
||||
continue;
|
||||
}
|
||||
<line> * :=> skip /* Guess it can't be simplified? */
|
||||
<line> "Genesis" / lookat => book { book = Genesis; continue; }
|
||||
<line> "Exodus" / lookat => book { book = Exodus; continue; }
|
||||
/*| "Leviticus" | "Numbers" | "Deuteronomy"
|
||||
@ -60,22 +68,50 @@ static int scan(union date32 date, const char *const buffer,
|
||||
| "Hebrews" | "James" | "I"{1,2} " Peter" | "I"{1,3} " John" | "Jude"
|
||||
| "Revelation") @s1 ws* / bible_ref ws+ "--" ws+ "``" */
|
||||
//<line> [^\n\x00]* newline { printf("throw\n"); line++; continue; }
|
||||
<book> ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? => skip {
|
||||
if(!helper_natural(s0, s1, &chapter)
|
||||
<book> ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? {
|
||||
if(chapter || verse || verse_end
|
||||
|| !helper_natural(s0, s1, &chapter)
|
||||
|| !helper_natural(t0, t1, &verse)) goto catch;
|
||||
union kjvcite cite
|
||||
= { .book = book, .chapter = chapter, .verse = verse };
|
||||
const size_t old_set_words = kj->set_words;
|
||||
char citestr[12];
|
||||
if(!kjv_add(kj, cite)) goto catch;
|
||||
if(!*datestr) date32_to_string(date, &datestr);
|
||||
kjvcite_to_string(cite, &citestr);
|
||||
printf("%s\t%zu\t%zu\t# %s\n",
|
||||
datestr, old_set_words, kj->set_words, citestr);
|
||||
continue;
|
||||
}
|
||||
<skip> [^\n\x00]* "\n" => line { line++; continue; }
|
||||
//=> bible { x->s0 = s0, x->s1 = s1; return x->symbol = KJV_BOOK, 1; }
|
||||
<book> "-" @s0 natural @s1 [ab]? { /* Verse range. */
|
||||
if(!chapter || !verse || verse_end
|
||||
|| !helper_natural(s0, s1, &verse_end)) goto catch;
|
||||
continue;
|
||||
}
|
||||
<book> engage => skip {
|
||||
const size_t old_set_words = kj->set_words;
|
||||
char citestr[12];
|
||||
if(!chapter || !verse || verse_end && verse_end <= verse)
|
||||
goto catch;
|
||||
union kjvcite cite
|
||||
= { .book = book, .chapter = chapter, .verse = verse };
|
||||
if(!datestr[0]) date32_to_string(date, &datestr); /* Only once. */
|
||||
kjvcite_to_string(cite, &citestr);
|
||||
for( ; ; verse++, cite.verse++) {
|
||||
if(!kjv_add(kj, cite)) goto catch;
|
||||
if(!verse_end || verse_end <= verse) break;
|
||||
}
|
||||
if(verse_end) {
|
||||
printf("%s\t%zu\t%zu\t# %s-%" PRIu32 "\n",
|
||||
datestr, old_set_words, kj->set_words, citestr, verse_end);
|
||||
} else {
|
||||
printf("%s\t%zu\t%zu\t# %s\n",
|
||||
datestr, old_set_words, kj->set_words, citestr);
|
||||
}
|
||||
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;
|
||||
}
|
||||
*/ }
|
||||
catch:
|
||||
if(!errno) errno = EILSEQ;
|
||||
@ -101,11 +137,26 @@ int main(void) {
|
||||
j = journal();
|
||||
if(!journal_is_valid(&j)) goto catch;
|
||||
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
|
||||
printf("# date\told\tnew / %zu\n", kj.total_words);
|
||||
printf("set term postscript eps enhanced\n"
|
||||
"set output \"kjv.eps\"\n"
|
||||
"$Data <<EOD\n"
|
||||
"# date\told\tnew / %zu\n", kj.total_words);
|
||||
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v)) {
|
||||
if(!scan(k, v->text, &kj)) goto catch;
|
||||
if(++i > 32) break;
|
||||
}
|
||||
printf("EOD\n"
|
||||
"set monochrome\n"
|
||||
"set xdata time\n"
|
||||
"set timefmt \"%%Y-%%m-%%d\"\n"
|
||||
"set xtics format \"%%Y-%%m-%%d\" rotate by -30\n"
|
||||
"set ylabel \"KJV memorized\"\n"
|
||||
"set format y \"%%g%%%%\"\n"
|
||||
"unset key #set key bottom right\n"
|
||||
"set grid\n"
|
||||
"unset border\n"
|
||||
"plot $Data using 1:($3-$2)*100/%zu smooth cumulative "
|
||||
"with steps lw 2\n", kj.total_words);
|
||||
goto finally;
|
||||
catch:
|
||||
success = EXIT_FAILURE;
|
||||
|
Loading…
Reference in New Issue
Block a user