Consider the following example:

lexical syntax
    TYPEVARIABLE = [\'] IDENT

templates
    TypeExpr.TypeVariable = [[TYPEVARIABLE]]
    TypeExpr              = [([TypeExpr])] {bracket}
    TypeExpr.FuncType     = [[TypeExpr] -> [TypeExpr]] {right}
    TypeExpr.ConstrType   = [[GLOBALNAME]]
    TypeExpr.ConstrType   = [[TypeExpr] [GLOBALNAME]]
    TypeExpr.ConstrType   = [([TypeExpr+; separator=","]) [GLOBALNAME]] {avoid}

context-free priorities
    TypeExpr.ConstrType >
    TypeExpr.FuncType

The resulting priority rules that are generated depend on which rules with the constructor name in question came last. In this case it generates:

"(" {TypeExpr ","}+ ")" GLOBALNAME -> TypeExpr >
TypeExpr "->" TypeExpr -> TypeExpr

Whereas my expectation was that the generated SDF2 priorities would include all (or all relevant) rules constructing a ConstrType like so:

{ "(" {TypeExpr ","}+ ")" GLOBALNAME -> TypeExpr
  TypeExpr GLOBALNAME -> TypeExpr                } >
TypeExpr "->" TypeExpr -> TypeExpr

Right now I have to fall back on writing SDF2 style priority rules to get the behaviour I was looking for.
I think it would be nicer to have the priorities generated the way I was expecting them to be generated. Taking the last rule in the list seems arbitrary, and if you don’t want this behaviour then you shouldn’t have used the same constructor name on different rules because they obviously mean something different.

Submitted by Jeff Smits on 17 November 2013 at 14:38

On 17 November 2013 at 14:56 Eelco Visser commented:

Overloading the constructor in this way does not appear to be very useful, as you won’t be able to distinguish between the variant with a list argument and with a single argument.


On 17 November 2013 at 15:10 Jeff Smits commented:

Yes, I guess this example isn’t very good.
And yet, I believe this situation/problem might still occur in well-written grammars.

Log in to post comments