test-lr-error-recovery-02.scm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ;;; test-lr-error-recovery-02.scm --
  2. ;;
  3. ;;Test error recovery policy when the synchronisation terminal has the
  4. ;;same category of the lookahead that raises the error.
  5. ;;
  6. (load "common-test.scm")
  7. (define (doit . tokens)
  8. (let ((parser (lalr-parser (expect: 0)
  9. (A B C)
  10. (alphas (alpha) : $1
  11. (alphas alpha) : $2)
  12. (alpha (A B) : (list $1 $2)
  13. (C) : $1
  14. (error C) : 'error-form))))
  15. (parser (make-lexer tokens) error-handler)))
  16. ;;; --------------------------------------------------------------------
  17. ;;; No error, just grammar tests.
  18. (check
  19. (doit (make-lexical-token 'A #f 1)
  20. (make-lexical-token 'B #f 2))
  21. => '(1 2))
  22. (check
  23. (doit (make-lexical-token 'C #f 3))
  24. => '3)
  25. ;;; --------------------------------------------------------------------
  26. ;;; Successful error recovery.
  27. (check
  28. ;;Error, recovery, end-of-input.
  29. (let ((r (doit (make-lexical-token 'A #f 1)
  30. (make-lexical-token 'C #f 3))))
  31. (cons r *error*))
  32. => '(error-form (error-handler "Syntax error: unexpected token : " . C)))
  33. (check
  34. ;;Error, recovery, correct parse of "A B".
  35. (let ((r (doit (make-lexical-token 'A #f 1)
  36. (make-lexical-token 'C #f 3)
  37. (make-lexical-token 'A #f 1)
  38. (make-lexical-token 'B #f 2))))
  39. (cons r *error*))
  40. => '((1 2)
  41. (error-handler "Syntax error: unexpected token : " . C)))
  42. ;;; end of file