|
|
|
|
|
|
|
|
|
|
|
(load "common-test.scm") |
|
|
|
(define (doit . tokens) |
|
(let ((parser (lalr-parser |
|
(expect: 0) |
|
(NUMBER BAD NEWLINE) |
|
|
|
(script (lines) : (reverse $1) |
|
() : 0) |
|
(lines (lines line) : (cons $2 $1) |
|
(line) : (list $1)) |
|
(line (NEWLINE) : (list 'line $1) |
|
(NUMBER NEWLINE) : (list 'line $1 $2) |
|
(NUMBER NUMBER NEWLINE) : (list 'line $1 $2 $3) |
|
|
|
|
|
|
|
(error NEWLINE) : (list 'recover $1 $2))))) |
|
(parser (make-lexer tokens) error-handler))) |
|
|
|
|
|
|
|
|
|
(check |
|
(doit) |
|
=> 0) |
|
|
|
(check |
|
(doit (make-lexical-token 'NEWLINE #f #\newline)) |
|
=> '((line #\newline))) |
|
|
|
(check |
|
(doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'NEWLINE #f #\newline)) |
|
=> '((line 1 #\newline))) |
|
|
|
(check |
|
(doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'NUMBER #f 2) |
|
(make-lexical-token 'NEWLINE #f #\newline)) |
|
=> '((line 1 2 #\newline))) |
|
|
|
(check |
|
(doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 2) |
|
(make-lexical-token 'NEWLINE #f #\newline)) |
|
=> '((line 1 #\newline) |
|
(line 2 #\newline))) |
|
|
|
(check |
|
(doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 2) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 3) |
|
(make-lexical-token 'NEWLINE #f #\newline)) |
|
=> '((line 1 #\newline) |
|
(line 2 #\newline) |
|
(line 3 #\newline))) |
|
|
|
(check |
|
(doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 2) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 3) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 41) |
|
(make-lexical-token 'NUMBER #f 42) |
|
(make-lexical-token 'NEWLINE #f #\newline)) |
|
=> '((line 1 #\newline) |
|
(line 2 #\newline) |
|
(line 3 #\newline) |
|
(line 41 42 #\newline))) |
|
|
|
|
|
|
|
|
|
(check |
|
|
|
|
|
(let ((r (doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'BAD #f 'alpha) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 2) |
|
(make-lexical-token 'NEWLINE #f #\newline)))) |
|
(cons r *error*)) |
|
=> '(((recover #f #f) |
|
(line 2 #\newline)) |
|
(error-handler "Syntax error: unexpected token : " . BAD))) |
|
|
|
|
|
(check |
|
|
|
|
|
|
|
(let ((r (doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'BAD #f 'alpha) |
|
(make-lexical-token 'BAD #f 'beta) |
|
(make-lexical-token 'BAD #f 'delta) |
|
(make-lexical-token 'NEWLINE #f #\newline) |
|
(make-lexical-token 'NUMBER #f 2) |
|
(make-lexical-token 'NEWLINE #f #\newline)))) |
|
(cons r *error*)) |
|
=> '(((recover #f #f) |
|
(line 2 #\newline)) |
|
(error-handler "Syntax error: unexpected token : " . BAD))) |
|
|
|
|
|
|
|
|
|
(check |
|
|
|
(let ((r (doit (make-lexical-token 'NUMBER #f 1)))) |
|
(cons r *error*)) |
|
=> '(#f (error-handler "Syntax error: unexpected end of input"))) |
|
|
|
(check |
|
|
|
|
|
|
|
|
|
(let ((r (doit (make-lexical-token 'NUMBER #f 1) |
|
(make-lexical-token 'BAD #f 'alpha) |
|
(make-lexical-token 'BAD #f 'beta) |
|
(make-lexical-token 'BAD #f 'delta)))) |
|
(cons r *error*)) |
|
=> '(0 (error-handler "Syntax error: unexpected token : " . BAD))) |
|
|
|
(check |
|
|
|
|
|
|
|
|
|
(let ((r (doit (make-lexical-token 'BAD #f 'alpha)))) |
|
(cons r *error*)) |
|
=> '(0 (error-handler "Syntax error: unexpected token : " . BAD))) |
|
|
|
|
|
|