diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-05-03 23:36:43 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-05-03 23:36:43 -0400 |
commit | b20ccd6bafaa12acacff8b75a666d3ac51eda371 (patch) | |
tree | 855307cd2082be730d074dcd24aff4951133ae48 | |
parent | b11937fc35264180f15b31fedbab56724d2fadfa (diff) |
better unrecognized expression error message
-rw-r--r-- | parse.c | 7 | ||||
-rw-r--r-- | test.toc | 41 |
2 files changed, 8 insertions, 40 deletions
@@ -2114,8 +2114,11 @@ static Status parse_expr(Parser *p, Expression *e, Token *end) { return false; goto success; } - - tokr_err(t, "Unrecognized expression."); + Location where; + where.file = p->file; + where.start = (U32)(t->token - t->tokens); + where.end = (U32)(end - t->tokens); + err_print(where, "Unrecognized expression."); return false; } } @@ -1,39 +1,4 @@ -// BUGBUGBUG: puti(puti(x)) +main ::=fn(){ -printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int; - - -// NOTE: this doesn't work (e.g. "%%%") -tprintf_valid ::= fn(fmt :: []char, nargs: int) bool { - if fmt[fmt.len-1] != '\0' { - return false; - } - count := 0; - for x, i := fmt { - if x == '%' { - if i == fmt.len-1 { - count += 1; - } elif fmt[i+1] != '%' { - count += 1; - } else { - count -= 1; - } - } - } - count == nargs -}; - - -tprintf ::= fn(fmt :: []char, args: ..) { - #if !tprintf_valid(fmt, args.len) { - #error "Invalid printf format"; - } - f := fmt; - printf(&f[0], args); -}; - -main ::= fn() { - tprintf("%d %d%%\n\0", 3 as #C int, 4 as #C int); - tprintf("%d %d %d%%\n\0", 3 as #C int, 4 as #C int, 5 as #C int); - tprintf("Hello!\n\0"); -}; + yeoop #C 3; +} |