aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_bazel.lua
blob: 8b0348ebdd3b48222b7b7ef359e0a63407048b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
--- Author: Rohan Vashisht: https://github.com/rohanvashisht1234/
-- mod-version:3
------------ IMPORT LIB ------------
local syntax_highlight = require("core.syntax")
------------------------------------

------------- DATABASE -------------

---- SYMBOLS ----
local SYMBOLS = {}

local KEYWORDS = {
  "break",
  "continue",
  "elif",
  "else",
  "for",
  "if",
  "pass",
  "return",
  "True",
  "False"
}

local KEYWORDS2 = {
  "as",
  "assert",
  "class",
  "del",
  "except",
  "finally",
  "from",
  "global",
  "import",
  "in",
  "is",
  "lambda",
  "nonlocal",
  "raise",
  "try",
  "while",
  "with",
  "yield"
}

local LITERALS = {
  "all",
  "any",
  "bool",
  "dict",
  "dir",
  "enumerate",
  "getattr",
  "hasattr",
  "hash",
  "int",
  "len",
  "list",
  "load",
  "max",
  "min",
  "repr",
  "reversed",
  "sorted",
  "str",
  "tuple",
  "type",
  "zip"
}
-----------------

---- PATTERNS ----
local PATTERNS = {
  { pattern = { '"', '"', '\\' }, type = "string"   },  -- tested ok
  { pattern = "#.*",              type = "comment"  },  -- tested ok
  { pattern = "[!%-/*?:=><]",     type = "operator" },  -- tested ok
  { pattern = "-?%d+[%d%.eE_]*",  type = "number"   },  -- tested ok
  { pattern = '[%a_][%w_]*%f[(]', type = 'function' },  -- tested ok
  { pattern = "-?%d+[%d%.eE_]*",  type = "number"   },  -- tested ok
  { pattern = "[%a_][%w_]*",      type = "normal"   }   -- tested ok
}
------------------
------------------------------------

--------------- MAIN ---------------
for _, keyword in ipairs(KEYWORDS) do
  SYMBOLS[keyword] = "keyword"
end
for _, keyword2 in ipairs(KEYWORDS2) do
  SYMBOLS[keyword2] = "keyword2"
end
for _, literal in ipairs(LITERALS) do
  SYMBOLS[literal] = "literal"
end
syntax_highlight.add {
  name = "Bazel",
  files = {"%.bazel$","%.bzl$"},
  comment = "#",
  patterns = PATTERNS,
  symbols = SYMBOLS,
}
------------------------------------