Even more detailed error messages in lex.
This commit is contained in:
parent
a06d2d234d
commit
ba74302f04
@ -112,7 +112,7 @@ struct page_tree_entry_c;
|
||||
static void entry_to_string(struct page_tree_entry_c, char (*)[12]);
|
||||
struct page {
|
||||
struct char_array entry;
|
||||
struct lex_array lexx;
|
||||
struct lex_array meaning;
|
||||
};
|
||||
#define TREE_NAME page
|
||||
#define TREE_KEY union date32
|
||||
@ -168,7 +168,7 @@ static int bible_graph(/*const*/ struct page_tree *const journal) {
|
||||
for(struct page_tree_iterator p_it = page_tree_iterator(journal);
|
||||
(entry = page_tree_next(&p_it)).key; ) {
|
||||
struct page *const page = entry.value;
|
||||
for(struct lex_array_iterator l_it = lex_array_iterator(&page->lexx);
|
||||
for(struct lex_array_iterator l_it = lex_array_iterator(&page->meaning);
|
||||
(lex = lex_array_next(&l_it)); ) {
|
||||
switch(lex->symbol) {
|
||||
case BIBLE_BOOK:
|
||||
@ -305,14 +305,15 @@ int main(int argc, char **argv) {
|
||||
goto syntax;
|
||||
}
|
||||
page->entry = char_array();
|
||||
page->lexx = lex_array();
|
||||
page->meaning = lex_array();
|
||||
if(!append_file(&page->entry, fn)) goto syntax;
|
||||
for(lex_reset(page->entry.data); ; ) {
|
||||
if(!(lex = lex_array_new(&page->lexx))) goto syntax;
|
||||
if(!(lex = lex_array_new(&page->meaning))) goto syntax;
|
||||
if(!lex_next(lex)) {
|
||||
if(lex->symbol != END) { errno = EILSEQ; goto syntax; }
|
||||
break;
|
||||
}
|
||||
/* fixme: print the books */
|
||||
if(lex->symbol == BIBLE_BOOK
|
||||
|| lex->symbol == BIBLE_CHAPTER_VERSE)
|
||||
printf("[%.*s]\n", (int)(lex->s1 - lex->s0), lex->s0);
|
||||
@ -321,20 +322,23 @@ int main(int argc, char **argv) {
|
||||
syntax:
|
||||
fprintf(stderr, "On date: %d-%.2d-%.2d.\n", *y, *m, *d);
|
||||
if(!page) goto catch;
|
||||
printf("While parsing <<<\n%s>>>\n", page->entry.data);
|
||||
fprintf(stderr, "While parsing <<<\n%s>>>.\n",
|
||||
page->entry.data);
|
||||
if(!lex) goto catch;
|
||||
printf("On line %lu: %s",
|
||||
for(struct lex_array_iterator it
|
||||
= lex_array_iterator(&page->meaning);
|
||||
lex = lex_array_next(&it); ) {
|
||||
fprintf(stderr, "%lu: %s",
|
||||
(unsigned long)lex->line, lex_symbols[lex->symbol]);
|
||||
if(lex->symbol == TEXT || lex->symbol == ARG_KEYWORD
|
||||
|| lex->symbol == ARG_DATE
|
||||
|| lex->symbol == ARG_FREEFORM
|
||||
|| lex->symbol == CAPTION
|
||||
|| lex->symbol == BIBLE_TEXT) {
|
||||
if(lex->s0 && lex->s1) {
|
||||
if(lex->s0 + INT_MAX < lex->s1)
|
||||
{ intent = "line too long"; errno = EILSEQ; }
|
||||
printf(" <<%.*s>>", (int)(lex->s1 - lex->s0), lex->s0);
|
||||
intent = "line too long", errno = EILSEQ;
|
||||
else
|
||||
fprintf(stderr, " <<%.*s>>",
|
||||
(int)(lex->s1 - lex->s0), lex->s0);
|
||||
}
|
||||
fprintf(stderr, ".\n");
|
||||
}
|
||||
printf(".\n");
|
||||
goto catch;
|
||||
}
|
||||
|
||||
@ -369,7 +373,7 @@ finally:
|
||||
char z[12];
|
||||
date32_to_string(*entry.key, &z);
|
||||
/*printf("Freeing %s.\n", z);*/
|
||||
lex_array_(&page->lexx);
|
||||
lex_array_(&page->meaning);
|
||||
char_array_(&page->entry);
|
||||
}
|
||||
return success;
|
||||
|
Loading…
Reference in New Issue
Block a user