git.haldean.org expel / 2b381ac
show resolution failures in-place Haldean Brown 6 years ago
5 changed file(s) with 38 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
6767
6868 parse_err = xl_parse(&ast, "(stdin)", &sstdin);
6969 if (parse_err == OK)
70 parse_err = xl_resolve(ast, "(stdin)", &rctx);
70 parse_err = xl_resolve(ast, "(stdin)", &sstdin, &rctx);
7171 if (argc > 1 && strcmp(argv[1], "emit-ast") == 0)
7272 err = xl_ast_print(ast);
7373 c(parse_err);
100100 xl_resolve(
101101 struct xl_ast *ast,
102102 char *source_name,
103 struct xl_stream *stream,
103104 struct xl_resolve_context *ctx);
104105
105106 void
9797 if (err != OK)
9898 return err;
9999
100 err = xl_resolve(ast, source_name, &ctx);
100 err = xl_resolve(ast, source_name, in_stream, &ctx);
101101 if (err != OK)
102102 goto free_ast;
103103
3333 xl_vector_free(&ctx->allocs);
3434 }
3535
36 void
36 static void
3737 _print_line_in_stream(struct xl_stream *stream, size_t line)
3838 {
3939 #define lis_buf_len 512
5151 printf("%s\n", buf);
5252 }
5353
54 void
54 static void
5555 _show_char_in_line(size_t column)
5656 {
5757 size_t i;
2525 #include "expel/env.h"
2626 #include "expel/natives.h"
2727 #include "expel/resolve.h"
28 #include "expel/streamutil.h"
2829 #include "expel/util.h"
2930
3031 no_ignore xl_error
514515 return OK;
515516 }
516517
518 static void
519 _print_line_in_stream(struct xl_stream *stream, size_t line)
520 {
521 #define lis_buf_len 512
522 char buf[lis_buf_len];
523 char *explain;
524 xl_error err;
525
526 err = xl_streamutil_get_line(buf, stream, line, lis_buf_len);
527 if (err != OK)
528 {
529 explain = xl_error_explain(err);
530 printf("couldn't print line in file: %s\n", explain);
531 return;
532 }
533 printf("%s\n", buf);
534 }
535
536 static void
537 _show_char_in_line(size_t column)
538 {
539 size_t i;
540 for (i = 0; i < column - 1; i++)
541 putchar(' ');
542 printf("^\n");
543 }
544
517545 no_ignore xl_error
518546 xl_resolve(
519547 struct xl_ast *ast,
520548 char *source_name,
549 struct xl_stream *stream,
521550 struct xl_resolve_context *ctx)
522551 {
523552 struct xl_resolve_error *resolv_err;
563592 resolv_err->loc.line_start,
564593 resolv_err->loc.col_start,
565594 resolv_err->name);
595 _print_line_in_stream(
596 stream,
597 resolv_err->loc.line_start - 1);
598 _show_char_in_line(resolv_err->loc.col_start);
566599 }
567600 }
568601 return xl_raise(ERR_BAD_VALUE, "couldn't resolve some names");