test-lr-no-clause.scm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ;;; test-lr-no-clause.scm --
  2. ;;
  3. (load "common-test.scm")
  4. (define (doit . tokens)
  5. (let ((parser (lalr-parser (expect: 0)
  6. (NUMBER COMMA NEWLINE)
  7. (lines (lines line) : (list $2)
  8. (line) : (list $1))
  9. (line (NEWLINE) : #\newline
  10. (NUMBER NEWLINE) : $1
  11. ;;this is a rule with no semantic action
  12. (COMMA NUMBER NEWLINE)))))
  13. (parser (make-lexer tokens) error-handler)))
  14. (check
  15. ;;correct input
  16. (doit (make-lexical-token 'NUMBER #f 1)
  17. (make-lexical-token 'NEWLINE #f #\newline))
  18. => '(1))
  19. (check
  20. ;;correct input with comma, which is a rule with no client form
  21. (doit (make-lexical-token 'COMMA #f #\,)
  22. (make-lexical-token 'NUMBER #f 1)
  23. (make-lexical-token 'NEWLINE #f #\newline))
  24. => '(#(line-3 #\, 1 #\newline)))
  25. (check
  26. ;;correct input with comma, which is a rule with no client form
  27. (doit (make-lexical-token 'NUMBER #f 1)
  28. (make-lexical-token 'NEWLINE #f #\newline)
  29. (make-lexical-token 'COMMA #f #\,)
  30. (make-lexical-token 'NUMBER #f 2)
  31. (make-lexical-token 'NEWLINE #f #\newline))
  32. => '(#(line-3 #\, 2 #\newline)))
  33. ;;; end of file