From 72397d937eaf6e803b2d83bf136a22ef3666c2ca Mon Sep 17 00:00:00 2001 From: Rutger van Beusekom Date: Tue, 20 Sep 2016 13:04:31 +0200 Subject: [PATCH] refactor for error handling --- sh/peg.scm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sh/peg.scm b/sh/peg.scm index 147611b..fe316dc 100644 --- a/sh/peg.scm +++ b/sh/peg.scm @@ -83,11 +83,12 @@ ws < sp / nl ") -(let ((match (match-pattern script input))) +(let* ((match (match-pattern script input)) + (tree (peg:tree match))) (if (not (eq? (string-length input) (peg:end match))) - (let ((tree (peg:tree match))) - (pretty-print (peg:tree match)) + (begin + (pretty-print tree) (pretty-print "parse error" (current-error-port)) (pretty-print (peg:end match)) #f) - (peg:tree match)))) + tree)))