anchor.diff:      | NUMBER                                             /* Number literal */
       ;
   
  -csort
  -    : COLONCOLON csortname;                              /* Sort annotation */
  -
  -cdispatchCases
  -    : cterm (SEMI cterm)*                                /* Dispatch cases */
  +cvariable
  +    : VARIABLE<symbol> FUNCTIONAL? csortas?              /* Variable occurrence */
       ;
   
  -clist
  -    : LPAR term* RPAR                                    /* List of term */
  -    | LPAR ckv* RPAR                                     /* List of key-value pair */
  +csortas
  +    : AS csort                                           /* Sort annotation */
       ;
   
   ckv
  
positive.code:     | STRING COLON cterm                                 /* match named property value / construct    */
      ;
  
  /*  Sort declaration */
  
  csortparams
      : FORALL cvariable+ DOT                              /* Sort parameters. */
      ;
  
  csortset
      : LPAR csortkv* RPAR
      ;
  
  csortkv
      : constructor COLON cterm
      ;
  
  csortnames
      : csortname (COMMA csortname)*
      ;
  
  csortname
      : cconstructor csortargs?                            /* Concrete sort reference */
      | cvariable                                          /* Sort variable */
      ;
  
  csortargs
      : LSQUARE csortnames RSQUARE                         /*  */
      ;
  
  cforms
      : (cform SEMI)*
      ;
  
  cform
      : cconstructor csargs?
      | cvariable
      ;
  
  cconstructor
      : CONSTRUCTOR
      | COLON
  
negative.code: // Lexer rules
  
  DATA            : 'data';
  FN              : 'fn';
  RULE            : 'rule';
  AS              : 'as';
  COLON           : ':';
  ARROW           : '→';
  FORALL          : '∀';
  LPAR            : '(';
  RPAR            : ')';
  LCURLY          : '}';
  RCURLY          : '}';
  SEMI            : ';';
  COMMA           : ',';  
  DOT             : '.';
  NOT             : '¬'; 
  FUNCTIONAL      : 'ˢ';    
  
  // -- Common lexing rules with Crsx.g4.
  //    Cannot extract these rules yet as the antlr meta parser generator does not support modular grammars yet 
  
  CONSTRUCTOR     : StartConstructorChar ConstructorChar* // '$' is for internal use only.
                  | '<' [Other] ConstructorChar*;
  VARIABLE        : Lower (Lower | Digit | '-' | '_')*;
  
  METAVAR         : '#' (Alpha | Digit | '-' | '_' | Unicode)* Ebnf? Digit*; // '$' is for internal use only
  
  STRING          :  '"' ('\\"'|~'"')* '"';
  
  NUMBER          : Decimal;
  
  fragment StartConstructorChar : Upper | Other | UnicodeS;
  fragment ConstructorChar      : Alpha | Digit | Other | Unicode;
  
  fragment Digit    : [0-9];
  fragment Upper    : [A-Z];
  fragment Lower    : [a-z];
  fragment Alpha    : [a-zA-Z];
  fragment Decimal  : '-'? [0-9]+ ('.' [0-9]+)? | '.' [0-9]+;
  fragment Other    : '-' | [$_+/|`~!@^&*=?/>.:];
  fragment Unicode  : ~[\u0000-\u00FF\uD800-\uDBFF] | [\uD800-\uDBFF] [\uDC00-\uDFFF];
  fragment UnicodeS : ~[\u0000-\u00FF\uD800-\uDBFF\u27e6\u27e7\u27e8\u27e9] | [\uD800-\uDBFF] [\uDC00-\uDFFF];
  fragment Ebnf     : '*' | '?' | '+';
  
  WS               : [ \t\r\n\f]+ -> channel(HIDDEN) ;
  
  BLOCK_COMMENT    : '/*' .*? ('*/' | EOF)    -> channel(HIDDEN);
  LINE_COMMENT     : '//' ~[\r\n]*            -> channel(HIDDEN);