Top 1,000 Features Creators Resources Blog Explore Download
GitHub icon

turnstile

< >

turnstile is a grammar language created in 2017 by Stephen Chang and Alex Knauth and Ben Greenman and Milo Turner and Michael Ballantyne.

#2459on PLDB 7Years Old


Example from the web:
#lang turnstile (provide → Int λ #%app #%datum + ann) (define-base-type Int) (define-type-constructor → #:arity > 0) (define-primop + : (→ Int Int Int)) ; [APP] (define-typed-syntax (#%app e_fn e_arg ...) ≫ [⊢ e_fn ≫ e_fn- ⇒ (~→ τ_in ... τ_out)] #:fail-unless (stx-length=? #'[τ_in ...] #'[e_arg ...]) (format "arity mismatch, expected ~a args, given ~a" (stx-length #'[τ_in ...]) #'[e_arg ...]) [⊢ e_arg ≫ e_arg- ⇐ τ_in] ... -------- [⊢ (#%app- e_fn- e_arg- ...) ⇒ τ_out]) ; [LAM] (define-typed-syntax λ #:datum-literals (:) [(_ ([x:id : τ_in:type] ...) e) ≫ [[x ≫ x- : τ_in.norm] ... ⊢ e ≫ e- ⇒ τ_out] ------- [⊢ (λ- (x- ...) e-) ⇒ (→ τ_in.norm ... τ_out)]] [(_ (x:id ...) e) ⇐ (~→ τ_in ... τ_out) ≫ [[x ≫ x- : τ_in] ... ⊢ e ≫ e- ⇐ τ_out] --------- [⊢ (λ- (x- ...) e-)]]) ; [ANN] (define-typed-syntax (ann e (~datum :) τ:type) ≫ [⊢ e ≫ e- ⇐ τ.norm] -------- [⊢ e- ⇒ τ.norm]) ; [DATUM] (define-typed-syntax #%datum [(_ . n:integer) ≫ -------- [⊢ (#%datum- . n) ⇒ Int]] [(_ . x) ≫ -------- [#:error (type-error #:src #'x #:msg "Unsupported literal: ~v" #'x)]])

Language features

Feature Supported Token Example
Comments
; A comment
Line Comments ;
; A comment
Semantic Indentation X

View source

- Build the next great programming language · About · Acknowledgements · Extensions · Day 625 · feedback@pldb.io