1

How do I provide syntax rules in racket?

I have code which is similar to this:

(define-syntax SELECT 
  (syntax-rules (FROM WHERE star)
    [(SELECT colnames FROM relnames)
     ...]
    [(SELECT colnames FROM relnames WHERE . expression)
     ...]))

How do I use a provide statement in order to provide FROM WHERE and star?

This is how I provide SELECT:

(provide SELECT)
Atonic
  • 509
  • 1
  • 5
  • 14

1 Answers1

2

Here is one way to do it. First define the literals (and give a nice error messages if used outside SELECT), second provide them.

#lang racket
(provide SELECT FROM WHERE)

(define-syntax FROM  (λ (stx) (raise-syntax-error 'FROM  "literal FROM used outside SELECT"  stx)))
(define-syntax WHERE (λ (stx) (raise-syntax-error 'WHERE "literal WHERE used outside SELECT" stx)))

(define-syntax SELECT 
  (syntax-rules (FROM WHERE star)
    [(SELECT colnames FROM relnames)                    ...]
    [(SELECT colnames FROM relnames WHERE . expression) ...]))
soegaard
  • 30,661
  • 4
  • 57
  • 106
  • I’m not sure that is the right thing here. It seems that the OP simply wants to provide some identifiers to be recognized as literals. – Alexis King Jan 26 '18 at 17:11
  • Thank you. I really enjoyed the link you provided before your edit, which explains some things around, even tough it didn't provide the answer directly (linking it in case someone wants something more to read). Section 5: [Syntac parameters](http://www.greghendershott.com/fear-of-macros/all.html#%28part._.Syntax_parameters%29) – Atonic Jan 30 '18 at 13:10