Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfjouault2013-12-18 12:23:55 -0500
committerfjouault2013-12-18 12:23:55 -0500
commit65b0671d4f5d0907029e1974c39e5dad4ffad691 (patch)
tree0de5dbf66d69f19c467de658fbb468031a3e5ec3 /syntaxes/Kmelia
downloadorg.eclipse.atl.tcs-65b0671d4f5d0907029e1974c39e5dad4ffad691.tar.gz
org.eclipse.atl.tcs-65b0671d4f5d0907029e1974c39e5dad4ffad691.tar.xz
org.eclipse.atl.tcs-65b0671d4f5d0907029e1974c39e5dad4ffad691.zip
initial commit of approved contribution (see bug 417707)
This version needs refactoring (notably package names) as well as porting to current version of ATL
Diffstat (limited to 'syntaxes/Kmelia')
-rw-r--r--syntaxes/Kmelia/.project22
-rw-r--r--syntaxes/Kmelia/Metamodel/Kmelia.km397
-rw-r--r--syntaxes/Kmelia/Syntax/Kmelia.tcs292
-rw-r--r--syntaxes/Kmelia/build.properties2
4 files changed, 413 insertions, 0 deletions
diff --git a/syntaxes/Kmelia/.project b/syntaxes/Kmelia/.project
new file mode 100644
index 0000000..2ff1fb9
--- /dev/null
+++ b/syntaxes/Kmelia/.project
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Kmelia</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.gmt.tcs.builder.Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2m.atl.adt.builder.atlBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2m.atl.adt.builder.atlNature</nature>
+ </natures>
+</projectDescription>
diff --git a/syntaxes/Kmelia/Metamodel/Kmelia.km3 b/syntaxes/Kmelia/Metamodel/Kmelia.km3
new file mode 100644
index 0000000..9ba463b
--- /dev/null
+++ b/syntaxes/Kmelia/Metamodel/Kmelia.km3
@@ -0,0 +1,97 @@
+-- @name Kmelia
+-- @version 1.0
+-- @authors Frédéric Jouault
+-- @date 2007/10/17
+-- @description Abstract syntax of a subset of the Kmelia component language.
+package Kmelia {
+
+ -- Every class should extend LocatedElement, directly or indirectly.
+ -- This is a technical constraint to support text-to-model traceability.
+ abstract class LocatedElement {
+ attribute location[0-1] : String;
+ attribute commentsBefore[*] ordered : String;
+ attribute commentsAfter[*] ordered : String;
+ }
+
+-- BEGIN DSL-specific classes (replace sample contents)
+ class Component extends LocatedElement {
+ attribute name : String;
+ reference provides[*] ordered : Service;
+ reference requires[*] ordered : Service;
+ reference services[*] ordered container : Service;
+ }
+
+ abstract class Service extends LocatedElement {
+ attribute name : String;
+ attribute isRequired : Boolean;
+ }
+
+ class ExternalService extends Service {}
+
+ class InternalService extends Service {
+ reference parameters[*] ordered container : Parameter;
+ attribute returnType[0-1] : String;
+ reference body[0-1] container : Body;
+ }
+
+ class Parameter extends LocatedElement {
+ attribute name : String;
+ attribute type : String;
+ }
+
+ class Body extends LocatedElement {
+ reference interface container : Interface;
+ reference behavior[0-1] container : Behavior;
+ }
+
+ class Interface extends LocatedElement {}
+
+ class Behavior extends LocatedElement {
+ reference initialState : State;
+ reference finalStates[1-*] ordered : State;
+ reference states[1-*] ordered container : State;
+ reference transitions[1-*] ordered container : Transition;
+ }
+
+ class State extends LocatedElement {
+ attribute name : String;
+ }
+
+ class Transition extends LocatedElement {
+ reference source : State;
+ reference target : State;
+ reference actions[*] ordered container : Action;
+ }
+
+-- @begin Actions
+ abstract class Action extends LocatedElement {}
+
+ class FunctionCall extends Action {
+ attribute name : String;
+ reference arguments[*] ordered container : Expression;
+ }
+
+ abstract class Communication extends Action {
+ attribute channel : String;
+ }
+
+ class ServiceCall extends Communication {
+ attribute name : String;
+ }
+-- @end Actions
+
+-- @begin Expressions
+ abstract class Expression extends LocatedElement {}
+
+ class StringExp extends Expression {
+ attribute value : String;
+ }
+-- @end Expressions
+-- END DSL-specific classes
+}
+
+package PrimitiveTypes {
+ datatype Boolean;
+ datatype Integer;
+ datatype String;
+}
diff --git a/syntaxes/Kmelia/Syntax/Kmelia.tcs b/syntaxes/Kmelia/Syntax/Kmelia.tcs
new file mode 100644
index 0000000..e133744
--- /dev/null
+++ b/syntaxes/Kmelia/Syntax/Kmelia.tcs
@@ -0,0 +1,292 @@
+-- @name Kmelia
+-- @version 1.0
+-- @authors Frédéric Jouault
+-- @date 2007/10/17
+-- @description Concrete syntax of the Kmelia language.
+
+-- The different sections of a TCS model have been enclosed between BEGIN and END
+-- comments below. Additional information is provided below each BEGIN comment.
+-- The main sections of interest are "Class templates", and
+-- "Operator table" (the latter only for DSLs using operators).
+syntax Kmelia {
+
+-- BEGIN Primitive templates
+-- Specifies representation of primitive types.
+-- Only needs modification when default lexer is not satisfactory.
+-- Generally modified along with the lexer.
+ primitiveTemplate identifier for String default using NAME:
+ value = "%token%";
+
+ primitiveTemplate stringSymbol for String using STRING:
+ value = "%token%",
+ serializer="'\'' + %value%.toCString() + '\''";
+
+ primitiveTemplate integerSymbol for Integer default using INT:
+ value = "Integer.valueOf(%token%)";
+
+ primitiveTemplate floatSymbol for Double default using FLOAT:
+ value = "Double.valueOf(%token%)";
+-- END Primitive templates
+
+-- BEGIN Class templates
+-- Specifies representation of classes.
+-- This is the main section to work on.
+ template Component main context
+ : "COMPONENT" name
+ "INTERFACE"
+ "provides" ":" "{" provides{refersTo = name, separator = ","} "}"
+ "requires" ":" "{" requires{refersTo = name, separator = ","} "}"
+ "SERVICES"
+ services
+ "END_SERVICES"
+ ;
+
+ template Service abstract;
+
+ template ExternalService addToContext
+ : (isRequired ? "required" : "provided") "external" name
+ ;
+
+ template InternalService addToContext
+ : (isRequired ? "required" : "provided") name
+ "(" parameters{separator = ","} ")"
+ (isDefined(returnType) ? ":" returnType)
+ (isDefined(body) ? body)
+ "end"
+ ;
+
+ template Parameter
+ : name ":" type
+ ;
+
+ template Body
+ : interface
+ (isDefined(behavior) ? "Behavior" behavior)
+ ;
+
+ template Interface
+ : "Interface"
+ ;
+
+ template Behavior context
+ : "init" initialState{refersTo = name, createIn = '#context'.states, autoCreate = ifmissing}
+ "final" finalStates{refersTo = name, createIn = '#context'.states, autoCreate = ifmissing, separator = ","}
+ "{"
+ transitions{separator = ","}
+ "}"
+ ;
+
+ template State addToContext
+ : name
+ ;
+
+ template Transition
+ : source{refersTo = name, createIn = '#context'.states, autoCreate = ifmissing} "--"
+ actions{separator = ","}
+ "-->" target{refersTo = name, createIn = '#context'.states, autoCreate = ifmissing}
+ ;
+
+-- @begin Actions
+ template Action abstract;
+
+ template FunctionCall
+ : name "(" arguments{separator = ","} ")"
+ ;
+
+ template Communication abstract;
+
+ template ServiceCall
+ : channel "!!" name "(" ")"
+ ;
+-- @end Actions
+
+-- @begin Expressions
+ template Expression abstract;
+
+ template StringExp
+ : value
+ ;
+-- @end Expressions
+-- END Class templates
+
+-- BEGIN Special symbols
+-- Possible modifications:
+-- - Addition of new symbols.
+-- - Modification of spaces information.
+-- - Removal of unused symbols so that using these symbols results in lexical
+-- error rather than parsing error.
+ symbols {
+ lsquare = "[";
+ rsquare = "]" : rightSpace;
+ excl = "!";
+ exclexcl = "!!";
+ coma = "," : leftNone, rightSpace;
+ lparen = "(";
+ rparen = ")" : leftNone, rightSpace;
+ lcurly = "{" : leftSpace;
+ rcurly = "}" : leftNone, rightSpace;
+ semi = ";" : leftNone, rightSpace;
+ colon = ":" : leftSpace, rightSpace;
+ pipe = "|" : leftSpace, rightSpace;
+ sharp = "#" : leftSpace;
+ qmark = "?";
+ coloncolon = "::" : leftNone, rightNone;
+
+ -- operator symbols
+ point = "." : leftNone;
+ minusminus = "--" : leftSpace, rightSpace;
+ rlarrow = "-->" : leftSpace, rightSpace;
+ rarrow = "->" : leftNone;
+ minus = "-" : leftSpace, rightSpace;
+ star = "*" : leftSpace, rightSpace;
+ slash = "/" : leftSpace, rightSpace;
+ plus = "+" : leftSpace, rightSpace;
+ eq = "=" : leftSpace, rightSpace;
+ gt = ">" : leftSpace, rightSpace;
+ lt = "<" : leftSpace, rightSpace;
+ ge = ">=" : leftSpace, rightSpace;
+ le = "<=" : leftSpace, rightSpace;
+ ne = "<>" : leftSpace, rightSpace;
+ larrow = "<-" : leftSpace, rightSpace;
+ }
+-- END Special symbols
+
+-- BEGIN Operator table
+-- Defines all operators with their priority, arity, and associativity.
+-- All defined operators must be used in operator templates.
+
+-- Specify operator table(s) here if necessary.
+
+-- END Operator table
+
+
+-- BEGIN Lexer
+-- Specifies the lexical entities.
+-- Only needs modification when default lexer is not satisfactory.
+-- Generally modified along with Primitive templates.
+ token COMMENT : endOfLine(start = "#") |
+ multiLine(start = "/*", end = "*/");
+
+ lexer = "
+%options testLiterals = false;
+
+NL
+ : ( '\\r' '\\n'
+ | '\\n' '\\r' //Improbable
+ | '\\r'
+ | '\\n'
+ )
+ {newline();}
+ ;
+
+WS
+ : ( ' '
+ | '\\t'
+ )
+ ;
+
+%protected
+DIGIT
+ : '0'..'9'
+ ;
+
+%protected
+ALPHA
+ : 'a'..'z'
+ | 'A'..'Z'
+ | '_'
+ //For Unicode compatibility (from 0000 to 00ff)
+ | '\\u00C0' .. '\\u00D6'
+ | '\\u00D8' .. '\\u00F6'
+ | '\\u00F8' .. '\\u00FF'
+ ;
+
+%protected
+SNAME
+%v2 options {
+%v2 testLiterals = true;
+%v2 }
+ : (ALPHA) (ALPHA | DIGIT)*
+;
+
+NAME
+ : (
+%v3 SNAME
+%v2 s:SNAME {if(s.getType() != SNAME) $setType(s.getType());}
+ | '\"'!
+ ( ESC
+ | '\\n' {newline();}
+ | ~('\\\\'|'\\\"'|'\\n')
+ )*
+ '\"'!
+%v3 {setText(ei.unescapeString(getText(), 1));}
+ )
+ ;
+
+INT
+ : (DIGIT)+
+%v2 (('.' DIGIT)=> '.' (DIGIT)+ {$setType(FLOAT);})?
+ ;
+
+%v3 FLOAT : DIGIT+ '.' DIGIT* ;
+
+%protected
+ESC
+ : '\\\\'!
+ ( 'n' %v2{%setText(\"\\n\");}
+ | 'r' %v2{%setText(\"\\r\");}
+ | 't' %v2{%setText(\"\\t\");}
+ | 'b' %v2{%setText(\"\\b\");}
+ | 'f' %v2{%setText(\"\\f\");}
+ | '\"' %v2{%setText(\"\\\"\");}
+ | '\\'' %v2{%setText(\"\\'\");}
+ | '\\\\' %v2{%setText(\"\\\\\");}
+ | (
+ ('0'..'3')
+ (
+%v2 options {
+%v2 warnWhenFollowAmbig = false;
+%v2 }
+ : ('0'..'7')
+ (
+%v2 options {
+%v2 warnWhenFollowAmbig = false;
+%v2 }
+ : '0'..'7'
+ )?
+ )?
+ | ('4'..'7')
+ (
+%v2 options {
+%v2 warnWhenFollowAmbig = false;
+%v2 }
+ : ('0'..'7')
+ )?
+ )
+ {
+%v2 String s = %getText;
+%v2 int i;
+%v2 int ret = 0;
+%v2 String ans;
+%v2 for (i=0; i<s.length(); ++i)
+%v2 ret = ret*8 + s.charAt(i) - '0';
+%v2 ans = String.valueOf((char) ret);
+%v2 %setText(ans);
+ }
+ )
+ ;
+
+STRING
+ : '\\''!
+ ( ESC
+ | '\\n' {newline();}
+ | ~('\\\\'|'\\''|'\\n')
+ )*
+ '\\''!
+%v3 {setText(ei.unescapeString(getText(), 1));}
+ ;
+
+ ";
+-- END Lexer
+
+}
diff --git a/syntaxes/Kmelia/build.properties b/syntaxes/Kmelia/build.properties
new file mode 100644
index 0000000..3573a48
--- /dev/null
+++ b/syntaxes/Kmelia/build.properties
@@ -0,0 +1,2 @@
+dsl.name=Kmelia
+dsl.ext=cmp

Back to the top