-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Eclipse ATL language (https://eclipse.dev/atl/) (#1024)
Would like to use ATL syntax highlighting on the ATL website, which is generated using hugo.
- Loading branch information
Showing
3 changed files
with
639 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<lexer> | ||
<config> | ||
<name>ATL</name> | ||
<alias>atl</alias> | ||
<filename>*.atl</filename> | ||
<mime_type>text/x-atl</mime_type> | ||
<dot_all>true</dot_all> | ||
</config> | ||
<rules> | ||
<state name="root"> | ||
<rule pattern="(--.*?)(\n)"> | ||
<bygroups> | ||
<token type="CommentSingle" /> | ||
<token type="TextWhitespace" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(and|distinct|endif|else|for|foreach|if|implies|in|let|not|or|self|super|then|thisModule|xor)\b"> | ||
<token type="Keyword" /> | ||
</rule> | ||
<rule pattern="(OclUndefined|true|false|#\w+)\b"> | ||
<token type="KeywordConstant" /> | ||
</rule> | ||
<rule pattern="(module|query|library|create|from|to|uses)\b"> | ||
<token type="KeywordNamespace" /> | ||
</rule> | ||
<rule pattern="(do)(\s*)({)"> | ||
<bygroups> | ||
<token type="KeywordNamespace" /> | ||
<token type="TextWhitespace" /> | ||
<token type="Punctuation" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(abstract|endpoint|entrypoint|lazy|unique)(\s+)"> | ||
<bygroups> | ||
<token type="KeywordDeclaration" /> | ||
<token type="TextWhitespace" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(rule)(\s+)"> | ||
<bygroups> | ||
<token type="KeywordNamespace" /> | ||
<token type="TextWhitespace" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(helper)(\s+)"> | ||
<bygroups> | ||
<token type="KeywordNamespace" /> | ||
<token type="TextWhitespace" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(context)(\s+)"> | ||
<bygroups> | ||
<token type="KeywordNamespace" /> | ||
<token type="TextWhitespace" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(def)(\s*)(:)(\s*)"> | ||
<bygroups> | ||
<token type="KeywordNamespace" /> | ||
<token type="TextWhitespace" /> | ||
<token type="Punctuation" /> | ||
<token type="TextWhitespace" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="(Bag|Boolean|Integer|OrderedSet|Real|Sequence|Set|String|Tuple)"> | ||
<token type="KeywordType" /> | ||
</rule> | ||
<rule pattern="(\w+)(\s*)(<-|<:=)"> | ||
<bygroups> | ||
<token type="NameNamespace" /> | ||
<token type="TextWhitespace" /> | ||
<token type="Punctuation" /> | ||
</bygroups> | ||
</rule> | ||
<rule pattern="#""> | ||
<token type="KeywordConstant" /> | ||
<push state="quotedenumliteral" /> | ||
</rule> | ||
<rule pattern="""> | ||
<token type="NameNamespace" /> | ||
<push state="quotedname" /> | ||
</rule> | ||
<rule pattern="[^\S\n]+"> | ||
<token type="TextWhitespace" /> | ||
</rule> | ||
<rule pattern="'"> | ||
<token type="LiteralString" /> | ||
<push state="string" /> | ||
</rule> | ||
<rule | ||
pattern="[0-9]*\.[0-9]+"> | ||
<token type="LiteralNumberFloat" /> | ||
</rule> | ||
<rule pattern="0|[1-9][0-9]*"> | ||
<token type="LiteralNumberInteger" /> | ||
</rule> | ||
<rule pattern="[*<>+=/-]"> | ||
<token type="Operator" /> | ||
</rule> | ||
<rule pattern="([{}();:.,!|]|->)"> | ||
<token type="Punctuation" /> | ||
</rule> | ||
<rule pattern="\n"> | ||
<token type="TextWhitespace" /> | ||
</rule> | ||
<rule pattern="\w+"> | ||
<token type="NameNamespace" /> | ||
</rule> | ||
</state> | ||
<state name="string"> | ||
<rule pattern="[^\\']+"> | ||
<token type="LiteralString" /> | ||
</rule> | ||
<rule pattern="\\\\"> | ||
<token type="LiteralString" /> | ||
</rule> | ||
<rule pattern="\\'"> | ||
<token type="LiteralString" /> | ||
</rule> | ||
<rule pattern="\\"> | ||
<token type="LiteralString" /> | ||
</rule> | ||
<rule pattern="'"> | ||
<token type="LiteralString" /> | ||
<pop depth="1" /> | ||
</rule> | ||
</state> | ||
<state name="quotedname"> | ||
<rule pattern="[^\\"]+"> | ||
<token type="NameNamespace" /> | ||
</rule> | ||
<rule pattern="\\\\"> | ||
<token type="NameNamespace" /> | ||
</rule> | ||
<rule pattern="\\""> | ||
<token type="NameNamespace" /> | ||
</rule> | ||
<rule pattern="\\"> | ||
<token type="NameNamespace" /> | ||
</rule> | ||
<rule pattern="""> | ||
<token type="NameNamespace" /> | ||
<pop depth="1" /> | ||
</rule> | ||
</state> | ||
<state name="quotedenumliteral"> | ||
<rule pattern="[^\\"]+"> | ||
<token type="KeywordConstant" /> | ||
</rule> | ||
<rule pattern="\\\\"> | ||
<token type="KeywordConstant" /> | ||
</rule> | ||
<rule pattern="\\""> | ||
<token type="KeywordConstant" /> | ||
</rule> | ||
<rule pattern="\\"> | ||
<token type="KeywordConstant" /> | ||
</rule> | ||
<rule pattern="""> | ||
<token type="KeywordConstant" /> | ||
<pop depth="1" /> | ||
</rule> | ||
</state> | ||
</rules> | ||
</lexer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Oops, something went wrong.