提供语法规则Racket

时间:2018-01-25 12:16:44

标签: racket define-syntax syntax-rules

如何在球拍中提供语法规则?

我的代码类似于:

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

如何使用provide语句提供FROM WHERE和star?

这就是我提供SELECT的方式:

(provide SELECT)

1 个答案:

答案 0 :(得分:2)

这是一种方法。首先定义文字(如果在SELECT之外使用,则给出一个很好的错误消息),第二个提供它们。

#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) ...]))