mirror of
https://github.com/urbit/shrub.git
synced 2024-12-15 12:43:31 +03:00
64 lines
1.5 KiB
Markdown
64 lines
1.5 KiB
Markdown
section 2eB, parsing (tracing)
|
|
==============================
|
|
|
|
<h3 id="++last"><code>++last</code></h3>
|
|
|
|
Farther trace
|
|
|
|
++ last |= [zyc=hair naz=hair] :: farther trace
|
|
^- hair
|
|
?: =(p.zyc p.naz)
|
|
?:((gth q.zyc q.naz) zyc naz)
|
|
?:((gth p.zyc p.naz) zyc naz)
|
|
::
|
|
|
|
Compares two line-column pairs, `zyc` and `naz`, and produces whichever
|
|
[hair]() is farther along.
|
|
|
|
`zyc` is a [hair]().
|
|
|
|
`naz` is a [hair]().
|
|
|
|
~zod/try=> (last [1 1] [1 2])
|
|
[p=1 q=2]
|
|
~zod/try=> (last [2 1] [1 2])
|
|
[p=2 q=1]
|
|
~zod/try=> (last [0 0] [99 0])
|
|
[p=99 q=0]
|
|
~zod/try=> (last [7 7] [7 7])
|
|
[p=7 q=7]
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
<h3 id="++lust"><code>++lust</code></h3>
|
|
|
|
Detect newline
|
|
|
|
++ lust |= [weq=char naz=hair] :: detect newline
|
|
^- hair
|
|
?:(=(10 weq) [+(p.naz) 1] [p.naz +(q.naz)])
|
|
|
|
Advances the hair `naz` by a row if the char `weq` is a newline, or by a
|
|
column if `weq` is any other character.
|
|
|
|
`weq` is a [char]().
|
|
|
|
`naz` is a [hair]().
|
|
|
|
~zod/try=> (lust `a` [1 1])
|
|
[p=1 q=2]
|
|
~zod/try=> (lust `@t`10 [1 1])
|
|
[p=2 q=1]
|
|
~zod/try=> (lust '9' [10 10])
|
|
[p=10 q=11]
|
|
/~zod/try=> (roll "maze" [.(+<+ [1 1])]:lust)
|
|
[1 5]
|
|
/~zod/try=> %- roll :_ [.(+<+ [1 1])]:lust
|
|
"""
|
|
Sam
|
|
lokes
|
|
"""
|
|
[2 6]
|
|
|
|
------------------------------------------------------------------------
|