1 package m
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Modula2 = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Modula-2",
12 Aliases: []string{"modula2", "m2"},
13 Filenames: []string{"*.def", "*.mod"},
14 MimeTypes: []string{"text/x-modula2"},
15 DotAll: true,
16 },
17 modula2Rules,
18 ))
19
20 func modula2Rules() Rules {
21 return Rules{
22 "whitespace": {
23 {`\n+`, Text, nil},
24 {`\s+`, Text, nil},
25 },
26 "dialecttags": {
27 {`\(\*!m2pim\*\)`, CommentSpecial, nil},
28 {`\(\*!m2iso\*\)`, CommentSpecial, nil},
29 {`\(\*!m2r10\*\)`, CommentSpecial, nil},
30 {`\(\*!objm2\*\)`, CommentSpecial, nil},
31 {`\(\*!m2iso\+aglet\*\)`, CommentSpecial, nil},
32 {`\(\*!m2pim\+gm2\*\)`, CommentSpecial, nil},
33 {`\(\*!m2iso\+p1\*\)`, CommentSpecial, nil},
34 {`\(\*!m2iso\+xds\*\)`, CommentSpecial, nil},
35 },
36 "identifiers": {
37 {`([a-zA-Z_$][\w$]*)`, Name, nil},
38 },
39 "prefixed_number_literals": {
40 {`0b[01]+(\'[01]+)*`, LiteralNumberBin, nil},
41 {`0[ux][0-9A-F]+(\'[0-9A-F]+)*`, LiteralNumberHex, nil},
42 },
43 "plain_number_literals": {
44 {`[0-9]+(\'[0-9]+)*\.[0-9]+(\'[0-9]+)*[eE][+-]?[0-9]+(\'[0-9]+)*`, LiteralNumberFloat, nil},
45 {`[0-9]+(\'[0-9]+)*\.[0-9]+(\'[0-9]+)*`, LiteralNumberFloat, nil},
46 {`[0-9]+(\'[0-9]+)*`, LiteralNumberInteger, nil},
47 },
48 "suffixed_number_literals": {
49 {`[0-7]+B`, LiteralNumberOct, nil},
50 {`[0-7]+C`, LiteralNumberOct, nil},
51 {`[0-9A-F]+H`, LiteralNumberHex, nil},
52 },
53 "string_literals": {
54 {`'(\\\\|\\'|[^'])*'`, LiteralString, nil},
55 {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
56 },
57 "digraph_operators": {
58 {`\*\.`, Operator, nil},
59 {`\+>`, Operator, nil},
60 {`<>`, Operator, nil},
61 {`<=`, Operator, nil},
62 {`>=`, Operator, nil},
63 {`==`, Operator, nil},
64 {`::`, Operator, nil},
65 {`:=`, Operator, nil},
66 {`\+\+`, Operator, nil},
67 {`--`, Operator, nil},
68 },
69 "unigraph_operators": {
70 {`[+-]`, Operator, nil},
71 {`[*/]`, Operator, nil},
72 {`\\`, Operator, nil},
73 {`[=#<>]`, Operator, nil},
74 {`\^`, Operator, nil},
75 {`@`, Operator, nil},
76 {`&`, Operator, nil},
77 {`~`, Operator, nil},
78 {"`", Operator, nil},
79 },
80 "digraph_punctuation": {
81 {`\.\.`, Punctuation, nil},
82 {`<<`, Punctuation, nil},
83 {`>>`, Punctuation, nil},
84 {`->`, Punctuation, nil},
85 {`\|#`, Punctuation, nil},
86 {`##`, Punctuation, nil},
87 {`\|\*`, Punctuation, nil},
88 },
89 "unigraph_punctuation": {
90 {`[()\[\]{},.:;|]`, Punctuation, nil},
91 {`!`, Punctuation, nil},
92 {`\?`, Punctuation, nil},
93 },
94 "comments": {
95 {`^//.*?\n`, CommentSingle, nil},
96 {`\(\*([^$].*?)\*\)`, CommentMultiline, nil},
97 {`/\*(.*?)\*/`, CommentMultiline, nil},
98 },
99 "pragmas": {
100 {`<\*.*?\*>`, CommentPreproc, nil},
101 {`\(\*\$.*?\*\)`, CommentPreproc, nil},
102 },
103 "root": {
104 Include("whitespace"),
105 Include("dialecttags"),
106 Include("pragmas"),
107 Include("comments"),
108 Include("identifiers"),
109 Include("suffixed_number_literals"),
110 Include("prefixed_number_literals"),
111 Include("plain_number_literals"),
112 Include("string_literals"),
113 Include("digraph_punctuation"),
114 Include("digraph_operators"),
115 Include("unigraph_punctuation"),
116 Include("unigraph_operators"),
117 },
118 }
119 }
120
View as plain text