{"size": 1499, "ext": "scrbl", "max_stars_repo_path": "define-datum-literal-set/define-datum-literal-set.scrbl", "max_stars_repo_name": "maueroats/syntax-parse-example", "max_stars_repo_stars_event_min_datetime": "2017-05-18T22:15:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T13:13:05.000Z", "max_issues_repo_path": "define-datum-literal-set/define-datum-literal-set.scrbl", "max_issues_repo_name": "maueroats/syntax-parse-example", "max_issues_repo_issues_event_min_datetime": "2017-05-18T22:54:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-19T02:58:50.000Z", "max_forks_repo_path": "define-datum-literal-set/define-datum-literal-set.scrbl", "max_forks_repo_name": "maueroats/syntax-parse-example", "max_forks_repo_forks_event_min_datetime": "2017-05-19T14:27:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T09:36:54.000Z"}
{"max_stars_count": 22, "max_issues_count": 20, "max_forks_count": 6, "avg_line_length": 35.6904761905, "max_line_length": 178, "alphanum_fraction": 0.6731154103}
#lang syntax-parse-example
@require[
  (for-label racket/base syntax/parse syntax-parse-example/define-datum-literal-set/define-datum-literal-set)]

@(define define-datum-literal-set-eval
   (make-base-eval '(require syntax-parse-example/define-datum-literal-set/define-datum-literal-set (for-syntax racket/base syntax/parse))))

@title{@tt{define-datum-literal-set}}

@; =============================================================================

@defmodule[syntax-parse-example/define-datum-literal-set/define-datum-literal-set]{}

@defform[(define-datum-literal-set id (id ...))]{

  @racket[syntax-parse] can match literal symbols using the @racket[#:datum-literals]
   option or the @racket[~datum] pattern form.
  These work well for a small number of literals.

  Given a sequence of symbols, the @racket[define-datum-literal-set] macro builds
   a @tech[#:doc '(lib "syntax/scribblings/syntax.scrbl")]{syntax class} that matches these symbols.

  @racketblock[
   (define-datum-literal-set C-keyword
     (auto break case char const continue default do double else))

   (define-syntax (is-C-keyword? stx)
     (syntax-parse stx
      [(_ x:C-keyword)
       #'#true]
      [(_ x)
       #'#false]))

   (is-C-keyword? else)
   (is-C-keyword? synchronized)
  ]

  The macro works by defining a @tech[#:doc '(lib "syntax/scribblings/syntax.scrbl")]{literal set} and then a @tech[#:doc '(lib "syntax/scribblings/syntax.scrbl")]{syntax class}.

  @racketfile{define-datum-literal-set.rkt}
}
