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 \r or \n explicitly, any carriage-returns or line-feed characters in the template should be treated equally as layout.

Submitted by D. Pelsmaeker on 8 August 2014 at 14:56

On 12 August 2014 at 11:11 D. Pelsmaeker commented:

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.


On 13 August 2014 at 13:56 Eduardo Amorim commented:

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.


On 13 August 2014 at 14:05 D. Pelsmaeker commented:

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