Last active
June 6, 2022 02:38
-
-
Save 6cdh/65619e761753eb4166d15185a6236040 to your computer and use it in GitHub Desktop.
Generate Racket builtin variable list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
; some code copied from https://github.com/greghendershott/racket-mode/blob/master/racket/keywords.rkt | |
(define (exports mod #:only-stx? [only-stx? #f]) | |
(define (ids phases) | |
(for*/list ([phase phases] | |
[item (cdr phase)]) | |
(car item))) | |
(define-values (vars stxs) (module->exports mod)) | |
(remove-duplicates (append (ids stxs) | |
(if only-stx? '() (ids vars))) | |
eq?)) | |
(define (subtract xs ys) | |
(set->list | |
(set-subtract (list->set xs) | |
(list->set ys)))) | |
(define (union xs ys) | |
(set->list | |
(set-union (list->set xs) | |
(list->set ys)))) | |
(define (pp xs) | |
(println (sort (map symbol->string xs) string<=?))) | |
; used in tree-sitter `#match?` predicate | |
(define (symlist->regex-match lst) | |
(string-append | |
"^(" | |
(regexp-replace* #rx"([*+?^$.])" | |
(string-join (map symbol->string lst) "|") | |
"\\\\\\1") | |
")$")) | |
(parameterize ([current-namespace (make-base-empty-namespace)]) | |
(namespace-require 'racket) | |
(define all (exports 'racket)) | |
(define stx (exports 'racket #:only-stx? #t)) | |
(define builtin-procedures | |
(filter (λ (sym) | |
(with-handlers ([exn:fail? (const #f)]) | |
(procedure? (eval sym)))) | |
all)) | |
(define builtin-keywords (subtract stx builtin-procedures)) | |
(define builtin-values (subtract (subtract all stx) builtin-procedures)) | |
(pp builtin-procedures)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment