urbit/pkg/base-dev/lib/story.hoon

117 lines
2.6 KiB
Plaintext
Raw Normal View History

2022-01-26 19:37:02 +03:00
/- *story
!:
2022-02-04 20:49:55 +03:00
^?
2022-01-26 19:37:02 +03:00
|%
:: XX generalize move to hoon.hoon
++ dif-ju
|= [a=story b=story]
^- story
:: if 0 is the empty set,
:: a \ 0 = a
2022-02-05 14:15:45 +03:00
:: 0 \ b = 0 :: anything in 0 but not in b is by definition 0
::
?: =(~ a) ~
2022-02-03 07:35:55 +03:00
~& a
2022-02-05 14:15:45 +03:00
:: uno := (a-b) + (merged items in both a and b) + (b-a)
:: ret := (a-b) + (merged items in both a and b)
:: ret = (~(int by a) uno) :: preserve only the entries whose keys are in a
=/ uno=story
2022-02-03 07:35:55 +03:00
%- (~(uno by a) b)
|= [k=tako:clay proses-a=proses proses-b=proses]
^- proses
(~(dif in proses-a) proses-b)
::
2022-02-05 14:15:45 +03:00
=/ ret=story (~(int by a) uno)
:: normalizing step, remove any keys with null sets,
:: which can occur if proses-a == proses-b above
%- ~(gas by *story)
(skip ~(tap by ret) |=([k=* v=proses] ?=(~ v)))
::
++ uni-ju
|= [a=story b=story]
^- story
2022-02-03 07:35:55 +03:00
:: 0 + b = b
?: =(~ a) b
%- (~(uno by a) b)
|= [k=tako:clay proses-a=proses proses-b=proses]
^- proses
(~(uni in proses-a) proses-b)
::
:: Canonical textual representation
::
2022-01-26 19:37:02 +03:00
++ tako-to-text
|= [=tako:clay]
2022-01-30 23:59:58 +03:00
^- tape
"commit: {<`@uv`tako>}\0a"
::
2022-01-26 19:37:02 +03:00
++ proses-to-text
2022-01-30 23:59:58 +03:00
|= [=proses]
^- tape
2022-01-26 19:37:02 +03:00
=/ proses-list=(list prose) ~(tap in proses)
2022-01-30 23:59:58 +03:00
?: ?=(~ proses-list) ""
2022-01-26 19:37:02 +03:00
?: ?=([prose ~] proses-list)
2022-01-30 23:59:58 +03:00
(prose-to-text i.proses-list)
2022-01-26 19:37:02 +03:00
%- tail
2022-01-30 23:59:58 +03:00
%^ spin ;;((list prose) t.proses-list) :: XX WHY DO WE NEED ;;
2022-02-04 20:49:10 +03:00
(prose-to-text i.proses-list)
2022-01-30 23:59:58 +03:00
|= [prz=prose state=tape]
2022-01-26 19:37:02 +03:00
^- [prose tape]
2022-01-30 23:59:58 +03:00
:- prz
2022-01-26 19:37:02 +03:00
;: welp
state
2022-01-30 23:59:58 +03:00
"|||"
"\0a"
(prose-to-text prz)
==
::
++ prose-to-text
2022-02-05 14:15:45 +03:00
|= prz=prose
=/ [title=@t body=@t] prz
2022-01-30 23:59:58 +03:00
^- tape
;: welp
2022-01-26 19:37:02 +03:00
"{(trip title)}"
"\0a\0a"
"{(trip body)}"
"\0a"
==
2022-01-31 00:01:00 +03:00
::
:: Parsers
::
++ parse-commit
;~ sfix
;~ pfix (jest 'commit: ')
(cook @uv ;~(pfix (jest '0v') viz:ag))
==
::
(just '\0a')
==
::
++ parse-title
;~ sfix
(cook crip (star prn))
(jest '\0a\0a')
==
::
++ parse-body-single
%- star
;~ less
;~(pose (jest '|||\0a') (jest '---\0a'))
(cook crip ;~(sfix (star prn) (just '\0a')))
==
::
++ parse-prose-single ;~(plug parse-title parse-body-single)
++ parse-rest-proses (star ;~(pfix (jest '|||\0a') parse-prose-single))
++ parse-proses ;~(plug parse-prose-single parse-rest-proses)
++ parse-chapter ;~(plug parse-commit parse-proses)
++ parse-story (star ;~(sfix parse-chapter (jest '---\0a')))
::
:: Parse prose: a title, followed by a body
::
:: Parse proses: a prose, followed by zero or more proses, representing conflicts
::
:: Parse chapters (story entries): a commit followed by one or more proses
::
:: Parse story: zero or more chapters
::
::
2022-01-26 19:37:02 +03:00
--