MatchPattern.g4 1.91 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
23
24
25
26
termPattern :
	   DONTCARE      #dontCare
	 //| STARDONTCARE  #starDontCare
	 | SID           #schemaVar
	 | STARDONTCARE termPattern STARDONTCARE #anywhere
27
	 | DIGITS #number
Alexander Weigl's avatar
Alexander Weigl committed
28
	 | func=ID ( '(' termPattern (',' termPattern)* ')')? #function
29
	 | left=termPattern op=(PLUS|MINUS|MUL|LE|GE|LEQ|GEQ|NEQ|EQ| AND|OR|IMP) right=termPattern #binaryOperation
Alexander Weigl's avatar
Alexander Weigl committed
30
	 ;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

	 /*
	       expression MUL expression #exprMultiplication
         | <assoc=right> expression DIV expression #exprDivision
         | expression op=(PLUS|MINUS) expression #exprLineOperators
         | expression op=(LE|GE|LEQ|GEQ) expression #exprComparison
         | expression op=(NEQ|EQ) expression  #exprEquality
         | expression AND expression   #exprAnd
         | expression OR expression    #exprOr
         | expression IMP expression   #exprIMP
         //|   expression EQUIV expression already covered by EQ/NEQ
         | expression LBRACKET substExpressionList RBRACKET #exprSubst
         | MINUS expression   #exprNegate
         | NOT expression  #exprNot
         | '(' expression ')' #exprParen
	 */
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
52
53
54
55
56
57

ARROW : '⇒' | '==>';
DONTCARE: '?' | '_' | '█';
STARDONTCARE: '...' | '…';
DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ;
SID: '?' [_a-zA-Z0-9\\]+ ;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
ID : [a-zA-Z\\_] ([_a-zA-Z0-9\\])*;


PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
DIV : '/' ;
EQ : '=' ;
NEQ : '!=' ;
GEQ : '>=' ;
LEQ : '<=' ;
GE : '>' ;
LE : '<' ;
AND : '&' ;
OR: '|' ;
73
IMP: '->';
74

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