racket / scribble

Other
201 stars 92 forks source link

codeblock reports errors in terms of read-syntax #273

Open LiberalArtist opened 4 years ago

LiberalArtist commented 4 years ago

When codeblock can't parse its arguments, the error can be raised in terms of read-syntax. For example, the following program produces the error message “:4:4: read-syntax: bad syntax #” at runtime (not at read-time):

#lang scribble/manual

@codeblock{
 `@"`"`
 A ::= B
 | C
 | D # which is an E
 `@"`"`
}

This inspired @shriram's example in https://github.com/greghendershott/markdown/issues/84. With that example, the srcloc points to the markdown/scrib library:

#lang at-exp racket

(require markdown markdown/scrib scribble/decode)

(define xs
  (parameterize  ([current-input-port
                   (open-input-string
                    @string-append{```
                    A ::= B
                    | C
                    | D # which is an E
                    ```})])
    (read-markdown)))

xs

(with-handlers ([exn:fail? (λ (e) e)])
  (xexprs->scribble-pres xs))