Search code examples
rascal

What does `\` mean at the beginning of an ADT alternative?


From http://tutor.rascal-mpl.org/Rascal/Libraries/lang/java/m3/TypeSymbol/Bound/Bound.html:

data Bound 
   = \super(list[TypeSymbol] bound)
   | \extends(list[TypeSymbol] bound)
   | \unbounded()
   ;

Is there any specific reason why all the alternatives start with a \? What does this mean? Is this some sort of convention or is it special Rascal syntax?


Solution

  • This is a way to escape identifiers.

    Say you want to name a constructor (or function) if, this would overlap with the if statement (and is therefore reserved).

    If you put a \ in front of an identifier, you escape the name. Just like a \" inside a string literal.

    Now, for the Java AST, the choice was made for alignment. Instead of:

    | method(...)
    | \if(...)
    | variable(...)
    

    You add a \ in front of every alternative.