MatchPattern.g4 2.53 KB
Newer Older
Alexander Weigl's avatar
Alexander Weigl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
grammar MatchPattern;

/* Examples for testing

f(x)
f(x,y,g(y))
X
?Y
_
...
f(... ?X ...)
f(..., ?X)
f(..., ...?X...)
f(..., ... g(x) ...)
f(_, x, _, y, ... y ...)
*/
17

Alexander Weigl's avatar
Alexander Weigl committed
18 19 20
sequentPattern : antec=semiSeqPattern? ARROW succ=semiSeqPattern? #sequentArrow
               | anywhere=semiSeqPattern #sequentAnywhere
               ;
21

22
semiSeqPattern : termPattern (',' termPattern)*;
23

Alexander Weigl's avatar
Alexander Weigl committed
24
termPattern :
25 26 27 28
      termPattern MUL termPattern                               #mult
    | <assoc=right> termPattern op=(DIV|MOD) termPattern        #divMod
    | termPattern op=(PLUS|MINUS) termPattern                   #plusMinus
    | termPattern op=(LE|GE|LEQ|GEQ) termPattern                #comparison
Sarah Grebing's avatar
Sarah Grebing committed
29
    | termPattern op=(NEQ|EQ) termPattern                       #equality
30 31 32 33
    | termPattern AND termPattern                               #and
    | termPattern OR termPattern                                #or
    | termPattern IMP termPattern                               #impl
    | termPattern XOR termPattern                               #xor
Sarah Grebing's avatar
Sarah Grebing committed
34
    | termPattern EQUIV termPattern                             #equivalence
35 36
    | MINUS termPattern                                         #exprNegate
    | NOT termPattern                                           #exprNot
Alexander Weigl's avatar
Alexander Weigl committed
37 38 39
    | '(' termPattern ')' bindClause?                                      #exprParen
    | func=ID ( '(' termPattern (',' termPattern)* ')')? bindClause?        #function
    |  DONTCARE   bindClause?                                              #dontCare
40 41 42 43 44 45
    //| STARDONTCARE  #starDontCare
    | SID                                                       #schemaVar
    | STARDONTCARE termPattern STARDONTCARE                     #anywhere
    | DIGITS                                                    #number
    // not working because of ambigue | left=termPattern op=(PLUS|MINUS|MUL|LE|GE|LEQ|GEQ|NEQ|EQ| AND|OR|IMP) right=termPattern #binaryOperation
    ;
46

Alexander Weigl's avatar
Alexander Weigl committed
47 48 49
/*
f(x), f(x,y,g(y)), X, ?Y, _, ..., f(... ?X ...), f(..., ?X), f(..., ...?X...), f(..., ... g(x) ...), f(_, x, _, y, ... y ...)
*/
50

Alexander Weigl's avatar
Alexander Weigl committed
51
bindClause : ('\\as' | ':') SID;
Alexander Weigl's avatar
Alexander Weigl committed
52 53 54 55

ARROW : '⇒' | '==>';
DONTCARE: '?' | '_' | '█';
STARDONTCARE: '...' | '…';
56 57 58 59 60 61 62 63
PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
DIV : '/' ;
EQ : '=' ;
NEQ : '!=' ;
GEQ : '>=' ;
LEQ : '<=' ;
64
EQUIV : '<->';
65 66 67 68
GE : '>' ;
LE : '<' ;
AND : '&' ;
OR: '|' ;
69
IMP: '->';
70 71
MOD:'%';
XOR:'^';
Alexander Weigl's avatar
Alexander Weigl committed
72 73
FORALL: '\forall' | '∀';
EXISTS: '\exists';
74 75 76 77 78

DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ;
SID: '?' [_a-zA-Z0-9\\]+ ;
ID : [a-zA-Z\\_] ([_a-zA-Z0-9\\])*;
79

Alexander Weigl's avatar
Alexander Weigl committed
80
COMMENT: '//' ~[\n\r]* -> channel(HIDDEN);
81
WS: [\n\f\r\t ] -> channel(HIDDEN);