diff --git a/src/interpret.c b/src/interpret.c index 286fdac..259dcb6 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -313,6 +313,9 @@ int main(int argc, char **argv) { if(lex->symbol != END) { errno = EILSEQ; goto syntax; } break; } + if(lex->symbol == BIBLE_BOOK + || lex->symbol == BIBLE_CHAPTER_VERSE) + printf("[%.*s]\n", (int)(lex->s1 - lex->s0), lex->s0); } continue; syntax: diff --git a/src/lex.re_c.c b/src/lex.re_c.c index 9f8c638..7779ad9 100644 --- a/src/lex.re_c.c +++ b/src/lex.re_c.c @@ -119,7 +119,7 @@ static void expect_pop(void) { } int lex_next(struct lex *const x) { - /*!re2c + /*!re2c /**/ re2c:flags:tags = 1; re2c:define:YYCURSOR = scan.cursor; re2c:define:YYMARKER = scan.marker; @@ -130,7 +130,7 @@ int lex_next(struct lex *const x) { re2c:define:YYSETCONDITION = 'scan.condition = @@;'; re2c:define:YYSETCONDITION:naked = 1; sentinel = "\x00"; - illegal = [\x01-\x08\x0a-\x1f\x7f]; // unix-style control characters + illegal = [\x01-\x08\x0a-\x1f\x7f]; /* unix-style control characters */ newline = "\n"; ws = [ \t]; glyph = [^] \ (sentinel | illegal | newline | ws); @@ -146,7 +146,7 @@ int lex_next(struct lex *const x) { x->line = scan.line; x->s0 = x->s1 = 0; scan: - /*!re2c + /*!re2c /**/ <*> illegal { return x->symbol = ILLEGAL, 0; } <*> * { return x->symbol = SYNTAX, 0; } <*> sentinel @@ -159,9 +159,10 @@ scan: "--" :=> source "->" :=> location "[" :=> edict - ws* / glyph :=> text + /* Just plain text. */ + ws* / glyph :=> text /* match-empty-string: text takes care of it. */ - newline => line { x->line = ++scan.line; 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; } @@ -169,6 +170,7 @@ scan: roman1 = "1"|"I"; roman2 = roman1|"2"|"II"; roman3 = roman2|"3"|"III"; + bible_ref = natural ":" natural [ab]? ("-" (natural ":")? natural [ab]?)?; @s0 ("Genesis" | "Exodus" | "Leviticus" | "Numbers" | "Deuteronomy" | "Joshua" | "Judges" | "Ruth" | roman2 " Samuel" | roman2 " Kings" @@ -181,14 +183,16 @@ scan: | "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] + | "Revelation") @s1 ws* / bible_ref ws+ "--" ws+ "``" => bible { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_BOOK, 1; } - @s0 natural ":" natural @s1 ws* "--" ws* "``" / [A-Z] + @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; } - @s0 glyph+ @s1 + "''" => expect_line { printf("**reset;\n"); } + /* HACK! Bible verses generally don't contain apostrophes. */ + @s0 (glyph \ ['])+ @s1 { x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_TEXT, 1; } - "''" :=> expect_line + newline { x->line = ++scan.line; goto scan; } @s0 keyword @s1 => expect_line { x->s0 = s0, x->s1 = s1; return x->symbol = SOURCE_RECALL, 1; }