vhdl.go

 1package v
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// VHDL lexer.
 9var VHDL = internal.Register(MustNewLexer(
10	&Config{
11		Name:            "VHDL",
12		Aliases:         []string{"vhdl"},
13		Filenames:       []string{"*.vhdl", "*.vhd"},
14		MimeTypes:       []string{"text/x-vhdl"},
15		CaseInsensitive: true,
16	},
17	Rules{
18		"root": {
19			{`\n`, Text, nil},
20			{`\s+`, Text, nil},
21			{`\\\n`, Text, nil},
22			{`--.*?$`, CommentSingle, nil},
23			{`'(U|X|0|1|Z|W|L|H|-)'`, LiteralStringChar, nil},
24			{`[~!%^&*+=|?:<>/-]`, Operator, nil},
25			{`'[a-z_]\w*`, NameAttribute, nil},
26			{`[()\[\],.;\']`, Punctuation, nil},
27			{`"[^\n\\"]*"`, LiteralString, nil},
28			{`(library)(\s+)([a-z_]\w*)`, ByGroups(Keyword, Text, NameNamespace), nil},
29			{`(use)(\s+)(entity)`, ByGroups(Keyword, Text, Keyword), nil},
30			{`(use)(\s+)([a-z_][\w.]*\.)(all)`, ByGroups(Keyword, Text, NameNamespace, Keyword), nil},
31			{`(use)(\s+)([a-z_][\w.]*)`, ByGroups(Keyword, Text, NameNamespace), nil},
32			{`(std|ieee)(\.[a-z_]\w*)`, ByGroups(NameNamespace, NameNamespace), nil},
33			{Words(``, `\b`, `std`, `ieee`, `work`), NameNamespace, nil},
34			{`(entity|component)(\s+)([a-z_]\w*)`, ByGroups(Keyword, Text, NameClass), nil},
35			{`(architecture|configuration)(\s+)([a-z_]\w*)(\s+)(of)(\s+)([a-z_]\w*)(\s+)(is)`, ByGroups(Keyword, Text, NameClass, Text, Keyword, Text, NameClass, Text, Keyword), nil},
36			{`([a-z_]\w*)(:)(\s+)(process|for)`, ByGroups(NameClass, Operator, Text, Keyword), nil},
37			// This seems to cause a recursive loop.
38			// {`(end)(\s+)`, ByGroups(UsingSelf("root"), Text), Push("endblock")},
39			{`(end)(\s+)`, ByGroups(Keyword, Text), Push("endblock")},
40			Include("types"),
41			Include("keywords"),
42			Include("numbers"),
43			{`[a-z_]\w*`, Name, nil},
44		},
45		"endblock": {
46			Include("keywords"),
47			{`[a-z_]\w*`, NameClass, nil},
48			{`(\s+)`, Text, nil},
49			{`;`, Punctuation, Pop(1)},
50		},
51		"types": {
52			{Words(``, `\b`, `boolean`, `bit`, `character`, `severity_level`, `integer`, `time`, `delay_length`, `natural`, `positive`, `string`, `bit_vector`, `file_open_kind`, `file_open_status`, `std_ulogic`, `std_ulogic_vector`, `std_logic`, `std_logic_vector`, `signed`, `unsigned`), KeywordType, nil},
53		},
54		"keywords": {
55			{Words(``, `\b`, `abs`, `access`, `after`, `alias`, `all`, `and`, `architecture`, `array`, `assert`, `attribute`, `begin`, `block`, `body`, `buffer`, `bus`, `case`, `component`, `configuration`, `constant`, `disconnect`, `downto`, `else`, `elsif`, `end`, `entity`, `exit`, `file`, `for`, `function`, `generate`, `generic`, `group`, `guarded`, `if`, `impure`, `in`, `inertial`, `inout`, `is`, `label`, `library`, `linkage`, `literal`, `loop`, `map`, `mod`, `nand`, `new`, `next`, `nor`, `not`, `null`, `of`, `on`, `open`, `or`, `others`, `out`, `package`, `port`, `postponed`, `procedure`, `process`, `pure`, `range`, `record`, `register`, `reject`, `rem`, `return`, `rol`, `ror`, `select`, `severity`, `signal`, `shared`, `sla`, `sll`, `sra`, `srl`, `subtype`, `then`, `to`, `transport`, `type`, `units`, `until`, `use`, `variable`, `wait`, `when`, `while`, `with`, `xnor`, `xor`), Keyword, nil},
56		},
57		"numbers": {
58			{`\d{1,2}#[0-9a-f_]+#?`, LiteralNumberInteger, nil},
59			{`\d+`, LiteralNumberInteger, nil},
60			{`(\d+\.\d*|\.\d+|\d+)E[+-]?\d+`, LiteralNumberFloat, nil},
61			{`X"[0-9a-f_]+"`, LiteralNumberHex, nil},
62			{`O"[0-7_]+"`, LiteralNumberOct, nil},
63			{`B"[01_]+"`, LiteralNumberBin, nil},
64		},
65	},
66))