on master help sign in
made parse-print loop idempotent
commit025791c294293950a299a4f1ee92e975ff984343 authoriko <mail@iko.soy> dateTue 30 Jul 2024, 11:07 (2 years ago) parentbd8a7b7
2 files changed+19−10
desk/lib/lua/printer.hoon+3−1 desk/ted/test-lua.hoon+16−9
desk/lib/lua/printer.hoon+3−1
@@ -189,7 +189,9 @@ print
189189 |= [=prefix-expr]
190190 ?- -.prefix-expr
191191 %var (print-var +.prefix-expr)
192− %expr
192+ %expr
193+ :: since binops already have parens
194+ ?: ?=(%binop +<.prefix-expr) (print-expr +.prefix-expr)
193195 %- zing
194196 :~
195197 "("
desk/ted/test-lua.hoon+16−9
@@ -30,7 +30,12 @@
3030 ?- -.flag
3131 %restrict ~[+.flag]
3232 ==
33−;< bek=beak bind:m get-beak
33+=/ parse
34+ |* src=tape
35+ ?: (has-flag %crash-parser)
36+ (some (scan src lua-parser))
37+ (rust src lua-parser)
38+ ;< bek=beak bind:m get-beak
3439;< lua-files=(list path) bind:m (list-tree [bek /res/lua])
3540=/ lua-files %+ skim lua-files
3641 |= =path
@@ -51,10 +56,7 @@
5156 ;< =cage bind:m (read-file [bek current-file])
5257 =/ lua-code=@t (of-wain:format !<(wain +.cage))
5358 ~& %parsing
54− =/ ast-unit
55− ?: (has-flag %crash-parser)
56− (some (rash lua-code lua-parser))
57− (rush lua-code lua-parser)
59+ =/ ast-unit (parse (trip lua-code))
5860 ;< parse-result=test-result bind:m
5961 =/ m (strand:spider ,test-result)
6062 ?~ ast-unit (pure:m %err)
@@ -68,13 +70,18 @@
6870 %& [(into current-file 2 ~.cycled) %ins %lua !>((to-wain:format (crip printed)))]~
6971 ==
7072 ~& %parsing-printed
71− =/ cycled-ast-unit
72− ?: (has-flag %crash-parser)
73− (some (scan printed lua-parser))
74− (rust printed lua-parser)
73+ =/ cycled-ast-unit (parse printed)
7574 ?~ cycled-ast-unit (pure:m %err)
7675 =/ ast u.cycled-ast-unit
7776 ~? (has-flag %print-asts) ast
77+ ~& %printing-parsed
78+ =/ printed (lua-printer ast)
79+ ~& %comparing-printed
80+ ?. =(printed ^printed) (pure:m %err)
81+ ~& %parsing-reprinted
82+ =/ cycled-ast-unit (parse printed)
83+ ?~ cycled-ast-unit (pure:m %err)
84+ =/ ast u.cycled-ast-unit
7885 ~& %comparing-asts
7986 ?. =(^ast ast) (pure:m %err)
8087 (pure:m %ok)