4 Shrubbery Language
#lang shrubbery | package: shrubbery-lib |
#lang shrubbery/text |
The shrubbery meta-language is similar to the s-exp meta-language. It expects a module name after #lang shrubbery to serve as the language of a Racket module form, while the body of the module after the #lang line is parsed as shrubbery notation.
Unlike s-exp, shrubbery also works without another language listed on the #lang line. In that case, running the module prints the S-expression form of the parsed shrubbery (see Parsed Representation). For example,
#lang shrubbery 1+2
prints '(multi (group 1 (op +) 2)). But if "demo.rkt" contains
"demo.rkt"
#lang racket/base (require (for-syntax racket/base syntax/parse)) (provide (rename-out [module-begin #%module-begin]) + - * /) (define-syntax (module-begin stx) (syntax-parse stx #:datum-literals (multi group op) [(_ (multi (group n1:number (op o) n2:number))) #'(#%module-begin (o 'n1 'n2))]))
then
#lang shrubbery "demo.rkt" 1+2
prints the result 3.
A same-line module language for shrubbery is determined by using parse-all in 'line mode. As long as the resulting shrubbery is not empty, it is parsed in the same way that rhombus parses module names for import.
The shrubbery/text meta-language is similar to shrubbery, but it parses the module in 'text mode. For example,
#lang shrubbery/text @(1+2)
prints '(brackets (group (parens (group 1 (op +) 2)))).