/****************************************************************************** * Initial */ initial module ; initial commands ; initial import ; initial type ; initial exp ; initial equationBlock ; module = (declaration (SEMICOLON declaration)*)? # Module ; commands = command? # OneCommand | commands SEMICOLON command # ManyCommands ; command = statement # StatementCommand | import # ImportCommand ; /****************************************************************************** * Declarations */ declarations = LBRACE (declaration (SEMICOLON declaration)*)? RBRACE # Declarations ; declaration = MODULE LBRACE (field (COMMA field)*)? RBRACE # ModuleHeader | var (COMMA var)* HASTYPE type # TypeAnnotation | bexp rhs # ValueDefinition | DATA ID+ (EQUALS constructor (BAR constructor)*)? # DataDefinition | TYPE ID+ EQUALS type # TypeDefinition | CLASS context? ID+ (BAR fundeps)? (WHERE declarations)? # ClassDefinition | INSTANCE context? ID atype+ (WHERE declarations)? # InstanceDefinition | DERIVING INSTANCE context? ID atype+ # DerivingInstanceDefinition | BEGIN_STRING END_STRING # DocumentationString | ANNOTATION_ID aexp* # Annotation | (INFIX | INFIXL | INFIXR) INTEGER var (COMMA var)* # PrecedenceDefinition | import # JustImport | IMPORTJAVA BEGIN_STRING END_STRING WHERE declarations # ImportJava | EFFECT ID BEGIN_STRING END_STRING BEGIN_STRING END_STRING # EffectDefinition | (RULE | ABSTRACT_RULE) ID (EXTENDS ID (COMMA ID)*)? WHERE ruleDeclarations # RuleDefinition | MAPPING_RELATION ID atype* # MappingRelationDefinition | bexp FOLLOWS ruleDeclarations # RelationDefinition | RULESET ID WHERE statements # RulesetDefinition ; import = (IMPORT | INCLUDE) BEGIN_STRING END_STRING (AS ID)? importSpec? # Import ; importSpec = LPAREN (importItem (COMMA importItem)*)? RPAREN # ImportShowing | HIDING LPAREN (importItem (COMMA importItem)*)? RPAREN # ImportHiding ; importItem = ID # ImportValueItem // | (TYPE | DATA) ID # ImportTypeItem // | CLASS ID # ImportClassItem ; constructor = (ANNOTATION_ID aexp)* ID atype* # Constructor | (ANNOTATION_ID aexp)* ID LBRACE fieldDeclaration (COMMA fieldDeclaration)* RBRACE # RecordConstructor ; fieldDeclaration = ID HASTYPE type # FieldDescription ; rhs = EQUALS exp (WHERE statements)? # SimpleRhs | guardedExpEq+ (WHERE statements)? # GuardedRhs ; guardedExpEq = BAR exp (COMMA exp)* EQUALS exp # GuardedExpEq ; fundep = ID+ ARROW ID # Fundep ; fundeps = fundep (COMMA fundep)* # Fundeps ; /****************************************************************************** * Rules */ ruleDeclarations = LBRACE (ruleDeclaration (SEMICOLON ruleDeclaration)*)? RBRACE # RuleDeclarations ; ruleDeclaration = query # QueryRuleDeclaration | ANNOTATION_ID aexp* # Annotation ; /****************************************************************************** * Expressions */ exp = bexp (HASTYPE type)? # LocalTypeAnnotation, shift HASTYPE, shift COLON ; bexp = MINUS? lexp (symbol lexp)* # Binary, shift MINUS, shift SYMBOL, shift LESS, shift GREATER, shift SEPARATED_DOT, shift ESCAPED_ID ; lexp = faexp+ # Apply, shift ID, shift LAMBDA, shift LAMBDA_MATCH, shift LET, shift INTEGER, shift BEGIN_STRING, shift IF, shift MATCH, shift DO, shift MDO, shift EDO, shift ENFORCE, shift BLANK, shift FLOAT, shift LPAREN, shift LBRACKET, shift ESCAPED_SYMBOL, shift CHAR, shift LBRACE, shift WHEN, shift ATTACHED_HASH, shift SELECT, shift SELECT_FIRST, shift SELECT_DISTINCT, shift TRANSFORMATION, shift EQ, shift CHR_SELECT ; faexp = aexp ((ATTACHED_DOT | ATTACHED_HASH) accessor)* # FieldAccess, shift ATTACHED_DOT, shift ATTACHED_HASH ; accessor = ID # IdAccessor | BEGIN_STRING END_STRING # StringAccessor | LPAREN exp RPAREN # ExpAccessor ; aexp = LAMBDA aexp+ ARROW exp # Lambda, shift HASTYPE | LAMBDA_MATCH LBRACE case (SEMICOLON case)* RBRACE # LambdaMatch, shift HASTYPE | LET statements IN exp # Let, shift HASTYPE | IF exp THEN exp (ELSE exp)? # If, shift HASTYPE, shift ELSE | MATCH exp WITH LBRACE case (SEMICOLON case)* RBRACE # Match | (DO | MDO | EDO) statements # Do | (SELECT | SELECT_FIRST | SELECT_DISTINCT) exp WHERE queryBlock # Select | CHR_SELECT exp WHERE verboseChrQuery # CHRSelect | ENFORCE queryBlock # Enforce //| WHEN queryBlock SEMICOLON exp # When | var # Var | ATTACHED_HASH ID # HashedId | BLANK # Blank | INTEGER # Integer | FLOAT # Float | stringLiteral # String | CHAR # Char | LPAREN (exp (COMMA exp)*)? RPAREN # Tuple | LPAREN exp ARROW exp RPAREN # ViewPattern | LPAREN symbolWithoutMinus lexp RPAREN # RightSection | LPAREN lexp symbol RPAREN # LeftSection | LBRACKET (exp (COMMA exp)*)? RBRACKET # ListLiteral | LBRACKET exp DOTDOT exp RBRACKET # Range | LBRACKET exp BAR listQualifier (COMMA listQualifier)* RBRACKET # ListComprehension | ID AT aexp # As | ID LBRACE (field (COMMA field)*)? RBRACE # Record | TRANSFORMATION ID WHERE queryBlock # Transformation | EQ LBRACE equationBlock RBRACE # Eq ; stringLiteral = BEGIN_STRING (SUSPEND_STRING exp CONTINUE_STRING)* END_STRING # StringLiteral ; statements = LBRACE (statement (SEMICOLON statement)*)? RBRACE # Statements ; statement = exp # GuardStatement | exp rhs # LetStatement | exp BINDS exp # BindStatement | exp FOLLOWS queryBlock # RuleStatement | chrQuery IMPLIES chrQuery # CHRStatement | WHEN verboseChrQuery THEN_AFTER_WHEN verboseChrQuery # VerboseCHRStatement | CONSTRAINT constructor # ConstraintStatement | INCLUDE ID aexp # LocalInclude ; verboseChrQuery = LBRACE chrQuery (SEMICOLON chrQuery)* RBRACE # VerboseCHRConjunction ; chrQuery = chrQueryPart (COMMA chrQueryPart)* # CHRConjunction ; chrQueryPart = exp # CHRAtom | exp EQUALS exp # CHREquals | exp BINDS exp # CHRBinds ; listQualifier = exp # GuardQualifier | exp EQUALS exp # LetQualifier | exp BINDS exp # BindQualifier | THEN exp (BY exp)? # ThenQualifier ; case = exp caseRhs # Case ; caseRhs = ARROW exp (WHERE statements)? # SimpleCaseRhs | guardedExpArrow+ (WHERE statements)? # GuardedCaseRhs ; guardedExpArrow = BAR exp (COMMA exp)* ARROW exp # GuardedExpArrow ; field = ID EQUALS exp # Field | ID # FieldShorthand ; /****************************************************************************** * Queries */ queryBlock = LBRACE (query (SEMICOLON query)*)? RBRACE # QueryBlock ; query = exp # GuardQuery, shift BINDS, shift EQUALS | exp EQUALS exp # EqualsQuery | exp BINDS exp # BindQuery | QUERY_OP queryBlock # CompositeQuery ; /****************************************************************************** * Equations */ equationBlock = (equation (SEMICOLON equation)*)? # EquationBlock ; equation = exp # GuardEquation | exp EQUALS exp # BasicEquation ; /****************************************************************************** * Types */ context = LPAREN type (COMMA type)* RPAREN IMPLIES # Context ; type = etype ((ARROW | IMPLIES) etype)* # Arrow, shift ARROW, shift IMPLIES ; etype = LESS ID (COMMA ID)* GREATER btype # Effect | btype # JustEtype | FORALL ID+ (SEPARATED_DOT | ATTACHED_DOT) type # ForAll ; btype = atype+ # ApplyType, shift ID, shift LPAREN, shift LBRACKET ; atype = ID # TypeVar | LPAREN (type (COMMA type)*)? RPAREN # TupleType | LBRACKET type RBRACKET # ListType | LBRACKET RBRACKET # ListTypeConstructor | LPAREN COMMA+ RPAREN # TupleTypeConstructor ; /****************************************************************************** * Variables and symbols */ var = ID # VarId | ESCAPED_SYMBOL # EscapedSymbol | LPAREN COMMA+ RPAREN # TupleConstructor ; symbol = SYMBOL # Symbol | ESCAPED_ID # EscapedId | MINUS # Minus | LESS # Less | GREATER # Greater | SEPARATED_DOT # Dot ; symbolWithoutMinus = SYMBOL # Symbol | ESCAPED_ID # EscapedId | LESS # Less | GREATER # Greater | SEPARATED_DOT # Dot ; /****************************************************************************** * Auxiliary tokens */ dummy = COMMENT EOL # Dummy ;