Moe Kayali
Moe Kayali

Reputation: 205

Racket's syntax-parse: identifier not matching as expected

I'm having trouble with Racket's syntax-parse. In particular, I am getting the following error message:

unknown: rule: expected one of these identifiers: `model', `line', or `rule'
at: rule
in: (rule (predicate (symbol "T") "[" (symbol-list (symbol "X")) "]") "<-" (predicate (symbol "Q") "[" (symbol-list (symbol "X")) "]"))

Why isn't the rule syntax object matching the identifier? I'm invoking the function as follows:

(define (parse-carl s)
(syntax-parse s
    [((~literal model) ~rest x)
        (with-syntax ([x (map parse-carl (syntax-e #'x))]) #'x)]
    [((~literal line) x) (with-syntax ([x (parse-carl #'x)]) #'x)]
    [((~literal rule) p1 "<-" p2) 'ok]))

Here is the input (passed through syntax->datum):

(model (line (rule (predicate (symbol T) [ (symbol-list (symbol X)) ]) <- (predicate (symbol Q) [ (symbol-list (symbol X)) ]))) 
(line (rule (predicate (symbol Y) [ (symbol-list (symbol X)) ]) <-   (predicate (symbol Q) [ (symbol-list (symbol X)) ]))) 
(line (rule (predicate (symbol Y) [ (symbol-list (symbol X)) ]) <- (predicate (symbol T) [ (symbol-list (symbol X)) ]))) 
(line (query (rule (predicate (symbol Y) [ (symbol-list (symbol X)) ]) <- (predicate (symbol T) [ (symbol-list (symbol X)) ])) ?)) 
)

Thanks in advance.

Upvotes: 1

Views: 133

Answers (1)

Sorawee Porncharoenwase
Sorawee Porncharoenwase

Reputation: 6502

Is rule actually defined? ~literal recognizes a binding, so if there's no binding, it won't work. You would need ~datum instead in that case.

Upvotes: 3

Related Questions