Maybe I should break it up?
This commit is contained in:
parent
3f81d8ea51
commit
91dfdf5aa3
@ -171,7 +171,7 @@ static int bible_graph(/*const*/ struct page_tree *const journal) {
|
||||
for(struct lex_array_iterator l_it = lex_array_iterator(&page->meaning);
|
||||
(lex = lex_array_next(&l_it)); ) {
|
||||
switch(lex->symbol) {
|
||||
case BIBLE_BOOK:
|
||||
case KJV_BOOK:
|
||||
if(state != CHILL && state != WORD) goto catch;
|
||||
if(state == WORD) printf("\n");
|
||||
fprintf(stderr, "%d-%.2d-%.2d: \"%.*s\", ",
|
||||
@ -179,16 +179,16 @@ static int bible_graph(/*const*/ struct page_tree *const journal) {
|
||||
(int)(lex->s1 - lex->s0), lex->s0);
|
||||
state = BOOK;
|
||||
break;
|
||||
case BIBLE_CHAPTER_VERSE:
|
||||
case KJV_CHAPTER_VERSE:
|
||||
if(state != BOOK) goto catch;
|
||||
printf("\"%.*s\", \"", (int)(lex->s1 - lex->s0), lex->s0);
|
||||
state = CHAPTER;
|
||||
break;
|
||||
case BIBLE_NEXT:
|
||||
case KJV_NEXT:
|
||||
if(state != WORD) goto catch;
|
||||
printf("\"\n");
|
||||
break;
|
||||
case BIBLE_TEXT:
|
||||
case KJV_TEXT:
|
||||
if(state != WORD && state != CHAPTER && state != NEXT)
|
||||
goto catch;
|
||||
printf("%s%.*s<%d>", state == WORD ? "*" : "",
|
||||
@ -342,13 +342,13 @@ int main(int argc, char **argv) {
|
||||
first ? "" : " ", (int)(lex->s1 - lex->s0), lex->s0);
|
||||
first = 0; break;
|
||||
case PARAGRAPH: printf("\n" C_RESET); break;
|
||||
case BIBLE_BOOK: printf(C_YELLOW "%.*s",
|
||||
case KJV_BOOK: printf(C_YELLOW "%.*s",
|
||||
(int)(lex->s1 - lex->s0), lex->s0); break;
|
||||
case BIBLE_CHAPTER_VERSE: printf(" ch. %.*s",
|
||||
case KJV_CHAPTER_VERSE: printf(" ch. %.*s",
|
||||
(int)(lex->s1 - lex->s0), lex->s0); break;
|
||||
case BIBLE_TEXT: printf("%s%.*s",
|
||||
case KJV_TEXT: printf("%s%.*s",
|
||||
(int)(lex->s1 - lex->s0), lex->s0); break;
|
||||
case BIBLE_NEXT: printf("(next)\n"); break;
|
||||
case KJV_NEXT: printf("(next)\n"); break;
|
||||
default:
|
||||
fprintf(stderr, "%lu: %s",
|
||||
(unsigned long)lex->line, lex_symbols[lex->symbol]);
|
||||
|
56
src/lex.h
56
src/lex.h
@ -4,37 +4,59 @@ int lex_looks_like_year(const char *, int *);
|
||||
int lex_looks_like_month(const char *);
|
||||
int lex_looks_like_day(const char *);
|
||||
|
||||
#define LEX_SYMBOL \
|
||||
#define FOR_SYMBOL(X) \
|
||||
\
|
||||
/* Results. */ \
|
||||
X(END), X(SYNTAX), X(ILLEGAL), X(NOT_FOUND), \
|
||||
X(END, 0), \
|
||||
X(SYNTAX, 0), \
|
||||
X(ILLEGAL, 0), \
|
||||
X(NOT_FOUND, 0), \
|
||||
\
|
||||
X(ORDERED_LIST_ITEM), X(LIST_ITEM), X(COMPLETE), X(CANCELLED), X(HEADING), \
|
||||
X(ORDERED_LIST_ITEM, &no_vt), \
|
||||
X(LIST_ITEM, 0), \
|
||||
X(COMPLETE, 0), \
|
||||
X(CANCELLED, 0), \
|
||||
X(HEADING, 0), \
|
||||
/* Text. */ \
|
||||
X(PARAGRAPH), X(TEXT), X(CAPTION), \
|
||||
X(PARAGRAPH, 0), \
|
||||
X(TEXT, &word_vt), \
|
||||
/*This is lazy.*/X(CAPTION, &word_vt), \
|
||||
\
|
||||
/* Edicts. */ \
|
||||
X(SOURCE), X(DEFAULT), X(SOURCE_RECALL), \
|
||||
X(LOCATION), X(LOCATION_SAVE), X(LOCATION_RECALL), \
|
||||
X(SIGNIFICANT), X(SIGNIFICANT_RECALL), X(EDITORIALIZING), \
|
||||
X(SOURCE, &word_vt), \
|
||||
X(DEFAULT, 0), \
|
||||
X(SOURCE_RECALL, &word_vt), \
|
||||
X(LOCATION, 0), \
|
||||
X(LOCATION_SAVE, 0), \
|
||||
X(LOCATION_RECALL, 0), \
|
||||
X(SIGNIFICANT, 0), \
|
||||
X(SIGNIFICANT_RECALL, 0), \
|
||||
X(EDITORIALIZING, 0), \
|
||||
\
|
||||
/* Arguments. */ \
|
||||
X(ARG_KEYWORD), X(ARG_DATE), X(ARG_NATURAL), X(ARG_RESTRICT_TEXT), \
|
||||
X(ARG_END_TEXT), \
|
||||
X(ARG_KEYWORD, 0), \
|
||||
X(ARG_DATE, &date_vt), \
|
||||
X(ARG_NATURAL, &no_vt), \
|
||||
X(ARG_RESTRICT_TEXT, &word_vt), \
|
||||
X(ARG_END_TEXT, &word_vt), \
|
||||
\
|
||||
/* Bible */ \
|
||||
X(BIBLE_BOOK), X(BIBLE_CHAPTER_VERSE), X(BIBLE_TEXT), X(BIBLE_NEXT)
|
||||
X(KJV_BOOK, &kjv_book_vt), \
|
||||
X(KJV_CHAPTER_VERSE, &word_vt), \
|
||||
X(KJV_TEXT, &word_vt), \
|
||||
X(KJV_NEXT, 0)
|
||||
|
||||
|
||||
|
||||
struct lex {
|
||||
#define X(n) n
|
||||
enum lex_symbol { LEX_SYMBOL } symbol;
|
||||
#undef X
|
||||
/*int ws_before, new_paragraph; ???*/
|
||||
const char *s0, *s1;
|
||||
size_t line;
|
||||
#define ARG1(n, m) n
|
||||
enum lex_symbol { FOR_SYMBOL(ARG1) } symbol;
|
||||
#undef ARG1
|
||||
const char *s0, *s1;
|
||||
};
|
||||
#define X(n) #n
|
||||
static const char *const lex_symbols[] = { LEX_SYMBOL };
|
||||
#define STR1(n, m) #n
|
||||
static const char *const lex_symbols[] = { FOR_SYMBOL(STR1) };
|
||||
#undef X
|
||||
|
||||
void lex_reset(const char *const buffer);
|
||||
|
@ -192,16 +192,16 @@ scan:
|
||||
| "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; }
|
||||
=> bible { x->s0 = s0, x->s1 = s1; return x->symbol = KJV_BOOK, 1; }
|
||||
<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; }
|
||||
{ x->s0 = s0, x->s1 = s1; return x->symbol = KJV_CHAPTER_VERSE, 1; }
|
||||
<bible> "``" { return x->symbol = KJV_NEXT, 1; }
|
||||
<bible> "''" :=> 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. */
|
||||
<bible> @s0 ("'"? glyph_minus+ ("'" glyph_minus+)*) @s1
|
||||
{ x->s0 = s0, x->s1 = s1; return x->symbol = BIBLE_TEXT, 1; }
|
||||
{ x->s0 = s0, x->s1 = s1; return x->symbol = KJV_TEXT, 1; }
|
||||
/* Multiple verses can be present, but they end in ''.
|
||||
Not strictly enforced. */
|
||||
<bible> newline / (newline | "``") { x->line = ++scan.line; goto scan; }
|
||||
|
Loading…
Reference in New Issue
Block a user