urbit/gen/cram.hoon

61 lines
2.3 KiB
Plaintext
Raw Normal View History

2017-11-10 03:48:57 +03:00
::BROKEN fixme when md is properly merged
2017-07-16 03:59:57 +03:00
::
2017-07-24 09:19:53 +03:00
:::: hoon/cram/gen
2017-07-16 03:59:57 +03:00
::
2017-07-24 22:21:53 +03:00
:: test generator for the cram markdown syntax
::
:: todo: integrate with ++sail and embed in hoon compiler
::
:: ++cram is a simple markdown-inspired parser that makes
:: common html tropes easy to type. you can think of ++cram
:: as "rational markdown" or "markdown with syntax errors."
:: a document format should be easy to type and read, but
:: that doesn't mean it can't or have rigorous syntax.
::
2017-07-25 01:49:59 +03:00
:: tldr: ++cram is indent-oriented. indent 2 spaces for
2017-07-24 22:21:53 +03:00
:: a dynamic interpolation, 4 spaces for example code, 6
:: spaces for a blockquote and 8 spaces for verse. separate
2017-07-25 01:49:59 +03:00
:: every semantic block by a blank line. use - for
:: unordered lists, + for ordered lists.
::
2017-07-24 22:21:53 +03:00
:: markdown link syntax works. * means bold, _ means
:: italics, "" inserts smart quotes. all enclosed
:: strings are reparsed; escape the terminator within
:: the string, eg, *star \* in bold text*.
::
:: markdown `literal` syntax is supported, but all hoon
:: constants are automatically marked as code. also, any
2017-07-25 01:49:59 +03:00
:: hoon expression prefixed with # is a code literal.
2017-07-24 22:21:53 +03:00
::
:: (++cram is a valid hoon parsing rule, but it does a lot
:: of custom processing internally, since the language is
:: context-sensitive. we use a context-sensitive parser
:: to cut the lines into blocks, then reparse flow blocks
:: with normal hoon rules. multipass parsing is the tax
:: humans have to pay for simple but human-friendly syntax.)
2017-07-25 02:00:44 +03:00
::
::|= inp/cord
::=< (steam-marl (rash inp apex:(sail &)))
=< |=(pax/path (test pax))
2017-07-25 01:49:59 +03:00
|% ::
2017-07-24 02:00:45 +03:00
++ test :: test text parsing
|= pax/path
^- tape
::
2017-07-24 02:00:45 +03:00
:: src: text file as (list cord)
:: txt: source as tape with newlines
:: vex: parsing result
::
=/ src .^(wain %cx pax)
2017-08-02 02:38:06 +03:00
=. src ['---' src]
=/ txt (zing (turn src |=(@t (weld (rip 3 +<) `tape`~[`@`10]))))
2017-08-03 02:25:32 +03:00
=/ vex (cram:vast [1 1] txt)
2017-07-24 02:00:45 +03:00
::
:: print result as error or xml text
2017-07-24 02:00:45 +03:00
?~ q.vex
"syntax error: line {(scow %ud p.p.vex)}, column {(scow %ud q.p.vex)}"
2017-08-03 02:25:32 +03:00
?: [freeze=|] (poxo (snag 1 ~(shut ap p.u.q.vex)))
(poxo ;;(manx q:(slap !>(..zuse) p.u.q.vex)))
::
2017-07-18 04:07:47 +03:00
--