MatchPattern.g4 2.34 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
18
19

sequentPattern : antec=semiSeqPattern? ARROW succ=semiSeqPattern? | anywhere=semiSeqPattern;

20
semiSeqPattern : termPattern (',' termPattern)*;
21

Alexander Weigl's avatar
Alexander Weigl committed
22
termPattern :
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
      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
    | termPattern op=(NEQ|EQ) termPattern                       #equality
    | termPattern AND termPattern                               #and
    | termPattern OR termPattern                                #or
    | termPattern IMP termPattern                               #impl
    | termPattern XOR termPattern                               #xor
    //|   termPattern EQUIV termPattern already covered by EQ/NEQ
    | MINUS termPattern                                         #exprNegate
    | NOT termPattern                                           #exprNot
    | '(' termPattern ')'                                       #exprParen
    | func=ID ( '(' termPattern (',' termPattern)* ')')?        #function
    |  DONTCARE                                                 #dontCare
    //| 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
    ;
44

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

Alexander Weigl's avatar
Alexander Weigl committed
49
50
51
52

ARROW : '⇒' | '==>';
DONTCARE: '?' | '_' | '█';
STARDONTCARE: '...' | '…';
53
54
55
56
57
58
59
60
61
62
63
64
PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
DIV : '/' ;
EQ : '=' ;
NEQ : '!=' ;
GEQ : '>=' ;
LEQ : '<=' ;
GE : '>' ;
LE : '<' ;
AND : '&' ;
OR: '|' ;
65
IMP: '->';
66
67
68
69
70
71
72
MOD:'%';
XOR:'^';

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

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