diff options
Diffstat (limited to 'Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver')
7 files changed, 294 insertions, 0 deletions
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2 b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2 new file mode 100644 index 00000000..7f95e737 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2 | |||
@@ -0,0 +1,49 @@ | |||
1 | module org.eclipse.viatra.solver.language.GenerateSolverLanguage | ||
2 | |||
3 | import org.eclipse.xtext.xtext.generator.* | ||
4 | import org.eclipse.xtext.xtext.generator.model.project.* | ||
5 | |||
6 | var rootPath = ".." | ||
7 | |||
8 | Workflow { | ||
9 | |||
10 | component = XtextGenerator { | ||
11 | configuration = { | ||
12 | project = StandardProjectConfig { | ||
13 | baseName = "org.eclipse.viatra.solver.language" | ||
14 | rootPath = rootPath | ||
15 | runtimeTest = { | ||
16 | enabled = true | ||
17 | } | ||
18 | eclipsePlugin = { | ||
19 | enabled = true | ||
20 | } | ||
21 | eclipsePluginTest = { | ||
22 | enabled = true | ||
23 | } | ||
24 | createEclipseMetaData = true | ||
25 | } | ||
26 | code = { | ||
27 | encoding = "UTF-8" | ||
28 | lineDelimiter = "\r\n" | ||
29 | fileHeader = "/*\n * generated by Xtext \${version}\n */" | ||
30 | } | ||
31 | } | ||
32 | language = StandardLanguage { | ||
33 | name = "org.eclipse.viatra.solver.language.SolverLanguage" | ||
34 | fileExtensions = "vsc" | ||
35 | |||
36 | serializer = { | ||
37 | generateStub = false | ||
38 | } | ||
39 | validator = { | ||
40 | // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" | ||
41 | // Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage | ||
42 | generateDeprecationValidation = true | ||
43 | } | ||
44 | junitSupport = { | ||
45 | junitVersion = "5" | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext new file mode 100644 index 00000000..17a329ad --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext | |||
@@ -0,0 +1,154 @@ | |||
1 | grammar org.eclipse.viatra.solver.language.SolverLanguage with org.eclipse.xtext.common.Terminals | ||
2 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore | ||
3 | generate solverLanguage "http://www.eclipse.org/viatra/solver/language/SolverLanguage" | ||
4 | |||
5 | Problem: | ||
6 | statements+=Statement*; | ||
7 | Statement: Interpretation | Predicate; | ||
8 | |||
9 | @Override terminal STRING returns ecore::EString: '"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"'; | ||
10 | REALLiteral returns ecore::EBigDecimal: '-'? INT '.' INT; | ||
11 | INTLiteral returns ecore::EInt: '-'? INT; | ||
12 | BooleanValue: {BooleanTrue} 'true' | 'false' {BooleanFalse}; | ||
13 | TruthValue: {True} 'true' | {False} 'false' | {Unknown} 'unknown' | {Error} 'error' ; | ||
14 | |||
15 | |||
16 | /////////////////// | ||
17 | // Core grammar | ||
18 | /////////////////// | ||
19 | Interpretation: BasicInterpretation | DefaultInterpretation | CDInterpretation; | ||
20 | |||
21 | BasicInterpretation: symbol=Symbol '(' objects+=ComplexObject* ')' ':' value = TruthValue; | ||
22 | |||
23 | Symbol: ModelSymbol | PartialitySymbol | DataSymbol; | ||
24 | |||
25 | ModelSymbol: name = ID; | ||
26 | |||
27 | PartialitySymbol: ExistSymbol | EqualsSymbol; | ||
28 | ExistSymbol:'exists'{ExistSymbol}; | ||
29 | EqualsSymbol:'equals' {EqualsSymbol}; | ||
30 | |||
31 | DataSymbol: BooleanSymbol | IntegerSymbol | RealSymbol | StringSymbol; | ||
32 | BooleanSymbol:'bool' {BooleanSymbol}; | ||
33 | IntegerSymbol:'int' {IntegerSymbol}; | ||
34 | RealSymbol: 'real' {RealSymbol}; | ||
35 | StringSymbol:'string' {StringSymbol}; | ||
36 | |||
37 | ComplexObject: Object | AllInstances | AllObjects; | ||
38 | |||
39 | Object: NamedObject | UnnamedObject | DataObject; | ||
40 | NamedObject: "'" name = ID "'"; | ||
41 | UnnamedObject: name = ID; | ||
42 | DataObject: BooleanObject | IntObject | RealObject | StringObject; | ||
43 | BooleanObject: value = BooleanValue; | ||
44 | IntObject: value = INTLiteral; | ||
45 | RealObject: value = REALLiteral; | ||
46 | StringObject: value = STRING; | ||
47 | |||
48 | /////////////////// | ||
49 | // Predicte grammar | ||
50 | /////////////////// | ||
51 | Predicate: PredicateSymbol | ErrorPredicate; | ||
52 | PredicateSymbol: | ||
53 | 'predicate' symbol = ModelSymbol '(' parameters += Parameter* ')' ':' ('false' | (bodies += PatternBody ('|' bodies += PatternBody)*)) '.' | ||
54 | ; | ||
55 | ErrorPredicate: | ||
56 | {ErrorPredicate} 'error' (name = ID)? ('(' parameters += Parameter* ')') ':' ('false' | (bodies += PatternBody ('|' bodies += PatternBody)*)) '.' | ||
57 | ; | ||
58 | |||
59 | Parameter: variable = Variable (':' type = Symbol)?; | ||
60 | PatternBody: {PatternBody} ('true' | constraints += Constraint*) ; | ||
61 | Polarity: {Positive} '+' | {Negative} '-'; | ||
62 | Constraint: (polarity = Polarity)? symbol = ModelSymbol ( | ||
63 | ( '(' params += Literal* ')') | (closureType = ClosureType '(' params += Literal params += Literal ')')); | ||
64 | |||
65 | ClosureType: {ReflexiveClosure} '*' | {IrreflexiveClosure} '+'; | ||
66 | Literal: Variable | DataObject; | ||
67 | Variable: name = ID; | ||
68 | |||
69 | /////////////////// | ||
70 | // Complex Interpretation grammar | ||
71 | /////////////////// | ||
72 | |||
73 | AllInstances: ':' symbol = Symbol; | ||
74 | AllObjects: {AllObjects} '*'; | ||
75 | |||
76 | /////////////////// | ||
77 | // Defaul Interpretation grammar | ||
78 | /////////////////// | ||
79 | DefaultInterpretation: 'default' interpretation = BasicInterpretation; | ||
80 | |||
81 | /////////////////// | ||
82 | // Advanced Class-Diagram interpretations | ||
83 | /////////////////// | ||
84 | CDInterpretation: ClassInterpretation | EnumInterpretation| GlobalRelationInterpretation; | ||
85 | ClassInterpretation: | ||
86 | abstract?='abstract' 'class' symbol = ModelSymbol ('extends' supertypes += ModelSymbol+)?'{' | ||
87 | fielt += FieldRelationInterpretation* | ||
88 | '}' | ||
89 | ; | ||
90 | EnumInterpretation: 'enum' Symbol = ModelSymbol '{' objects+=NamedObject+ '}'; | ||
91 | FieldRelationInterpretation: containment ?= 'containment' symbol = ModelSymbol ':' multiplicity = MultiplicityDefinition? target = Symbol; | ||
92 | GlobalRelationInterpretation: containment ?= 'containment' 'relation' symbol = ModelSymbol ':' sourceMultiplicity = MultiplicityDefinition? source = Symbol targetMultiplicity = MultiplicityDefinition? target = Symbol; | ||
93 | MultiplicityDefinition: lower = INT '..' (upper = INT | unlimitedUpper?='*'); | ||
94 | |||
95 | ////SymbolIntroduction : Type | GlobalRelation | Predicate; | ||
96 | ////Symbol: Type | Relation | Predicate | Variable | Element; | ||
97 | // | ||
98 | ////////////////////// | ||
99 | //// Types | ||
100 | ////////////////////// | ||
101 | // | ||
102 | //Type: TypeDeclaration | /*TypeDefinition |*/ TypeEnumeration; | ||
103 | // | ||
104 | //TypeDeclaration: | ||
105 | // abstract?= 'abstract' 'class' name = ID ('extends' supertypes += [Type] (',' supertypes += [Type])) '{' | ||
106 | // fieldDeclarations += FieldRelationDeclaration* | ||
107 | // '}' | ||
108 | //; | ||
109 | //TypeEnumeration: | ||
110 | // 'enum' name = ID 'extends' supertypes += [Type] (',' supertypes += [Type]) '{' | ||
111 | // (elements += Element)* | ||
112 | // '}' | ||
113 | //; | ||
114 | //Element: | ||
115 | // name = ID | ||
116 | //; | ||
117 | // | ||
118 | ////////////////////// | ||
119 | //// Relations | ||
120 | ////////////////////// | ||
121 | // | ||
122 | //Relation: FieldRelationDeclaration | GlobalRelationDeclaration | RelationEnumeration; | ||
123 | //GlobalRelation returns Relation: GlobalRelationDeclaration | /*RelationDefinition |*/ RelationEnumeration; | ||
124 | // | ||
125 | //FieldRelationDeclaration: | ||
126 | // containment?='containment' target = [Type] name = ID | ||
127 | //; | ||
128 | // | ||
129 | //GlobalRelationDeclaration: | ||
130 | // containment?='containment' 'relation' name = ID '(' source = [Type] ',' target = [Type] ')' | ||
131 | //; | ||
132 | // | ||
133 | //RelationEnumeration: | ||
134 | // 'relation' name = ID '{' links += Link* '}' | ||
135 | //; | ||
136 | // | ||
137 | //Link: '(' source = Element ',' target = Element ')'; | ||
138 | // | ||
139 | // | ||
140 | // | ||
141 | // | ||
142 | // | ||
143 | // | ||
144 | //Model: | ||
145 | // 'model' '{' | ||
146 | // atoms += Atom (',' atoms += Atom ) | ||
147 | // '}' | ||
148 | //; | ||
149 | //Atom: referredSymbol = [Symbol] '(' (params += Element (',' params += Element)*)? ')'; | ||
150 | // | ||
151 | //ScopeDeclaration: | ||
152 | // 'scope' | ||
153 | //; | ||
154 | // | ||
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguageRuntimeModule.xtend b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguageRuntimeModule.xtend new file mode 100644 index 00000000..343bc48a --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguageRuntimeModule.xtend | |||
@@ -0,0 +1,11 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language | ||
5 | |||
6 | |||
7 | /** | ||
8 | * Use this class to register components to be used at runtime / without the Equinox extension registry. | ||
9 | */ | ||
10 | class SolverLanguageRuntimeModule extends AbstractSolverLanguageRuntimeModule { | ||
11 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguageStandaloneSetup.xtend b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguageStandaloneSetup.xtend new file mode 100644 index 00000000..1ce7b1d8 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguageStandaloneSetup.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language | ||
5 | |||
6 | |||
7 | /** | ||
8 | * Initialization support for running Xtext languages without Equinox extension registry. | ||
9 | */ | ||
10 | class SolverLanguageStandaloneSetup extends SolverLanguageStandaloneSetupGenerated { | ||
11 | |||
12 | def static void doSetup() { | ||
13 | new SolverLanguageStandaloneSetup().createInjectorAndDoEMFRegistration() | ||
14 | } | ||
15 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/generator/SolverLanguageGenerator.xtend b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/generator/SolverLanguageGenerator.xtend new file mode 100644 index 00000000..0b8620e9 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/generator/SolverLanguageGenerator.xtend | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.generator | ||
5 | |||
6 | import org.eclipse.emf.ecore.resource.Resource | ||
7 | import org.eclipse.xtext.generator.AbstractGenerator | ||
8 | import org.eclipse.xtext.generator.IFileSystemAccess2 | ||
9 | import org.eclipse.xtext.generator.IGeneratorContext | ||
10 | |||
11 | /** | ||
12 | * Generates code from your model files on save. | ||
13 | * | ||
14 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation | ||
15 | */ | ||
16 | class SolverLanguageGenerator extends AbstractGenerator { | ||
17 | |||
18 | override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { | ||
19 | // fsa.generateFile('greetings.txt', 'People to greet: ' + | ||
20 | // resource.allContents | ||
21 | // .filter(Greeting) | ||
22 | // .map[name] | ||
23 | // .join(', ')) | ||
24 | } | ||
25 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/scoping/SolverLanguageScopeProvider.xtend b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/scoping/SolverLanguageScopeProvider.xtend new file mode 100644 index 00000000..6b92897c --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/scoping/SolverLanguageScopeProvider.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.scoping | ||
5 | |||
6 | |||
7 | /** | ||
8 | * This class contains custom scoping description. | ||
9 | * | ||
10 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping | ||
11 | * on how and when to use it. | ||
12 | */ | ||
13 | class SolverLanguageScopeProvider extends AbstractSolverLanguageScopeProvider { | ||
14 | |||
15 | } | ||
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend new file mode 100644 index 00000000..a7ff7252 --- /dev/null +++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/validation/SolverLanguageValidator.xtend | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.18.0.M3 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.validation | ||
5 | |||
6 | |||
7 | /** | ||
8 | * This class contains custom validation rules. | ||
9 | * | ||
10 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation | ||
11 | */ | ||
12 | class SolverLanguageValidator extends AbstractSolverLanguageValidator { | ||
13 | |||
14 | // public static val INVALID_NAME = 'invalidName' | ||
15 | // | ||
16 | // @Check | ||
17 | // def checkGreetingStartsWithCapital(Greeting greeting) { | ||
18 | // if (!Character.isUpperCase(greeting.name.charAt(0))) { | ||
19 | // warning('Name should start with a capital', | ||
20 | // SolverLanguagePackage.Literals.GREETING__NAME, | ||
21 | // INVALID_NAME) | ||
22 | // } | ||
23 | // } | ||
24 | |||
25 | } | ||