Skip to content

Commit d11bdac

Browse files
guigui-78alecthomas
authored andcommitted
Add AL lexer
1 parent f4cddf0 commit d11bdac

File tree

3 files changed

+488
-0
lines changed

3 files changed

+488
-0
lines changed

Diff for: lexers/a/al.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package a
2+
3+
import (
4+
. "github.com/alecthomas/chroma" // nolint
5+
"github.com/alecthomas/chroma/lexers/internal"
6+
)
7+
8+
// Al lexer.
9+
var Al = internal.Register(MustNewLazyLexer(
10+
&Config{
11+
Name: "AL",
12+
Aliases: []string{"al"},
13+
Filenames: []string{"*.al", "*.dal"},
14+
MimeTypes: []string{"text/x-al"},
15+
DotAll: true,
16+
CaseInsensitive: true,
17+
},
18+
alRules,
19+
))
20+
21+
// https://github.com/microsoft/AL/blob/master/grammar/alsyntax.tmlanguage
22+
func alRules() Rules {
23+
return Rules{
24+
"root": {
25+
{`\s+`, TextWhitespace, nil},
26+
{`(?s)\/\*.*?\\*\*\/`, CommentMultiline, nil},
27+
{`(?s)//.*?\n`, CommentSingle, nil},
28+
{`\"([^\"])*\"`, Text, nil},
29+
{`'([^'])*'`, LiteralString, nil},
30+
{`\b(?i:(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`, Keyword, nil},
31+
{`\b(?i:(AND|DIV|MOD|NOT|OR|XOR))\b`, OperatorWord, nil},
32+
{`\b(?i:(AVERAGE|CONST|COUNT|EXIST|FIELD|FILTER|LOOKUP|MAX|MIN|ORDER|SORTING|SUM|TABLEDATA|UPPERLIMIT|WHERE|ASCENDING|DESCENDING))\b`, Keyword, nil},
33+
// Added new objects types of BC 2021 wave 1 (REPORTEXTENSION|Entitlement|PermissionSet|PermissionSetExtension)
34+
{`\b(?i:(CODEUNIT|PAGE|PAGEEXTENSION|PAGECUSTOMIZATION|DOTNET|ENUM|ENUMEXTENSION|VALUE|QUERY|REPORT|TABLE|TABLEEXTENSION|XMLPORT|PROFILE|CONTROLADDIN|REPORTEXTENSION|Entitlement|PermissionSet|PermissionSetExtension))\b`, Keyword, nil},
35+
{`\b(?i:(Action|Array|Automation|BigInteger|BigText|Blob|Boolean|Byte|Char|ClientType|Code|Codeunit|CompletionTriggerErrorLevel|ConnectionType|Database|DataClassification|DataScope|Date|DateFormula|DateTime|Decimal|DefaultLayout|Dialog|Dictionary|DotNet|DotNetAssembly|DotNetTypeDeclaration|Duration|Enum|ErrorInfo|ErrorType|ExecutionContext|ExecutionMode|FieldClass|FieldRef|FieldType|File|FilterPageBuilder|Guid|InStream|Integer|Joker|KeyRef|List|ModuleDependencyInfo|ModuleInfo|None|Notification|NotificationScope|ObjectType|Option|OutStream|Page|PageResult|Query|Record|RecordId|RecordRef|Report|ReportFormat|SecurityFilter|SecurityFiltering|Table|TableConnectionType|TableFilter|TestAction|TestField|TestFilterField|TestPage|TestPermissions|TestRequestPage|Text|TextBuilder|TextConst|TextEncoding|Time|TransactionModel|TransactionType|Variant|Verbosity|Version|XmlPort|HttpContent|HttpHeaders|HttpClient|HttpRequestMessage|HttpResponseMessage|JsonToken|JsonValue|JsonArray|JsonObject|View|Views|XmlAttribute|XmlAttributeCollection|XmlComment|XmlCData|XmlDeclaration|XmlDocument|XmlDocumentType|XmlElement|XmlNamespaceManager|XmlNameTable|XmlNode|XmlNodeList|XmlProcessingInstruction|XmlReadOptions|XmlText|XmlWriteOptions|WebServiceActionContext|WebServiceActionResultCode|SessionSettings))\b`, Keyword, nil},
36+
{`\b([<>]=|<>|<|>)\b?`, Operator, nil},
37+
{`\b(\-|\+|\/|\*)\b`, Operator, nil},
38+
{`\s*(\:=|\+=|-=|\/=|\*=)\s*?`, Operator, nil},
39+
{`\b(?i:(ADDFIRST|ADDLAST|ADDAFTER|ADDBEFORE|ACTION|ACTIONS|AREA|ASSEMBLY|CHARTPART|CUEGROUP|CUSTOMIZES|COLUMN|DATAITEM|DATASET|ELEMENTS|EXTENDS|FIELD|FIELDGROUP|FIELDATTRIBUTE|FIELDELEMENT|FIELDGROUPS|FIELDS|FILTER|FIXED|GRID|GROUP|MOVEAFTER|MOVEBEFORE|KEY|KEYS|LABEL|LABELS|LAYOUT|MODIFY|MOVEFIRST|MOVELAST|MOVEBEFORE|MOVEAFTER|PART|REPEATER|USERCONTROL|REQUESTPAGE|SCHEMA|SEPARATOR|SYSTEMPART|TABLEELEMENT|TEXTATTRIBUTE|TEXTELEMENT|TYPE))\b`, Keyword, nil},
40+
{`\s*[(\.\.)&\|]\s*`, Operator, nil},
41+
{`\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b`, LiteralNumber, nil},
42+
{`[;:,]`, Punctuation, nil},
43+
{`#[ \t]*(if|else|elif|endif|define|undef|region|endregion|pragma)\b.*?\n`, CommentPreproc, nil},
44+
{`\w+`, Text, nil},
45+
{`.`, Text, nil},
46+
},
47+
}
48+
}

