|
Re: How to validate through all objects [message #1804413 is a reply to message #1804307] |
Mon, 25 March 2019 19:15 |
|
i am not sure if i can follow you. but if you want to check multiple enrolls you should do so
@Check
def checkDuplicateCourseEnrollement(Model model) {
val names = HashMultimap.<String,String>create;
for (enroll : model.model.filter(Enroll))
for (i : enroll.students)
if (!names.put(enroll.course.name, i.name))
error("Duplicate entry: " + "\'" + i.name + "\'!", enroll, MyDslPackage.Literals.ENROLL__STUDENTS,
enroll.students.lastIndexOf(i));
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: How to validate through all objects [message #1805189 is a reply to message #1804307] |
Tue, 09 April 2019 14:43 |
Željko Kovačević Messages: 16 Registered: March 2019 |
Junior Member |
|
|
Hi!
I would like to ask for help regarding code generator for the grammar I already posted.
For generator, I wrote this method:
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
fsa.generateFile("generator.txt", '''
«FOR student : resource.allContents.filter(Student).toIterable»
Student «student.name»("«student.firstName»", "«student.lastName»", «student.ageOfBirth», "«student.faculty»");
«ENDFOR»
«FOR course : resource.allContents.filter(Course).toIterable»
Course «course.name»(«course.ects»«FOR student : course.students», «student.name»«ENDFOR»);
«ENDFOR»
''')
}
For the following application
Program StudentDSL_Test;
START
Course English (ECTS 6);
Student John ("John" "Johnston" born in 2000) studies Computing;
Course Mathematics (ECTS 0) enroll John;
Student Mark ("Mark" "Markston" born in 2002) studies Informatics;
FINISH
it will generate:
Student John("John", "Johnston", 2000, "Computing");
Student Mark("Mark", "Markston", 2002, "Informatics");
Course English(6);
Course Mathematics(0, John);
The result is as expected; first Student code is generated and then Course code. BUT, how do I rewrite my generator example to respect the order of created objects? In the DSL example above, I would like to have the following generated code:
Course English(6);
Student John("John", "Johnston", 2000, "Computing");
Course Mathematics(0, John);
Student Mark("Mark", "Markston", 2002, "Informatics");
I suspect I need to iterate through StudentDSL, but don't know how..
[Updated on: Tue, 09 April 2019 14:46] Report message to a moderator
|
|
|
|
Re: How to validate through all objects [message #1805192 is a reply to message #1805190] |
Tue, 09 April 2019 16:18 |
Željko Kovačević Messages: 16 Registered: March 2019 |
Junior Member |
|
|
Ok. I did this:
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
val root = resource.contents.get(0) as StudentDSL;
fsa.generateFile("generator.txt", '''
«FOR i : root.studentDSL»
«i.eClass.name»
«ENDFOR»
''')
}
This gives object types in correct order. But, I don't know how to access object name and its attributes like firstName, secondName etc.?
[Updated on: Tue, 09 April 2019 16:18] Report message to a moderator
|
|
|
|
|
|
|
|
Re: How to validate through all objects [message #1805203 is a reply to message #1805201] |
Tue, 09 April 2019 19:33 |
Željko Kovačević Messages: 16 Registered: March 2019 |
Junior Member |
|
|
Please let me revise:
Grammar:
StudentDSL:
'Program' name=ID ';'
'START'
studentDSL+=(Student | Course | Enroll)*
'FINISH'
;
Student:
'Student' name=ID
// personal info
'(' firstName=STRING lastName=STRING 'born' 'in' ageOfBirth=INT ')'
// student faculty - only fixed choices
'studies' faculty=('Informatics' | 'Computing' | 'Electrotehnics') ';'
;
Course:
'Course' name=ID
// how many ECTS?
'(' 'ECTS' ects=INT ')'
// enroll students (optional)
('enroll' students+=[Student](',' students+=[Student])*)?
';'
;
Enroll:
'Enroll' students+=[Student](',' students+=[Student])* 'to' course=[Course] ';'
;
This is the test DSL application:
Program StudentDSL_Test;
START
Student John ("John" "Johnston" born in 2000) studies Computing;
Course English (ECTS 6);
Student Mark ("Mark" "Markston" born in 2002) studies Informatics;
Course Mathematics (ECTS 0) enroll John;
Enroll John, Mark to Mathematics;
FINISH
And this is what I am trying to get with the code generator:
Student John("John", "Johnston", 2000, "Computing");
Course English(6);
Student Mark("Mark", "Markston", 2002, "Informatics");
Course Mathematics(0, John);
Mathematics.Enroll(John, Mark);
I appreciate your time & help :) Please let me know if you need me to clarify anything else.
[Updated on: Tue, 09 April 2019 19:34] Report message to a moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05900 seconds