From 4accda5d567da64ec18ed2f78a9319694c51ba33 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 6 Jul 2022 23:07:42 -0700 Subject: [PATCH] Okay, this is really strange, s0, s1 are corrupted? --- src/interpret.c | 13 ++++++------- src/lex.h | 2 +- src/lex.re_c.c | 27 +++++++++++++++------------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/interpret.c b/src/interpret.c index 2918231..cebcfa7 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -174,14 +174,14 @@ static int bible_graph(/*const*/ struct page_tree *const journal) { case BIBLE_BOOK: if(state != CHILL && state != WORD) goto catch; if(state == WORD) printf("\n"); - fprintf(stderr, "%d-%.2d-%.2d: %.*s ", + fprintf(stderr, "%d-%.2d-%.2d: \"%.*s\", ", entry.key->year, entry.key->month, entry.key->day, (int)(lex->s1 - lex->s0), lex->s0); state = BOOK; break; case BIBLE_CHAPTER_VERSE: if(state != BOOK) goto catch; - printf("%.*s -- \"", (int)(lex->s1 - lex->s0), lex->s0); + printf("\"%.*s\", \"", (int)(lex->s1 - lex->s0), lex->s0); state = CHAPTER; break; case BIBLE_NEXT: @@ -191,8 +191,8 @@ static int bible_graph(/*const*/ struct page_tree *const journal) { case BIBLE_TEXT: if(state != WORD && state != CHAPTER && state != NEXT) goto catch; - printf("%s%.*s", state == WORD ? "*" : "", - (int)(lex->s1 - lex->s0), lex->s0); + printf("%s%.*s<%d>", state == WORD ? "*" : "", + (int)(lex->s1 - lex->s0 < 0 ? 10 : lex->s1 - lex->s0), lex->s0, (int)(lex->s1 - lex->s0)); count++; state = WORD; break; @@ -322,9 +322,8 @@ int main(int argc, char **argv) { syntax: fprintf(stderr, "On date: %d-%.2d-%.2d.\n", *y, *m, *d); if(!page) goto catch; - fprintf(stderr, "While parsing <<<\n%s>>>.\n", - page->entry.data); - if(!lex) goto catch; + if(!lex) { fprintf(stderr, "While parsing <<<\n%s>>>.\n", + page->entry.data); goto catch; } for(struct lex_array_iterator it = lex_array_iterator(&page->meaning); lex = lex_array_next(&it); ) { diff --git a/src/lex.h b/src/lex.h index 343eb88..5fc1c57 100644 --- a/src/lex.h +++ b/src/lex.h @@ -27,7 +27,7 @@ struct lex { #define X(n) n enum lex_symbol { LEX_SYMBOL } symbol; #undef X - int ws_before, new_paragraph; + /*int ws_before, new_paragraph; ???*/ const char *s0, *s1; size_t line; }; diff --git a/src/lex.re_c.c b/src/lex.re_c.c index 8cc8afc..7d79094 100644 --- a/src/lex.re_c.c +++ b/src/lex.re_c.c @@ -167,32 +167,35 @@ scan: @s0 glyph+ @s1 { x->s0 = s0, x->s1 = s1; return x->symbol = TEXT, 1; } - roman1 = "1"|"I"; - roman2 = roman1|"2"|"II"; - roman3 = roman2|"3"|"III"; bible_ref = natural ":" natural [ab]? ("-" (natural ":")? natural [ab]?)?; + glyph_minus = glyph \ [']; @s0 ("Genesis" | "Exodus" | "Leviticus" | "Numbers" | "Deuteronomy" - | "Joshua" | "Judges" | "Ruth" | roman2 " Samuel" | roman2 " Kings" - | roman2 " Chronicles" | "Ezra" | "Nehemiah" | "Esther" | "Job" + | "Joshua" | "Judges" | "Ruth" | "I"{1,2} " Samuel" | "I"{1,2} " Kings" + | "I"{1,2} " Chronicles" | "Ezra" | "Nehemiah" | "Esther" | "Job" | "Psalms" | "Proverbs" | "Ecclesiastes" | "Song of Solomon" | "Isaiah" | "Jeremiah" | "Lamentations" | "Ezekiel" | "Daniel" | "Hosea" | "Joel" | "Amos" | "Obadiah" | "Jonah" | "Micah" | "Nahum" | "Habakkuk" | "Zephaniah" | "Haggai" | "Zechariah" | "Malachi" | "Matthew" | "Mark" - | "Luke" | "John" | "Acts" | "Romans" | roman2 " Corinthians" + | "Luke" | "John" | "Acts" | "Romans" | "I"{1,2} " Corinthians" | "Galatians" | "Ephesians" | "Philippians" | "Colossians" - | roman2 " Thessalonians" | roman2 " Timothy" | "Titus" | "Philemon" - | "Hebrews" | "James" | roman2 " Peter" | roman3 " John" | "Jude" + | "I"{1,2} " Thessalonians" | "I"{1,2} " Timothy" | "Titus" | "Philemon" + | "Hebrews" | "James" | "I"{1,2} " Peter" | "I"{1,3} " John" | "Jude" | "Revelation") @s1 ws* / bible_ref ws+ "--" ws+ "``" => bible { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_BOOK, 1; } @s0 bible_ref @s1 ws+ "--" ws+ "``" { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_CHAPTER_VERSE, 1; } "``" { return x->symbol = BIBLE_NEXT, 1; } - "''" => expect_line { printf("**reset;\n"); } - /* HACK! Bible verses generally don't contain apostrophes. */ - @s0 (glyph \ ['])+ @s1 + "''" :=> text + /* fixme: This is a hack that doesn't allow apostrophes at the end of a + word, (not sure there are any in the bible.) Is ' terminated by ''; + otherwise same as glyph+ above. */ + @s0 (glyph_minus+ ("'" glyph_minus+)*) | (("'" glyph_minus+)+) @s1 { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_TEXT, 1; } - newline { x->line = ++scan.line; goto scan; } + /* Multiple verses can be present, but they end in ''. + Not strictly enforced. */ + newline / (newline | "``") { x->line = ++scan.line; goto scan; } + newline { return x->symbol = SYNTAX, 0; } @s0 keyword @s1 => expect_line { x->s0 = s0, x->s1 = s1; return x->symbol = SOURCE_RECALL, 1; }