modula2.go

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