kriti-lang
kriti-lang copied to clipboard
`renderPretty` is broken
Current Behaviour
For the following Kriti template:
{"name": {{$.user.name}}, "age": {{$.user.age}} }
If I parse the above template and try to render it using renderPretty
, I get the following:
ghci> import Kriti.Parser
ghci> x = parser "{\"name\": {{$.user.name}}, \"age\": {{$.user.age}} }"
ghci> fmap renderPretty x
Right "{{age: $.user.age,name: $.user.name,}}"
Now, if I try parsing the rendered template, I get the following error:
ghci> parser "{{age: $.user.age,name: $.user.name}}"
Left (UnexpectedToken (Loc {getSpan = Span {start = AlexSourcePos {line = 0, col = 36}, end = AlexSourcePos {line = 0, col = 38}}, unLoc = TokSymbol (Loc {getSpan = Span {start = AlexSourcePos {line = 0, col = 6}, end = AlexSourcePos {line = 0, col = 7}}, unLoc = SymColon})}) "{{age: $.user.age,name: $.user.name}}")
Ideal behavior
The render of a parsed template should be the same as the original template.
It looks like there is definitely a bug in the pretty printer. We can and should fix this.
However, exact printing is a Hard problem and usually isn't needed. There is an inevitable loss of information in the parsing process. For example. when lexing we discard white-space and comments.
The standard we try to adhere to is: parse (prettyPrint term) == term
. We should have roundtrip parsing tests like this. I was working on some a while back but it looks like they never got merged.