Maybe new strategy?

This commit is contained in:
Neil 2022-07-06 14:59:56 -07:00
parent 78cdeafc8b
commit 82d2484f70
2 changed files with 16 additions and 9 deletions

View File

@ -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:

View File

@ -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:
<line> "--" :=> source
<line> "->" :=> location
<line> "[" :=> edict
<line> ws* / glyph :=> text
/* Just plain text. */
<line> ws* / glyph :=> text /* match-empty-string: text takes care of it. */
<text, bible> newline => line { x->line = ++scan.line; goto scan; }
<text> newline => line { x->line = ++scan.line; goto scan; }
<text, bible> ws+ { goto scan; }
<text> @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]?)?;
<line> @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; }
<bible> @s0 natural ":" natural @s1 ws* "--" ws* "``" / [A-Z]
<bible> @s0 bible_ref @s1 ws+ "--" ws+ "``"
{ x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_CHAPTER_VERSE, 1; }
<bible> "``" { return x->symbol = BIBLE_NEXT, 1; }
<bible> @s0 glyph+ @s1
<bible> "''" => expect_line { printf("**reset;\n"); }
/* HACK! Bible verses generally don't contain apostrophes. */
<bible> @s0 (glyph \ ['])+ @s1
{ x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_TEXT, 1; }
<bible> "''" :=> expect_line
<bible> newline { x->line = ++scan.line; goto scan; }
<source> @s0 keyword @s1 => expect_line
{ x->s0 = s0, x->s1 = s1; return x->symbol = SOURCE_RECALL, 1; }