From 4ee30807fcf673eca5df1cb23dc09f66b188fce6 Mon Sep 17 00:00:00 2001 From: Torben Leth Date: Sat, 8 Aug 2026 15:02:32 +0200 Subject: [PATCH] Add AL (Microsoft Dynamics 365 Business Central) AL is the language of Microsoft Dynamics 365 Business Central. It is recognised by GitHub Linguist and has editor support in VS Code, Zed, Sublime Text and Helix. Line comments are //, block comments /* */, and string literals are single quoted, with an embedded quote written ''. The example file covers all three, including strings containing /* and // so that they are counted as code rather than opening a comment, and a branch so the complexity checks are exercised. processor/constants.go and LANGUAGES.md are regenerated with go generate. The .al extension is shared with Perl's AutoLoader, but nothing in languages.json currently claims it, so this adds no ambiguity. I explicitly licence this contribution under the MIT licence. --- LANGUAGES.md | 1 + examples/language/al.al | 35 ++++++++++++++++++++++++++ languages.json | 7 ++++++ main_test.go | 1 + processor/constants.go | 54 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 examples/language/al.al diff --git a/LANGUAGES.md b/LANGUAGES.md index 2458b3955..ad42d0f2a 100644 --- a/LANGUAGES.md +++ b/LANGUAGES.md @@ -4,6 +4,7 @@ ABNF (abnf) ActionScript (as) Ada (ada,adb,ads,pad) Agda (agda) +AL (al) Alchemist (crn) Alex (x) Algol 68 (a68) diff --git a/examples/language/al.al b/examples/language/al.al new file mode 100644 index 000000000..17c1b97ce --- /dev/null +++ b/examples/language/al.al @@ -0,0 +1,35 @@ +/* AL is the language of Microsoft Dynamics 365 Business Central. + This block comment spans three lines and should be counted + as three comment lines. */ + +namespace MyCompany.Sales; + +using Microsoft.Foundation; + +table 50100 "My Table" +{ + // a standalone line comment + fields + { + field(1; Name; Text[50]) + { + Caption = 'Name'; + } + } + + procedure Compute(Value: Decimal): Decimal + var + Total: Decimal; + Note: Text; + begin + Total := Value * 2; // double it + IF Total > 100 THEN // legacy upper case AL + Total := 100; + Note := 'It''s at https://example.com'; + Note := 'not /* a comment */ either'; + Note := '// not a comment either'; + while Total > 200 do + Total -= 1; + exit(Total); + end; +} diff --git a/languages.json b/languages.json index 47a13e00c..8eb2890e1 100644 --- a/languages.json +++ b/languages.json @@ -25,6 +25,13 @@ "multi_line": [], "quotes": [] }, + "AL": { + "complexitychecks": ["if ", "if(", "IF ", "IF(", "case ", "CASE ", "while ", "WHILE ", "for ", "FOR ", "foreach ", "FOREACH ", "until ", "UNTIL ", "else ", "ELSE ", "and ", "AND ", "or ", "OR ", "xor ", "XOR ", "not ", "NOT "], + "extensions": ["al"], + "line_comment": ["//"], + "multi_line": [["/*", "*/"]], + "quotes": [{"end": "'", "start": "'"}] + }, "Apex": { "complexitychecks": [ "for ", diff --git a/main_test.go b/main_test.go index ef478bbba..27b5d0204 100644 --- a/main_test.go +++ b/main_test.go @@ -835,6 +835,7 @@ func TestLanguageNameTruncate(t *testing.T) { func TestSpecificLanguages(t *testing.T) { languages := [...]string{ "ABNF", + "AL", "Alchemist", "Algol 68", "Alloy", diff --git a/processor/constants.go b/processor/constants.go index fd4078721..4340cd0c1 100644 --- a/processor/constants.go +++ b/processor/constants.go @@ -55,6 +55,60 @@ var languageDatabase = map[string]Language{ FileNames: []string{}, SheBangs: []string{}, }, + "AL": { + LineComment: []string{ + "//", + }, + ComplexityChecks: []string{ + "if ", + "if(", + "IF ", + "IF(", + "case ", + "CASE ", + "while ", + "WHILE ", + "for ", + "FOR ", + "foreach ", + "FOREACH ", + "until ", + "UNTIL ", + "else ", + "ELSE ", + "and ", + "AND ", + "or ", + "OR ", + "xor ", + "XOR ", + "not ", + "NOT ", + }, + Extensions: []string{ + "al", + }, + ExtensionFile: false, + MultiLine: [][]string{ + { + "/*", + "*/", + }, + }, + Quotes: []Quote{ + { + Start: "'", + End: "'", + IgnoreEscape: false, + DocString: false, + }, + }, + NestedMultiLine: false, + Keywords: []string{}, + Heuristics: []Heuristic{}, + FileNames: []string{}, + SheBangs: []string{}, + }, "APL": { LineComment: []string{ "⍝",