According to the docs for syntax-parse/#:literals [1], "syntax-parse requires all literals to have a binding", and "the syntax-patterns are interpreted as if each occurrence of pattern-id were replaced with the following pattern: (~literal literal-id #:phase phase-expr)"
So, this error makes sense, because foo has no binding:
> (require syntax/parse)
> (syntax-parse #'(a foo b) #:literals (foo) [(x foo y) 'ok])
; readline-input:31:38: syntax-parse: literal is unbound in phase 0 (phase 0 relative to the enclosing module) at: foo
but when I use the expanded version, there is no error:
> (syntax-parse #'(a foo b) [(x (~literal foo) y) 'ok])
'ok
> (syntax-parse #'(a foo b) [(x (~literal foo #:phase 0) y) 'ok])
'ok
> (syntax-parse #'(a foo b) [(x (~literal foo #:phase 1) y) 'ok])
'ok
What am I missing here?
[1]
https://docs.racket-lang.org/syntax/Parsing_Syntax.html#(form._((lib._syntax%2Fparse..rkt)._syntax-parse))