add `quad/text` and #lang line options
parent
a6906fe841
commit
c7c80bc510
@ -0,0 +1,19 @@
|
||||
#lang quad/dev
|
||||
(require sugar/list)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(struct $doc (xs) #:transparent)
|
||||
(define (doc . xs) ($doc xs))
|
||||
|
||||
(define (multipage . xs) xs)
|
||||
|
||||
(define (multicolumn . xs) xs)
|
||||
|
||||
(define (multiblock . xs) xs)
|
||||
|
||||
(define (multiline . xs)
|
||||
(break-lines xs))
|
||||
|
||||
(struct $line (xs) #:transparent)
|
||||
(define (break-lines xs)
|
||||
(map (λ(xis) ($line xis)) (slice-at xs 6)))
|
@ -1,11 +1,17 @@
|
||||
#lang racket/base
|
||||
(require "quads.rkt")
|
||||
(provide (all-from-out racket/base "quads.rkt"))
|
||||
(require "quads.rkt" "doc.rkt" "parse.rkt" "tokenize.rkt" racket/list racket/string)
|
||||
(provide (except-out (all-from-out racket/base "quads.rkt") #%module-begin)
|
||||
(rename-out [~module-begin #%module-begin]))
|
||||
|
||||
(define-namespace-anchor ns)
|
||||
|
||||
(module reader racket/base
|
||||
(require br/reader-utils "parse.rkt" "tokenize.rkt")
|
||||
|
||||
(define-read-and-read-syntax (source-path input-port)
|
||||
#`(module quad-mod
|
||||
#,(parse source-path (tokenize input-port)))))
|
||||
(define-syntax-rule (~module-begin lang-line-config-arg . args)
|
||||
(#%module-begin
|
||||
(define main-quad (quad #f . args))
|
||||
;; branch on config-arg to allow debug / inspection options on #lang line
|
||||
(case (string-trim lang-line-config-arg)
|
||||
[("#:atoms") (tokenize main-quad)]
|
||||
[else (eval (parse (tokenize main-quad)) (namespace-anchor->namespace ns))])))
|
||||
|
||||
(module reader syntax/module-reader
|
||||
"main.rkt")
|
@ -1,3 +1,3 @@
|
||||
#lang quad
|
||||
#lang quad/text
|
||||
|
||||
(quad #f "Meg is an ally." (quad #f 'page-break) "Meg is an ally.")
|
||||
Meg is an ally. @(line-break) Meg is an ally.
|
||||
|
@ -0,0 +1,33 @@
|
||||
#lang racket/base
|
||||
|
||||
#|
|
||||
Same semantics as `#lang quad`,
|
||||
but substitutes a Scribble-style text-based reader
|
||||
|#
|
||||
|
||||
(module reader syntax/module-reader
|
||||
"main.rkt"
|
||||
#:read quad-read
|
||||
#:read-syntax quad-read-syntax
|
||||
#:whole-body-readers? #t ;; need this to make at-reader work
|
||||
(require scribble/reader racket/list sugar/list)
|
||||
|
||||
(define (quad-read p)
|
||||
(syntax->datum (quad-read-syntax (object-name p) p)))
|
||||
|
||||
(define quad-command-char #\@)
|
||||
|
||||
(define (quad-read-syntax path-string p)
|
||||
(define quad-at-reader (make-at-reader
|
||||
#:command-char quad-command-char
|
||||
#:syntax? #t
|
||||
#:inside? #t))
|
||||
(define source-stx (quad-at-reader path-string p))
|
||||
(define source-stx-list (syntax->list source-stx))
|
||||
(define config-line (car source-stx-list))
|
||||
;; we dump all whitespace lines in plain-text mode, as they have no semantic purpose
|
||||
;; the at-reader will kindly separate these all-whitespace lines into their own list elements
|
||||
(define source-stx-no-interline-whitespace
|
||||
(filter (λ(stx) (define datum (syntax->datum stx))
|
||||
(and (string? datum) (regexp-match #rx"\\s+" datum))) (cdr source-stx-list)))
|
||||
(datum->syntax source-stx (cons config-line source-stx-no-interline-whitespace) source-stx)))
|
Loading…
Reference in New Issue