aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language/src/main/java/org/eclipse/viatra/solver/language/Problem.xtext
blob: 2d4eb1b92e55cd87ba644522a61d1e18f0a60233 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
grammar org.eclipse.viatra.solver.language.Problem with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.eclipse.org/viatra/solver/language/model/Problem"

Problem:
	("problem" name=ID ".")?
	statements+=Statement*;

Statement:
	ClassDeclaration | PredicateDefinition | Assertion | ScopeDeclaration;

ClassDeclaration:
	abstract?="abstract"? "class"
	name=ID
	("extends" superTypes+=[ClassDeclaration|QualifiedName] ("," superTypes+=[ClassDeclaration|QualifiedName])*)?
	("{" (referenceDeclarations+=ReferenceDeclaration ";"?)* "}" | ".");

ReferenceDeclaration:
	(containment?="contains" | "refers")
	referenceType=[ClassDeclaration|QualifiedName]
	("[" multiplicity=Multiplicity "]")?
	name=ID
	("opposite" opposite=[ReferenceDeclaration|QualifiedName])?;

PredicateDefinition:
	(error?="error" "pred"? | "pred")
	name=ID
	"(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")"
	(":-" bodies+=Conjunction (";" bodies+=Conjunction)*)?
	".";

Parameter:
	parameterType=[ClassDeclaration] name=ID;

Conjunction:
	literals+=Literal ("," literals+=Literal)*;

Literal:
	Atom | NegativeLiteral;

NegativeLiteral:
	"!" atom=Atom;

Atom:
	relation=[Relation|QualifiedName]
	transitiveClosure?="+"?
	"(" (arguments+=Argument ("," arguments+=Argument)*)? ")";

Argument:
	variable=[Variable];

Assertion:
	(relation=[Relation|QualifiedName]
	"(" (arguments+=[Node|QualifiedName] ("," arguments+=[Node|QualifiedName])*)? ")"
	":" value=LogicValue |
	value=ShortLogicValue?
	relation=[Relation|QualifiedName]
	"(" (arguments+=[Node|QualifiedName] ("," arguments+=[Node|QualifiedName])*)? ")")
	".";

enum LogicValue:
	TRUE="true" | FALSE="false" | UNKNOWN="unknown";

enum ShortLogicValue returns LogicValue:
	FALSE="!" | UNKNOWN="?";

ScopeDeclaration:
	"scope" typeScopes+=TypeScope ("," typeScopes+=TypeScope)* ".";

TypeScope:
	targetType=[ClassDeclaration]
	(increment?="+=" | "=")
	multiplicity=DefiniteMultiplicity;

Multiplicity:
	UnboundedMultiplicity | DefiniteMultiplicity;

DefiniteMultiplicity returns Multiplicity:
	RangeMultiplicity | ExactMultiplicity;

UnboundedMultiplicity:
	{UnboundedMultiplicity};

RangeMultiplicity:
	lowerBound=INT ".." upperBound=UpperBound;

ExactMultiplicity:
	exactValue=INT;

UpperBound returns ecore::EInt:
	INT | "*";

QualifiedName:
	QUOTED_ID | ID (":" ID)* (":" QUOTED_ID)?;

@Override
terminal STRING: '"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"';

terminal QUOTED_ID: "'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'";