From f05f004356e91f110f5297bdb61827a7c4436d2f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 May 2021 23:32:09 -0700 Subject: parser: provide parse-errors function. * parser.c (parse_errors): New function. * parser.h (parse_errors): Declared. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated. --- parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'parser.c') diff --git a/parser.c b/parser.c index 1ab2e70b..3358d7bd 100644 --- a/parser.c +++ b/parser.c @@ -1683,6 +1683,19 @@ val parser_eof(val parser) return tnil(p->eof); } +val parse_errors(val stream) +{ + val self = lit("parse-errors"); + val errors = nil; + val parser = get_parser(stream); + if (parser) { + parser_t *p = coerce(parser_t *, cobj_handle(self, parser, parser_s)); + if (p->errors) + errors = num(p->errors); + } + return errors; +} + static val circref(val n) { uw_throwf(error_s, lit("unresolved #~s# reference in object syntax"), @@ -1876,6 +1889,7 @@ void parse_init(void) reg_fun(intern(lit("get-parser"), system_package), func_n1(get_parser)); reg_fun(intern(lit("parser-errors"), system_package), func_n1(parser_errors)); reg_fun(intern(lit("parser-eof"), system_package), func_n1(parser_eof)); + reg_fun(intern(lit("parse-errors"), user_package), func_n1(parse_errors)); reg_fun(intern(lit("repl"), system_package), func_n4(repl)); reg_mac(json_s, func_n2(me_json)); } -- cgit v1.2.3