Add Boucher's `lalr-scm' as the `(system base lalr)' module.
[bpt/guile.git] / test-suite / lalr / test-lr-basics-01.scm
1 ;;; test-lr-basics-01.scm --
2 ;;
3 ;;A grammar that only accept a single terminal as input. It refuses the
4 ;;end-of-input as first token.
5 ;;
6
7 (load "common-test.scm")
8
9 (define (doit . tokens)
10 (let* ((lexer (make-lexer tokens))
11 (parser (lalr-parser (expect: 0)
12 (A)
13 (e (A) : $1))))
14 (parser lexer error-handler)))
15
16 (check
17 (doit (make-lexical-token 'A #f 1))
18 => 1)
19
20 (check
21 (let ((r (doit)))
22 (cons r *error*))
23 => '(#f (error-handler "Syntax error: unexpected end of input")))
24
25 (check
26 ;;Parse correctly the first A and reduce it. The second A triggers
27 ;;an error which empties the stack and consumes all the input
28 ;;tokens. Finally, an unexpected end-of-input error is returned
29 ;;because EOI is invalid as first token after the start.
30 (let ((r (doit (make-lexical-token 'A #f 1)
31 (make-lexical-token 'A #f 2)
32 (make-lexical-token 'A #f 3))))
33 (cons r *error*))
34 => '(#f
35 (error-handler "Syntax error: unexpected end of input")
36 (error-handler "Syntax error: unexpected token : " . A)))
37
38 ;;; end of file