Diff for: lexers/testdata/al.actual

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/// <summary>
2+
/// Manage Loyalty Benefits
3+
/// </summary>
4+
codeunit 50100 "Loyalty Benefits Management"
5+
{
6+
var
7+
Vendor: record Vendor;
8+
9+
trigger OnRun()
10+
begin
11+
end;
12+
13+
/// <summary>
14+
/// Adjust a Sales Order with loyalty level
15+
/// </summary>
16+
/// <param name="SalesHeader">Sales Header to adjust based on Customer Loyalty</param>
17+
procedure AdjustForLoyalty(var SalesHeader: record "Sales Header"): Integer;
18+
var
19+
Customer: record Customer;
20+
LoyaltyBenefits: interface ILoyaltyBenefits;
21+
Discount: Decimal;
22+
begin
23+
Customer.Get(SalesHeader."Sell-to Customer No.");
24+
25+
LoyaltyBenefits := Customer.Loyalty;
26+
Discount := 1;
27+
Discount := LoyaltyBenefits.GetDiscount();
28+
ApplyDiscount(SalesHeader, Discount);
29+
end;
30+
31+
/// <summary>
32+
/// Applies the Discount to the Sales Order
33+
/// </summary>
34+
/// <param name="SalesHeader">Sales Order</param>
35+
/// <param name="Discount">Discount to apply</param>
36+
local procedure "Apply Discount"(SalesHeader: record "Sales Header"; Discount: Decimal)
37+
begin
38+
// TODO: Implement
39+
end;
40+
}
41+
42+
43+
enum 50140 SomeEnum
44+
{
45+
value(0; None) { }
46+
}
47+
48+
#region interface stuff
49+
50+
interface ISuperGreat
51+
{
52+
procedure YesSir("c in c": codeunit FooBar);
53+
}
54+
55+
#endregion
56+
57+
table 50100 Customer
58+
{
59+
Access = Internal;
60+
TableType = Normal;
61+
62+
fields
63+
{
64+
field(1; "P K"; Integer)
65+
{
66+
}
67+
}
68+
}
69+
70+
/// <summary>
71+
/// Add the Loyalty fields to the Customer table.
72+
/// </summary>
73+
tableextension 50100 LoyaltyCustomerExt extends Customer
74+
{
75+
fields
76+
{
77+
/// <summary>
78+
/// Customer loyalty.
79+
/// </summary>
80+
field(50100; Loyalty; enum LoyaltyLevel)
81+
{
82+
}
83+
}
84+
}
85+
86+
/// <summary>
87+
/// Adds the Loyalty field to the General group on the "Customer Card"
88+
/// </summary>
89+
pageextension 50100 LoyaltyCustCardExt extends "Customer Card"
90+
{
91+
layout
92+
{
93+
addlast(General)
94+
{
95+
field(Loyalty; Rec.Loyalty) { }
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)