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