backtracking hack to fix dedent parsing; adds == as terminator
$head :: # heading
$bloc :: > block-quote
$expr :: ;sail expression
+ $stet :: == to end markdown
$text :: anything else
== ::
++ graf :: paragraph element
=| hac/(list item)
=/ cur/item [%down ~]
=| lub/(unit (pair hair wall))
+ =| last-column/@ud :: for backtracking
|_ {top/@ud naz/hair los/tape}
::
++ $ :: resolve
$(los t.los, q.naz +(q.naz), nap [i.los nap])
::
:: consume newline
- :_ +>(los t.los, naz [+(p.naz) 1])
+ :_ +>(los t.los, naz [+(p.naz) 1], last-column q.naz)
::
:: trim trailing spaces
|- ^- tape
$(nap t.nap)
(flop nap)
::
- ++ skip :: discard line
- |- ^+ ..^$
- ::
- :: no unterminated lines
- ?~ los
- ::~& %unterminated-line
- ..^$(err `naz)
- ?. =(`@`10 i.los)
- ::
- :: eat byte and repeat
- $(los t.los)
- ::
- :: consume newline
- ..^$(los t.los, naz [+(p.naz) 1])
- ::
++ look :: inspect line
^- (unit trig)
(wonk (look:parse naz los))
?~ pic
::
:: break section
- =~(skip close-item line)
+ =~(+:snap close-item line)
::
:: line is not blank
=> .(pic u.pic)
::
:: if end of input, complete
- ?: |(?=($done sty.pic) (lth col.pic top))
+ ?: ?=($done sty.pic)
..$(q.naz col.pic)
::
+ :: if == or dedent, complete and backtrack
+ ?: |(?=($stet sty.pic) (lth col.pic top))
+ %_ ..$
+ p.naz (dec p.naz)
+ q.naz last-column
+ los ['\0a' los] :: put newline back
+ ==
+ ::
:: bal: inspection copy of lub, current section
=/ bal lub
::
$8 (push %poem) :: verse literal
$0 :: unindented forms
?- sty.pic
- $done !! :: blank
+ ?($done $stet) !! :: end of markdown
$rule (push %rule) :: horizontal ruler
$head (push %head) :: heading
$bloc (entr %bloc) :: blockquote line
;~ pose
(full (easy %done)) :: end of input
(cold ~ (just `@`10)) :: blank line
+ (cold %stet duz) :: == (ends markdown)
(cold %rule ;~(plug hep hep hep)) :: --- horizontal ruler
(cold %fens ;~(plug tec tec tec)) :: ``` code fence
(cold %head ;~(plug (star hax) ace)) :: # heading
