summaryrefslogtreecommitdiff
path: root/parser/parser-errors.scm
diff options
context:
space:
mode:
Diffstat (limited to 'parser/parser-errors.scm')
-rw-r--r--parser/parser-errors.scm74
1 files changed, 74 insertions, 0 deletions
diff --git a/parser/parser-errors.scm b/parser/parser-errors.scm
new file mode 100644
index 0000000..ae4d097
--- /dev/null
+++ b/parser/parser-errors.scm
@@ -0,0 +1,74 @@
+;;; This contains parser error handlers. They, in turn, call the
+;;; system error handlers.
+
+(define (lexer-error id . msgs)
+ (parser-error/common id 'recoverable msgs '#t)
+ `#\?)
+
+(define (parser-error id . msgs)
+ (parser-error/common id 'phase msgs '#f)
+ (if (null? *layout-stack*)
+ (abort-compilation)
+ (recover-to-next-decl *token-stream*)))
+
+(define (parser-error/recoverable id . args)
+ (parser-error/common id 'recoverable args '#f))
+
+(define (parser-error/common id type msgs in-lexer?)
+ (let ((place
+ (if in-lexer?
+ (list "Error occured at in file ~A at line ~A, column ~A."
+ *current-file* *current-line* *current-col*)
+ (list "Error occured at in file ~A at line ~A, token ~A."
+ *current-file* *current-line*
+ (cond ((null? *token-args*)
+ *token*)
+ ((null? (cdr *token-args*))
+ (car *token-args*))
+ (else *token-args*)))))) ; could be better
+ (haskell-error id type (list place msgs))))
+
+(define (recover-to-next-decl tokens)
+ (cond ((null? tokens)
+ (abort-compilation))
+ ((eq? (car (car tokens)) 'line)
+ (search-layout-stack *layout-stack* tokens (caddr (car tokens))))
+ (else (recover-to-next-decl (cdr tokens)))))
+
+(define (search-layout-stack layouts tokens column)
+ (cond ((null? layouts)
+ (abort-compilation))
+ ((> column (layout-col (car layouts)))
+ (recover-to-next-decl (cdr tokens)))
+ ((= column (layout-col (car layouts)))
+ (setf *current-col* column)
+ (setf *current-line* (cadr (car tokens)))
+ (setf *token-stream* (cdr tokens))
+ (advance-token) ; loads up *token*
+ ;; *** layout-recovery-fn is not defined anywhere!
+ (funcall (layout-recovery-fn (car layouts))))
+ (else
+ (setf *layout-stack* (cdr *layout-stack*))
+ (search-layout-stack (cdr layouts) tokens column))))
+
+
+;;; Here are some very commonly used signalling functions.
+;;; Other (more specific) signalling functions are defined near
+;;; the places where they are called.
+
+
+;;; This is used when a particular token isn't found.
+
+(define (signal-missing-token what where)
+ (parser-error 'missing-token
+ "Missing ~a in ~a." what where))
+
+
+;;; This is used to signal more complicated parse failures involving
+;;; failure to match a nonterminal.
+
+(define (signal-invalid-syntax where)
+ (parser-error 'invalid-syntax
+ "Invalid syntax appears where ~a is expected." where))
+
+