1 package v
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var VHDL = internal.Register(MustNewLazyLexer(
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 vhdlRules,
18 ))
19
20 func vhdlRules() Rules {
21 return Rules{
22 "root": {
23 {`\n`, Text, nil},
24 {`\s+`, Text, nil},
25 {`\\\n`, Text, nil},
26 {`--.*?$`, CommentSingle, nil},
27 {`'(U|X|0|1|Z|W|L|H|-)'`, LiteralStringChar, nil},
28 {`[~!%^&*+=|?:<>/-]`, Operator, nil},
29 {`'[a-z_]\w*`, NameAttribute, nil},
30 {`[()\[\],.;\']`, Punctuation, nil},
31 {`"[^\n\\"]*"`, LiteralString, nil},
32 {`(library)(\s+)([a-z_]\w*)`, ByGroups(Keyword, Text, NameNamespace), nil},
33 {`(use)(\s+)(entity)`, ByGroups(Keyword, Text, Keyword), nil},
34 {`(use)(\s+)([a-z_][\w.]*\.)(all)`, ByGroups(Keyword, Text, NameNamespace, Keyword), nil},
35 {`(use)(\s+)([a-z_][\w.]*)`, ByGroups(Keyword, Text, NameNamespace), nil},
36 {`(std|ieee)(\.[a-z_]\w*)`, ByGroups(NameNamespace, NameNamespace), nil},
37 {Words(``, `\b`, `std`, `ieee`, `work`), NameNamespace, nil},
38 {`(entity|component)(\s+)([a-z_]\w*)`, ByGroups(Keyword, Text, NameClass), nil},
39 {`(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},
40 {`([a-z_]\w*)(:)(\s+)(process|for)`, ByGroups(NameClass, Operator, Text, Keyword), nil},
41
42
43 {`(end)(\s+)`, ByGroups(Keyword, Text), Push("endblock")},
44 Include("types"),
45 Include("keywords"),
46 Include("numbers"),
47 {`[a-z_]\w*`, Name, nil},
48 },
49 "endblock": {
50 Include("keywords"),
51 {`[a-z_]\w*`, NameClass, nil},
52 {`(\s+)`, Text, nil},
53 {`;`, Punctuation, Pop(1)},
54 },
55 "types": {
56 {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},
57 },
58 "keywords": {
59 {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},
60 },
61 "numbers": {
62 {`\d{1,2}#[0-9a-f_]+#?`, LiteralNumberInteger, nil},
63 {`\d+`, LiteralNumberInteger, nil},
64 {`(\d+\.\d*|\.\d+|\d+)E[+-]?\d+`, LiteralNumberFloat, nil},
65 {`X"[0-9a-f_]+"`, LiteralNumberHex, nil},
66 {`O"[0-7_]+"`, LiteralNumberOct, nil},
67 {`B"[01_]+"`, LiteralNumberBin, nil},
68 },
69 }
70 }
71
View as plain text