diff options
-rw-r--r-- | parser.c | 14 | ||||
-rw-r--r-- | parser.h | 1 | ||||
-rw-r--r-- | share/txr/stdlib/doc-syms.tl | 1 | ||||
-rw-r--r-- | txr.1 | 42 |
4 files changed, 58 insertions, 0 deletions
@@ -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)); } @@ -143,4 +143,5 @@ val ensure_parser(val stream, val name); val parser_set_lineno(val self, val stream, val lineno); val parser_errors(val parser); val parser_eof(val parser); +val parse_errors(val stream); void parse_init(void); diff --git a/share/txr/stdlib/doc-syms.tl b/share/txr/stdlib/doc-syms.tl index e92e8a4e..3f77d0d7 100644 --- a/share/txr/stdlib/doc-syms.tl +++ b/share/txr/stdlib/doc-syms.tl @@ -1330,6 +1330,7 @@ ("parenb" "N-01B1B5DF") ("parmrk" "N-02391683") ("parodd" "N-01B1B5DF") + ("parse-errors" "N-00F843D4") ("partition" "N-0142889E") ("partition*" "N-03951D7A") ("partition-by" "N-000167DF") @@ -56632,6 +56632,48 @@ it may be useful to set true in order to obtain better diagnostics. However, source location recording incurs a performance and storage penalty. +.coNP Function @ parse-errors +.synb +.mets (parse-errors << stream ) +.syne +.desc +The +.code parse-errors +function retrieves information, from a +.metn stream , +pertaining to the status of the most recent parsing operation performed +on that stream: namely, a previous call to +.codn read , +.code iread +or +.codn get-json . + +If the +.meta stream +object has not been used for parsing, or else the most recent +parsing operation did not encounter errors, then +.code parse-errors +returns +.codn nil . + +If the most recent parsing operation on +.meta stream +encountered errors, then +.code parse-errors +function returns a positive integer value indicating the error count. +Otherwise it returns +.codn nil . + +If a parse error operation encounters a syntax error before obtaining any token +from the stream, then the error count is zero and +.code parse-errors +returns +.codn nil . +Consequently, +.code parse-errors +may be used after a failed parse operation to distinguish a true +syntax error from an end-of-stream condition. + .coNP Function @ record-adapter .synb .mets (record-adapter < regex >> [ stream <> [ include-match ]]) |