Skip to content

Commit

Permalink
Added support for AL (PrismJS#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored and quentinvernot committed Sep 11, 2020
1 parent 8840011 commit b909f9b
Show file tree
Hide file tree
Showing 15 changed files with 738 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -91,6 +91,10 @@
"title": "Ada",
"owner": "Lucretia"
},
"al": {
"title": "AL",
"owner": "RunDevelopment"
},
"antlr4": {
"title": "ANTLR4",
"alias": "g4",
Expand Down
25 changes: 25 additions & 0 deletions components/prism-al.js
@@ -0,0 +1,25 @@
// based on https://github.com/microsoft/AL/blob/master/grammar/alsyntax.tmlanguage

Prism.languages.al = {
'comment': /\/\/.*|\/\*[\s\S]*?\*\//,
'string': {
pattern: /'(?:''|[^'\r\n])*'(?!')|"(?:""|[^"\r\n])*"(?!")/,
greedy: true
},
'function': {
pattern: /(\b(?:event|procedure|trigger)\s+|(?:^|[^.])\.\s*)[a-z_]\w*(?=\s*\()/i,
lookbehind: true
},
'keyword': [
// keywords
/\b(?:array|asserterror|begin|break|case|do|downto|else|end|event|exit|for|foreach|function|if|implements|in|indataset|interface|internal|local|of|procedure|program|protected|repeat|runonclient|securityfiltering|suppressdispose|temporary|then|to|trigger|until|var|while|with|withevents)\b/i,
// objects and metadata that are used like keywords
/\b(?:action|actions|addafter|addbefore|addfirst|addlast|area|assembly|chartpart|codeunit|column|controladdin|cuegroup|customizes|dataitem|dataset|dotnet|elements|enum|enumextension|extends|field|fieldattribute|fieldelement|fieldgroup|fieldgroups|fields|filter|fixed|grid|group|key|keys|label|labels|layout|modify|moveafter|movebefore|movefirst|movelast|page|pagecustomization|pageextension|part|profile|query|repeater|report|requestpage|schema|separator|systempart|table|tableelement|tableextension|textattribute|textelement|type|usercontrol|value|xmlport)\b/i
],
'number': /\b(?:0x[\da-f]+|(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(?:F|U(?:LL?)?|LL?)?\b/i,
'boolean': /\b(?:false|true)\b/i,
'variable': /\b(?:Curr(?:FieldNo|Page|Report)|RequestOptionsPage|x?Rec)\b/,
'class-name': /\b(?:automation|biginteger|bigtext|blob|boolean|byte|char|clienttype|code|completiontriggererrorlevel|connectiontype|database|dataclassification|datascope|date|dateformula|datetime|decimal|defaultlayout|dialog|dictionary|dotnetassembly|dotnettypedeclaration|duration|errorinfo|errortype|executioncontext|executionmode|fieldclass|fieldref|fieldtype|file|filterpagebuilder|guid|httpclient|httpcontent|httpheaders|httprequestmessage|httpresponsemessage|instream|integer|joker|jsonarray|jsonobject|jsontoken|jsonvalue|keyref|list|moduledependencyinfo|moduleinfo|none|notification|notificationscope|objecttype|option|outstream|pageresult|record|recordid|recordref|reportformat|securityfilter|sessionsettings|tableconnectiontype|tablefilter|testaction|testfield|testfilterfield|testpage|testpermissions|testrequestpage|text|textbuilder|textconst|textencoding|time|transactionmodel|transactiontype|variant|verbosity|version|view|views|webserviceactioncontext|webserviceactionresultcode|xmlattribute|xmlattributecollection|xmlcdata|xmlcomment|xmldeclaration|xmldocument|xmldocumenttype|xmlelement|xmlnamespacemanager|xmlnametable|xmlnode|xmlnodelist|xmlprocessinginstruction|xmlreadoptions|xmltext|xmlwriteoptions)\b/i,
'operator': /\.\.|:[=:]|[-+*/]=?|<>|[<>]=?|=|\b(?:and|div|mod|not|or|xor)\b/i,
'punctuation': /[()\[\]{}:.;,]/
};
1 change: 1 addition & 0 deletions components/prism-al.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions examples/prism-al.html
@@ -0,0 +1,60 @@
<h2>Full example</h2>
<pre><code>// Source: https://github.com/microsoft/AL/blob/master/samples/ControlAddIn/al/Page/CustomerCardAddIn.al

pageextension 50300 CustomerCardAddIn extends "Customer Card"
{
layout
{
addafter(Blocked)
{
usercontrol(ControlName; TestAddIn)
{
ApplicationArea = All;

trigger Callback(i : integer; s: text; d : decimal; c : char)
begin
Message('Got from js: %1, %2, %3, %4', i, s, d, c);
end;
}
}
}

actions
{
addafter(Approve)
{
action(CallJavaScript)
{
ApplicationArea = All;

trigger OnAction();
begin
CurrPage.ControlName.CallJavaScript(5, 'text', 6.3, 'c');
end;
}

action(CallViaCodeunit)
{
ApplicationArea = All;

trigger OnAction();
var c : Codeunit AddInHelpers;
begin
c.CallJavaScript(CurrPage.ControlName);
end;
}

action(CallStaleControlAddIn)
{
ApplicationArea = All;

trigger OnAction();
var c : Codeunit AddInHelpersSingleton;
begin
c.CallStaleAddInMethod();
Message('Probably nothing should happen...');
end;
}
}
}
}</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -21,6 +21,7 @@
"js": "JavaScript",
"abap": "ABAP",
"abnf": "Augmented Backus–Naur form",
"al": "AL",
"antlr4": "ANTLR4",
"g4": "ANTLR4",
"apacheconf": "Apache Configuration",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/languages/al/boolean_feature.test
@@ -0,0 +1,17 @@
false
true
FALSE
TRUE

----------------------------------------------------

[
["boolean", "false"],
["boolean", "true"],
["boolean", "FALSE"],
["boolean", "TRUE"]
]

----------------------------------------------------

Checks for booleans.
211 changes: 211 additions & 0 deletions tests/languages/al/class-name_feature.test
@@ -0,0 +1,211 @@
automation
biginteger
bigtext
blob
boolean
byte
char
clienttype
code
completiontriggererrorlevel
connectiontype
database
dataclassification
datascope
date
dateformula
datetime
decimal
defaultlayout
dialog
dictionary
dotnetassembly
dotnettypedeclaration
duration
errorinfo
errortype
executioncontext
executionmode
fieldclass
fieldref
fieldtype
file
filterpagebuilder
guid
httpclient
httpcontent
httpheaders
httprequestmessage
httpresponsemessage
instream
integer
joker
jsonarray
jsonobject
jsontoken
jsonvalue
keyref
list
moduledependencyinfo
moduleinfo
none
notification
notificationscope
objecttype
option
outstream
pageresult
record
recordid
recordref
reportformat
securityfilter
sessionsettings
tableconnectiontype
tablefilter
testaction
testfield
testfilterfield
testpage
testpermissions
testrequestpage
text
textbuilder
textconst
textencoding
time
transactionmodel
transactiontype
variant
verbosity
version
view
views
webserviceactioncontext
webserviceactionresultcode
xmlattribute
xmlattributecollection
xmlcdata
xmlcomment
xmldeclaration
xmldocument
xmldocumenttype
xmlelement
xmlnamespacemanager
xmlnametable
xmlnode
xmlnodelist
xmlprocessinginstruction
xmlreadoptions
xmltext
xmlwriteoptions

----------------------------------------------------

[
["class-name", "automation"],
["class-name", "biginteger"],
["class-name", "bigtext"],
["class-name", "blob"],
["class-name", "boolean"],
["class-name", "byte"],
["class-name", "char"],
["class-name", "clienttype"],
["class-name", "code"],
["class-name", "completiontriggererrorlevel"],
["class-name", "connectiontype"],
["class-name", "database"],
["class-name", "dataclassification"],
["class-name", "datascope"],
["class-name", "date"],
["class-name", "dateformula"],
["class-name", "datetime"],
["class-name", "decimal"],
["class-name", "defaultlayout"],
["class-name", "dialog"],
["class-name", "dictionary"],
["class-name", "dotnetassembly"],
["class-name", "dotnettypedeclaration"],
["class-name", "duration"],
["class-name", "errorinfo"],
["class-name", "errortype"],
["class-name", "executioncontext"],
["class-name", "executionmode"],
["class-name", "fieldclass"],
["class-name", "fieldref"],
["class-name", "fieldtype"],
["class-name", "file"],
["class-name", "filterpagebuilder"],
["class-name", "guid"],
["class-name", "httpclient"],
["class-name", "httpcontent"],
["class-name", "httpheaders"],
["class-name", "httprequestmessage"],
["class-name", "httpresponsemessage"],
["class-name", "instream"],
["class-name", "integer"],
["class-name", "joker"],
["class-name", "jsonarray"],
["class-name", "jsonobject"],
["class-name", "jsontoken"],
["class-name", "jsonvalue"],
["class-name", "keyref"],
["class-name", "list"],
["class-name", "moduledependencyinfo"],
["class-name", "moduleinfo"],
["class-name", "none"],
["class-name", "notification"],
["class-name", "notificationscope"],
["class-name", "objecttype"],
["class-name", "option"],
["class-name", "outstream"],
["class-name", "pageresult"],
["class-name", "record"],
["class-name", "recordid"],
["class-name", "recordref"],
["class-name", "reportformat"],
["class-name", "securityfilter"],
["class-name", "sessionsettings"],
["class-name", "tableconnectiontype"],
["class-name", "tablefilter"],
["class-name", "testaction"],
["class-name", "testfield"],
["class-name", "testfilterfield"],
["class-name", "testpage"],
["class-name", "testpermissions"],
["class-name", "testrequestpage"],
["class-name", "text"],
["class-name", "textbuilder"],
["class-name", "textconst"],
["class-name", "textencoding"],
["class-name", "time"],
["class-name", "transactionmodel"],
["class-name", "transactiontype"],
["class-name", "variant"],
["class-name", "verbosity"],
["class-name", "version"],
["class-name", "view"],
["class-name", "views"],
["class-name", "webserviceactioncontext"],
["class-name", "webserviceactionresultcode"],
["class-name", "xmlattribute"],
["class-name", "xmlattributecollection"],
["class-name", "xmlcdata"],
["class-name", "xmlcomment"],
["class-name", "xmldeclaration"],
["class-name", "xmldocument"],
["class-name", "xmldocumenttype"],
["class-name", "xmlelement"],
["class-name", "xmlnamespacemanager"],
["class-name", "xmlnametable"],
["class-name", "xmlnode"],
["class-name", "xmlnodelist"],
["class-name", "xmlprocessinginstruction"],
["class-name", "xmlreadoptions"],
["class-name", "xmltext"],
["class-name", "xmlwriteoptions"]
]

----------------------------------------------------

Checks for class names.
17 changes: 17 additions & 0 deletions tests/languages/al/comment_feature.test
@@ -0,0 +1,17 @@
// comment
/**/
/*
comment
*/

----------------------------------------------------

[
["comment", "// comment"],
["comment", "/**/"],
["comment", "/*\n comment\n*/"]
]

----------------------------------------------------

Checks for comments.

0 comments on commit b909f9b

Please sign in to comment.