SDF3 treats \r (CR) differently from \n (LF)
The following SDF3-coq-semantics syntax:
Block.Block = < { <{Statement "\n"}*> } >
When written with Unix/OSX line endings (only LF at the end of each line): (zoom in to see them properly)
Block.Block = <␊ {␊ <{Statement "\n"}*>␊ }␊ >
it generates this pretty-printing code, as expected:
prettyprint-Block : Block(t0__) -> [ H( [SOpt(HS(), "0")] , [S("{")] ) , t0__' , H( [SOpt(HS(), "0")] , [S("}")] ) ] with t0__' := <pp-indent(|"2")> [<pp-V-list(prettyprint-Statement)> t0__]
However, when written with Windows line endings (CR+LF at the end of each line):
Block.Block = <␍␊ {␍␊ <{Statement "\n"}*>␍␊ }␍␊ >
then it generates pretty-printing code with additional newlines in them:
prettyprint-Block : Block(t0__) -> [ H( [] , [S("")] ) , H( [SOpt(HS(), "0")] , [S("{")] ) , H( [] , [S("")] ) , t0__' , H( [] , [S("")] ) , H( [SOpt(HS(), "0")] , [S("}")] ) , H( [] , [S("")] ) ] with t0__' := <pp-indent(|"2")> [<pp-V-list(prettyprint-Statement)> t0__]
Unless I specify
Submitted by D. Pelsmaeker on 8 August 2014 at 14:56\r
or\n
explicitly, any carriage-returns or line-feed characters in the template should be treated equally as layout.
Issue Log
Actually this is even more annoying than I initially thought. My Windows GIT replaces all LF by CR+LF on checkout as that’s the standard Windows line ending convention. In turn, this messes up all pretty-printing rules.
Could you post the AST that you get for the SDF3 production that you have on Windows? I think I know what is going on.
Sure, this is the AST:
TemplateProductionWithCons( SortCons(SortDef("Block"), Constructor("Block")) , Template( [ Line([]) , Line([]) , Line([Layout("\t"), String("{")]) , Line([]) , Line( [ Layout("\t ") , Angled(Placeholder(IterStarSep(Sort("Statement"), Lit("\"\\n\"")), NoOptions())) ] ) , Line([]) , Line([Layout("\t"), String("}")]) , Line([]) , Line([Layout("\t")]) ] ) , NoAttrs() )
Desugared:
TemplateProductionWithCons( SortCons(SortDef("Block"), Constructor("Block")) , Template( [ Line([Layout("")]) , Line([Layout(""), String("{")]) , Line([Layout("")]) , Line( [Layout(" "), Placeholder(IterStarSep(Sort("Statement"), Lit("\"\\n\"")), NoOptions())] ) , Line([Layout("")]) , Line([Layout(""), String("}")]) , Line([Layout("")]) ] ) , NoAttrs() )
Log in to post comments