From 1312ba95d1db184e8f2e56eb6d401cc3f138c444 Mon Sep 17 00:00:00 2001 From: Dennis Wagelaar Date: Sun, 1 Dec 2024 00:24:35 +0100 Subject: [PATCH] Add Eclipse ATL language (https://eclipse.dev/atl/) --- lexers/embedded/atl.xml | 165 ++++++++++++++ lexers/testdata/atl.actual | 61 ++++++ lexers/testdata/atl.expected | 413 +++++++++++++++++++++++++++++++++++ 3 files changed, 639 insertions(+) create mode 100644 lexers/embedded/atl.xml create mode 100644 lexers/testdata/atl.actual create mode 100644 lexers/testdata/atl.expected diff --git a/lexers/embedded/atl.xml b/lexers/embedded/atl.xml new file mode 100644 index 000000000..623dc205e --- /dev/null +++ b/lexers/embedded/atl.xml @@ -0,0 +1,165 @@ + + + ATL + atl + *.atl + text/x-atl + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lexers/testdata/atl.actual b/lexers/testdata/atl.actual new file mode 100644 index 000000000..677340c6e --- /dev/null +++ b/lexers/testdata/atl.actual @@ -0,0 +1,61 @@ +module TypeA2TypeB; +create b : TypeB from a : TypeA; + +rule RootA2RootB { + from + rtA : TypeA!RootA + to + rtB : TypeB!RootB ( + defs <- rtA.elms->iterate(e; res : Set(TypeA!ElementA) = Set {} | + if (res->collect(f | f.name)->includes(e.name)) then + res + else + res->including(e) + endif + )-- here we keep only one element of each name value + ->collect(e | thisModule.Definition(e)), + -- then we create a DefinitionB from each selected element + elms <- rtA.elms + ) +} + +lazy rule Definition { + from + s : TypeA!ElementA + to + t : TypeB!DefinitionB( + name <- s.name + ) +} + +helper def: nameToAssignHistory : Sequence(TupleType(e : TypeB!ElementB, s : String)) = + Sequence {}; + +rule NameToAssign (e : TypeB!ElementB, s : String) { + do { + thisModule.nameToAssignHistory <- thisModule.nameToAssignHistory->append(Tuple {e = e, s = s}); + } +} + +rule Element { + from + s : TypeA!ElementA + to + t : TypeB!ElementB( + ) + do { + -- The corresponding name for the current ElementB is added in the map. + -- This map will be used at the end of the transformation to create a link between ElementB and DefinitionB + thisModule.NameToAssign(t, s.name); + } +} + +-- execute delayed actions +endpoint rule EndRule() { + do { + for(dta in thisModule.nameToAssignHistory) { + -- We create a link between an ElementB and the corresponding DefinitionB + dta.e.definition <- TypeB!DefinitionB.allInstancesFrom('b')->any(e | e.name = dta.s); + } + } +} diff --git a/lexers/testdata/atl.expected b/lexers/testdata/atl.expected new file mode 100644 index 000000000..2257e6807 --- /dev/null +++ b/lexers/testdata/atl.expected @@ -0,0 +1,413 @@ +[ + {"type":"KeywordNamespace","value":"module"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeA2TypeB"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordNamespace","value":"create"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"b"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordNamespace","value":"from"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"a"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeA"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"KeywordNamespace","value":"rule"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"RootA2RootB"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"from"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"NameNamespace","value":"rtA"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeA"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"RootA"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"to"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"NameNamespace","value":"rtB"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"RootB"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"NameNamespace","value":"defs"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"\u003c-"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"rtA"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"elms"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"iterate"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"res"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"Set"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"TypeA"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"ElementA"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"Set"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{}"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"|"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Keyword","value":"if"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"res"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"collect"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"f"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"|"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"f"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"name"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"includes"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"name"}, + {"type":"Punctuation","value":"))"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"then"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t\t"}, + {"type":"NameNamespace","value":"res"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Keyword","value":"else"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t\t"}, + {"type":"NameNamespace","value":"res"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"including"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Keyword","value":"endif"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Punctuation","value":")"}, + {"type":"CommentSingle","value":"-- here we keep only one element of each name value"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"collect"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"|"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"thisModule"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"Definition"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":")),"}, + {"type":"TextWhitespace","value":"\n\t\t\t\t"}, + {"type":"CommentSingle","value":"-- then we create a DefinitionB from each selected element"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"NameNamespace","value":"elms"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"\u003c-"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"rtA"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"elms"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"KeywordDeclaration","value":"lazy"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordNamespace","value":"rule"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"Definition"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"from"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"NameNamespace","value":"s"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeA"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"ElementA"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"to"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"NameNamespace","value":"t"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"DefinitionB"}, + {"type":"Punctuation","value":"("}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"NameNamespace","value":"name"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"\u003c-"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"s"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"name"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"KeywordNamespace","value":"helper"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordNamespace","value":"def"}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"nameToAssignHistory"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"Sequence"}, + {"type":"Punctuation","value":"("}, + {"type":"KeywordType","value":"Tuple"}, + {"type":"NameNamespace","value":"Type"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"ElementB"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"s"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"String"}, + {"type":"Punctuation","value":"))"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordType","value":"Sequence"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{};"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"KeywordNamespace","value":"rule"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"NameToAssign"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"ElementB"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"s"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"String"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"do"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Keyword","value":"thisModule"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"nameToAssignHistory"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"\u003c-"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"thisModule"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"nameToAssignHistory"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"append"}, + {"type":"Punctuation","value":"("}, + {"type":"KeywordType","value":"Tuple"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"NameNamespace","value":"e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"s"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"s"}, + {"type":"Punctuation","value":"});"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"KeywordNamespace","value":"rule"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"Element"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"from"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"NameNamespace","value":"s"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeA"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"ElementA"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"to"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"NameNamespace","value":"t"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"ElementB"}, + {"type":"Punctuation","value":"("}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"do"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"CommentSingle","value":"-- The corresponding name for the current ElementB is added in the map."}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"CommentSingle","value":"-- This map will be used at the end of the transformation to create a link between ElementB and DefinitionB"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Keyword","value":"thisModule"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"NameToAssign"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"t"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"s"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"name"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"CommentSingle","value":"-- execute delayed actions"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"endpoint"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordNamespace","value":"rule"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"EndRule"}, + {"type":"Punctuation","value":"()"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"KeywordNamespace","value":"do"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Keyword","value":"for"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"dta"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"in"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"thisModule"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"nameToAssignHistory"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"CommentSingle","value":"-- We create a link between an ElementB and the corresponding DefinitionB"}, + {"type":"TextWhitespace","value":"\n\t\t\t"}, + {"type":"NameNamespace","value":"dta"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"definition"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"\u003c-"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"TypeB"}, + {"type":"Punctuation","value":"!"}, + {"type":"NameNamespace","value":"DefinitionB"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"allInstancesFrom"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"'b'"}, + {"type":"Punctuation","value":")"}, + {"type":"Operator","value":"-\u003e"}, + {"type":"NameNamespace","value":"any"}, + {"type":"Punctuation","value":"("}, + {"type":"NameNamespace","value":"e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"|"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"e"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"name"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameNamespace","value":"dta"}, + {"type":"Punctuation","value":"."}, + {"type":"NameNamespace","value":"s"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"} +]