How should we choose between ~describe
descriptions and #:role
for error information with syntax-parse
?
Consider this macro, inspired by a discussion on Discord:
#lang racket
(require (for-syntax syntax/parse))
(define-syntax hash-refs
(syntax-parser
[(_ (~var hsh expr #:role "hash")
(~describe "key with optional default"
(~seq (~var key expr #:role "key")
(~optional (~seq #:or (~describe "default expression"
default:expr)))))
...)
#`(let ([h hsh])
(values (hash-ref h key (~? default)) ...))]))
The incorrect use (hash-refs #hash() 'foo #:or)
gives a helpful error message:
hash-refs: expected more terms starting with default expression
parsing context:
while parsing key with optional default
If we replace the (~describe "default expression" default:expr)
form with (~var default expr #:role "default")
, the error message is less useful and does not mention the role:
hash-refs: expected more terms starting with expression
parsing context:
while parsing key with optional default
For completeness, I also tried (~describe #:role "default" "Expression" default:expr)
, which produced (again without mentioning the role):
hash-refs: expected more terms starting with Expression
parsing context:
while parsing key with optional default
Maybe this is just a bug, and these error messages should mention the role?