Use pretty-print to display error tree.

* gash/peg.scm (parse): Use pretty-print to display error tree.
  (parse-): Likewise.
This commit is contained in:
Jan Nieuwenhuizen 2018-06-30 06:35:36 +02:00
parent fbe9747d00
commit a14c7c7360
1 changed files with 8 additions and 5 deletions

View File

@ -1,8 +1,9 @@
(define-module (gash peg)
:use-module (ice-9 peg)
:use-module (ice-9 peg codegen)
#:use-module (ice-9 pretty-print)
#:use-module (ice-9 peg)
#:use-module (ice-9 peg codegen)
:export (parse peg-trace?))
#:export (parse peg-trace?))
(define (error? x)
(let loop ((x x))
@ -15,7 +16,8 @@
(define (parse input)
(let ((tree (parse- input)))
(cond ((error? tree)
(format (current-error-port) "error: ~a\n" tree)
(format (current-error-port) "error:\n")
(pretty-print tree (current-error-port))
#f)
(#t
tree))))
@ -104,7 +106,8 @@
tree
(if match
(begin
(format (current-error-port) "parse error: at offset: ~a\n~s\n" end tree)
(format (current-error-port) "parse error: at offset: ~a\n" end)
(pretty-print tree (current-error-port))
#f)
(begin
(format (current-error-port) "parse error: no match\n")