From: Mart Lubbers Date: Tue, 17 Nov 2015 12:11:47 +0000 (+0100) Subject: finished dsl assignment 1 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=10fff8b308d986b564ee17eaad78e68ce105823e;p=des2015.git finished dsl assignment 1 --- diff --git a/dsl/specs/spec1.tdsl b/dsl/specs/spec1.tdsl new file mode 100644 index 0000000..5f48e2b --- /dev/null +++ b/dsl/specs/spec1.tdsl @@ -0,0 +1,38 @@ +/* The first part specifies the robot specific information such as + * which sensor is plugged in which port. */ +Name MartNatanael +Acceleration 10000 +Speed 200 +LeftMotor plugged in A +RightMotor plugged in D +ColorSensor plugged in S1 +TouchSensor plugged in S2 and S3 +UltrasoneSensor plugged in S4 +/* After the static part you can specify one or more missions + * Every mission is a list of behaviours in the order of priority + * and a stopping condition. + */ +Mission: + /* All behaviours have an action and possibly a take control predicate + * When the take control predicate is not specified the behaviour will + * always try to take control. + */ + Behaviour + Name: DontFallOff + TakeControl: ColorLimit: Black + Action: Avoid + Behaviour + Name: AvoidLowObjects + TakeControl: TouchStatus: Touch + Action: Avoid + Behaviour + Name: AvoidHighObjects + TakeControl: Distance: "0.5" meter + Action: Avoid + Behaviour + Name: Wandering + TakeControl: + Action: Wander + stops when + Collected Colors: Red Yellow Blue + \ No newline at end of file diff --git a/dsl/src/robots/missions/GenerateTaskDSL.mwe2 b/dsl/src/robots/missions/GenerateTaskDSL.mwe2 new file mode 100644 index 0000000..cddc57c --- /dev/null +++ b/dsl/src/robots/missions/GenerateTaskDSL.mwe2 @@ -0,0 +1,133 @@ +module robots.missions.GenerateTaskDSL + +import org.eclipse.emf.mwe.utils.* +import org.eclipse.xtext.generator.* +import org.eclipse.xtext.ui.generator.* + +var grammarURI = "classpath:/robots/missions/TaskDSL.xtext" +var fileExtensions = "tdsl" +var projectName = "desdsl" +var runtimeProject = "../${projectName}" +var generateXtendStub = true +var encoding = "UTF-8" + +Workflow { + bean = StandaloneSetup { + scanClassPath = true + platformUri = "${runtimeProject}/.." + // The following two lines can be removed, if Xbase is not used. + registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage" + registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel" + } + + component = DirectoryCleaner { + directory = "${runtimeProject}/src-gen" + } + + component = DirectoryCleaner { + directory = "${runtimeProject}/model/generated" + } + + component = DirectoryCleaner { + directory = "${runtimeProject}.ui/src-gen" + } + + component = DirectoryCleaner { + directory = "${runtimeProject}.tests/src-gen" + } + + component = Generator { + pathRtProject = runtimeProject + pathUiProject = "${runtimeProject}.ui" + pathTestProject = "${runtimeProject}.tests" + projectNameRt = projectName + projectNameUi = "${projectName}.ui" + encoding = encoding + language = auto-inject { + uri = grammarURI + + // Java API to access grammar elements (required by several other fragments) + fragment = grammarAccess.GrammarAccessFragment auto-inject {} + + // generates Java API for the generated EPackages + fragment = ecore.EMFGeneratorFragment auto-inject {} + + // the old serialization component + // fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {} + + // serializer 2.0 + fragment = serializer.SerializerFragment auto-inject { + generateStub = false + } + + // a custom ResourceFactory for use with EMF + fragment = resourceFactory.ResourceFactoryFragment auto-inject {} + + // The antlr parser generator fragment. + fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject { + // options = { + // backtrack = true + // } + } + + // Xtend-based API for validation + fragment = validation.ValidatorFragment auto-inject { + // composedCheck = "org.eclipse.xtext.validation.ImportUriValidator" + // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" + } + + // old scoping and exporting API + // fragment = scoping.ImportURIScopingFragment auto-inject {} + // fragment = exporting.SimpleNamesFragment auto-inject {} + + // scoping and exporting API + fragment = scoping.ImportNamespacesScopingFragment auto-inject {} + fragment = exporting.QualifiedNamesFragment auto-inject {} + fragment = builder.BuilderIntegrationFragment auto-inject {} + + // generator API + fragment = generator.GeneratorFragment auto-inject {} + + // formatter API + fragment = formatting.FormatterFragment auto-inject {} + + // labeling API + fragment = labeling.LabelProviderFragment auto-inject {} + + // outline API + fragment = outline.OutlineTreeProviderFragment auto-inject {} + fragment = outline.QuickOutlineFragment auto-inject {} + + // quickfix API + fragment = quickfix.QuickfixProviderFragment auto-inject {} + + // content assist API + fragment = contentAssist.ContentAssistFragment auto-inject {} + + // generates a more lightweight Antlr parser and lexer tailored for content assist + fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {} + + // generates junit test support classes into Generator#pathTestProject + fragment = junit.Junit4Fragment auto-inject {} + + // rename refactoring + fragment = refactoring.RefactorElementNameFragment auto-inject {} + + // provides the necessary bindings for java types integration + fragment = types.TypesGeneratorFragment auto-inject {} + + // generates the required bindings only if the grammar inherits from Xbase + fragment = xbase.XbaseGeneratorFragment auto-inject {} + + // generates the required bindings only if the grammar inherits from Xtype + fragment = xbase.XtypeGeneratorFragment auto-inject {} + + // provides a preference page for template proposals + fragment = templates.CodetemplatesGeneratorFragment auto-inject {} + + // provides a compare view + fragment = compare.CompareFragment auto-inject {} + } + } +} + diff --git a/dsl/src/robots/missions/TaskDSL.xtext b/dsl/src/robots/missions/TaskDSL.xtext new file mode 100644 index 0000000..54426ad --- /dev/null +++ b/dsl/src/robots/missions/TaskDSL.xtext @@ -0,0 +1,65 @@ +grammar robots.missions.TaskDSL with org.eclipse.xtext.common.Terminals + +generate taskDSL "http://www.missions.robots/TaskDSL" + +Robot: + 'Name' name=ID + 'Acceleration' acc=INT + 'Speed' spd=INT + 'LeftMotor plugged in' leftMotorPort=MotorPort + 'RightMotor plugged in' righMotorPort=MotorPort + ('ColorSensor plugged in' colorSensorPort=SensorPort)? + ('TouchSensor plugged in' leftTouchSensorPort=SensorPort 'and' rightTouchSensorPort=SensorPort)? + ('UltrasoneSensor plugged in' ultrasoneSensorPort=SensorPort)? + ('Mission:' mission+=Mission)+; + +Mission: + behaviours+=Behaviour+ 'stops when' stoppingCondition=StoppingCondition +; + +StoppingCondition: + SensorLimitReached | CollectedColors; + +CollectedColors: + 'Collected Colors:' colors+=ColorValue+ +; + +SensorLimitReached: + TouchLimit | ColorLimit | DistanceLimit; + +ColorLimit: + 'ColorLimit: ' lim=ColorValue +; + +TouchLimit: + 'TouchStatus: ' lim=Touch +; + +Touch: + 'Touch' | 'NoTouch' +; + +DistanceLimit: + 'Distance:' dist=STRING 'meter' +; + +ColorValue: + 'Black' | 'Blue' | 'Brown' | 'Cyan' | 'DarkGray' | 'Gray' | 'Green' | 'LightGray' | 'Magenta' | 'Orange' | 'Pink' | 'Red' | 'White' | 'Yellow' +; + +Behaviour: + 'Behaviour' + 'Name:' name=ID + 'TakeControl:' takeControl=SensorLimitReached? + 'Action:' action=Action +; + +Action: + 'Avoid' | 'Wander' | 'Nothing' +; + +SensorPort: + 'S1' | 'S2' | 'S3' | 'S4'; + +MotorPort: + 'A' | 'B' | 'C' | 'D'; \ No newline at end of file diff --git a/dsl/src/robots/missions/TaskDSLRuntimeModule.java b/dsl/src/robots/missions/TaskDSLRuntimeModule.java new file mode 100644 index 0000000..2401334 --- /dev/null +++ b/dsl/src/robots/missions/TaskDSLRuntimeModule.java @@ -0,0 +1,11 @@ +/* + * generated by Xtext + */ +package robots.missions; + +/** + * Use this class to register components to be used at runtime / without the Equinox extension registry. + */ +public class TaskDSLRuntimeModule extends robots.missions.AbstractTaskDSLRuntimeModule { + +} diff --git a/dsl/src/robots/missions/TaskDSLStandaloneSetup.java b/dsl/src/robots/missions/TaskDSLStandaloneSetup.java new file mode 100644 index 0000000..08ec4c9 --- /dev/null +++ b/dsl/src/robots/missions/TaskDSLStandaloneSetup.java @@ -0,0 +1,16 @@ +/* + * generated by Xtext + */ +package robots.missions; + +/** + * Initialization support for running Xtext languages + * without equinox extension registry + */ +public class TaskDSLStandaloneSetup extends TaskDSLStandaloneSetupGenerated{ + + public static void doSetup() { + new TaskDSLStandaloneSetup().createInjectorAndDoEMFRegistration(); + } +} + diff --git a/dsl/src/robots/missions/formatting/TaskDSLFormatter.xtend b/dsl/src/robots/missions/formatting/TaskDSLFormatter.xtend new file mode 100644 index 0000000..5d904cf --- /dev/null +++ b/dsl/src/robots/missions/formatting/TaskDSLFormatter.xtend @@ -0,0 +1,30 @@ +/* + * generated by Xtext + */ +package robots.missions.formatting + +import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter +import org.eclipse.xtext.formatting.impl.FormattingConfig +// import com.google.inject.Inject; +// import robots.missions.services.TaskDSLGrammarAccess + +/** + * This class contains custom formatting declarations. + * + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#formatting + * on how and when to use it. + * + * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example + */ +class TaskDSLFormatter extends AbstractDeclarativeFormatter { + +// @Inject extension TaskDSLGrammarAccess + + override protected void configureFormatting(FormattingConfig c) { +// It's usually a good idea to activate the following three statements. +// They will add and preserve newlines around comments +// c.setLinewrap(0, 1, 2).before(SL_COMMENTRule) +// c.setLinewrap(0, 1, 2).before(ML_COMMENTRule) +// c.setLinewrap(0, 1, 1).after(ML_COMMENTRule) + } +} diff --git a/dsl/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/src/robots/missions/generator/TaskDSLGenerator.xtend new file mode 100644 index 0000000..2139ca5 --- /dev/null +++ b/dsl/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -0,0 +1,24 @@ +/* + * generated by Xtext + */ +package robots.missions.generator + +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.xtext.generator.IGenerator +import org.eclipse.xtext.generator.IFileSystemAccess + +/** + * Generates code from your model files on save. + * + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation + */ +class TaskDSLGenerator implements IGenerator { + + override void doGenerate(Resource resource, IFileSystemAccess fsa) { +// fsa.generateFile('greetings.txt', 'People to greet: ' + +// resource.allContents +// .filter(typeof(Greeting)) +// .map[name] +// .join(', ')) + } +} diff --git a/dsl/src/robots/missions/scoping/TaskDSLScopeProvider.xtend b/dsl/src/robots/missions/scoping/TaskDSLScopeProvider.xtend new file mode 100644 index 0000000..4267cce --- /dev/null +++ b/dsl/src/robots/missions/scoping/TaskDSLScopeProvider.xtend @@ -0,0 +1,15 @@ +/* + * generated by Xtext + */ +package robots.missions.scoping + +/** + * This class contains custom scoping description. + * + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping + * on how and when to use it. + * + */ +class TaskDSLScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider { + +} diff --git a/dsl/src/robots/missions/validation/TaskDSLValidator.xtend b/dsl/src/robots/missions/validation/TaskDSLValidator.xtend new file mode 100644 index 0000000..67fdc6e --- /dev/null +++ b/dsl/src/robots/missions/validation/TaskDSLValidator.xtend @@ -0,0 +1,25 @@ +/* + * generated by Xtext + */ +package robots.missions.validation + +//import org.eclipse.xtext.validation.Check + +/** + * This class contains custom validation rules. + * + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation + */ +class TaskDSLValidator extends AbstractTaskDSLValidator { + +// public static val INVALID_NAME = 'invalidName' +// +// @Check +// def checkGreetingStartsWithCapital(Greeting greeting) { +// if (!Character.isUpperCase(greeting.name.charAt(0))) { +// warning('Name should start with a capital', +// MyDslPackage.Literals.GREETING__NAME, +// INVALID_NAME) +// } +// } +} diff --git a/mart/ev3/ex2/nl/ru/des/MarsRover.java b/mart/ev3/ex2/nl/ru/des/MarsRover.java index 872ab93..f19ff15 100644 --- a/mart/ev3/ex2/nl/ru/des/MarsRover.java +++ b/mart/ev3/ex2/nl/ru/des/MarsRover.java @@ -40,8 +40,8 @@ public class MarsRover { LCDPrinter.print("Trying to pair"); BTController btController; - btController = BTController.getBTMaster("Rover1", mh); // Master - //btController = BTController.getBTSlave(mh); // Slave + //btController = BTController.getBTMaster("Rover1", mh); // Master + btController = BTController.getBTSlave(mh); // Slave btController.start(); LCDPrinter.print("Loading keylistener..."); diff --git a/natanael/dsl/robots.missions/spec1.tdsl b/natanael/dsl/robots.missions/spec1.tdsl deleted file mode 100644 index 8695107..0000000 --- a/natanael/dsl/robots.missions/spec1.tdsl +++ /dev/null @@ -1,19 +0,0 @@ -RobotName Rover1 - -LefMotor Acceleration 100 Speed 200 -RightMotor Acceleration 100 Speed 200 - -Sensor touchSensor SensorType TouchSensor "S3" "S4" -Sensor ultrasonicSensor SensorType UltrasonicSensor "S2" limit "0.512" -Sensor colorSensor SensorType ColorSensor "S1" - Color RED ColorID "RED" - Color BLUE ColorID "BLUE" - Color YELLOW ColorID "YELLOW" - Color WHITE ColorID "WHITE" - Color BLACK ColorID "BLACK" - -Behaviour Wander -Behaviour StayInsideBlackLine -Behaviour DetectColor -Behaviour AvoidHighObject -Behaviour AvoidLowObject \ No newline at end of file