From debffaf7a6542fe31abbb94977bce7d519589d00 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 5 Jul 2022 19:21:56 -0700 Subject: [PATCH] Fixed no-break. --- src/interpret.c | 9 +++++---- src/lex.h | 5 ++++- src/lex.re_c.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/interpret.c b/src/interpret.c index 420b1e1..bcd6320 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -84,14 +84,15 @@ static union date32 date_to_32(const int y, const int m, const int d) { /* Leap year calculations only work at y>=1 and Gregorian Calendar and max 23 bits. */ if(y < 1582 || y > 8388607 || m < 1 || m > 12 || d < 1 || d > 31) - return d32; + goto no; switch(m) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: break; - case 4: case 6: case 9: case 11: if(d > 30) return d32; break; - case 2: if(d > 28 + leap(y)) return d32; + case 4: case 6: case 9: case 11: if(d > 30) goto no; break; + case 2: if(d > 28 + leap(y)) goto no; break; default: assert(0); break; } d32.year = (unsigned)y, d32.month = (unsigned)m, d32.day = (unsigned)d; +no: return d32; } @@ -268,7 +269,7 @@ finally: struct page *const page = entry.value; char z[12]; date32_to_string(*entry.key, &z); - printf("Page %s gone.\n", z); + printf("Freeing %s.\n", z); lex_array_(&page->lexx); char_array_(&page->entry); } diff --git a/src/lex.h b/src/lex.h index 1e9393f..c2e3b35 100644 --- a/src/lex.h +++ b/src/lex.h @@ -18,7 +18,10 @@ int lex_looks_like_day(const char *); X(SIGNIFICANT), X(SIGNIFICANT_RECALL), \ \ /* Arguments. */ \ - X(ARG_KEYWORD), X(ARG_DATE), X(ARG_NATURAL), X(ARG_FREEFORM) + X(ARG_KEYWORD), X(ARG_DATE), X(ARG_NATURAL), X(ARG_FREEFORM), \ + \ + /* Bible */ \ + X(BIBLE_BOOK), X(BIBLE_CHAPTER_VERSE), X(BIBLE_TEXT), X(BIBLE_NEXT) struct lex { #define X(n) n diff --git a/src/lex.re_c.c b/src/lex.re_c.c index 8bda3dd..aa363da 100644 --- a/src/lex.re_c.c +++ b/src/lex.re_c.c @@ -159,14 +159,38 @@ scan: "--" :=> source "->" :=> location "[" :=> edict - "" / glyph :=> text + ws* / glyph :=> text - newline => line { x->line = ++scan.line; goto scan; } - ws+ { goto scan; } + newline => line { x->line = ++scan.line; goto scan; } + ws+ { goto scan; } @s0 glyph+ @s1 { x->s0 = s0, x->s1 = s1; return x->symbol = TEXT, 1; } - @s0 keyword @s1 => expect_line + roman1 = "1"|"I"; + roman2 = roman1|"2"|"II"; + roman3 = roman2|"3"|"III"; + + @s0 ("Genesis" | "Exodus" | "Leviticus" | "Numbers" | "Deuteronomy" + | "Joshua" | "Judges" | "Ruth" | roman2 " Samuel" | roman2 " Kings" + | roman2 " 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" + | "Galatians" | "Ephesians" | "Philippians" | "Colossians" + | roman2 " Thessalonians" | roman2 " Timothy" | "Titus" | "Philemon" + | "Hebrews" | "James" | roman2 " Peter" | roman3 " John" | "Jude" + | "Revelation") @s1 ws* / natural ":" natural ws* "--" ws* "``" [A-Z] + => bible { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_BOOK, 1; } + @s0 natural ":" natural @s1 ws* "--" ws* "``" / [A-Z] + { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_CHAPTER_VERSE, 1; } + "``" { return x->symbol = BIBLE_NEXT, 1; } + @s0 glyph+ @s1 + { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_TEXT, 1; } + "''" :=> expect_line + + @s0 keyword @s1 => expect_line { x->s0 = s0, x->s1 = s1; return x->symbol = SOURCE_RECALL, 1; } "" / "(" :=> map