Skip to content

Commit 7fa2dc4

Browse files
authored
Merge pull request #32 from caioraposo/vis-syntax
Add vis editor syntax highlighter
2 parents 1fc19f5 + 9a9a4b4 commit 7fa2dc4

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

syntax-highlight/vis/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# hush.lua
2+
3+
Vis editor syntax highlighting for _Hush_.
4+
5+
## Installation
6+
7+
Copy hush.lua into $XDG\_CONFIG\_HOME/vis/lexers, copy hush\_detect.lua into $XDG\_CONFIG\_HOME/vis, and add require("hush\_detect") to your visrc.

syntax-highlight/vis/hush.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- ? LPeg lexer.
2+
3+
local l = require('lexer')
4+
local token, word_match = l.token, l.word_match
5+
local P, R, S = lpeg.P, lpeg.R, lpeg.S
6+
7+
local M = {_NAME = 'hush'}
8+
9+
local comment = token(l.COMMENT, '#' * l.nonnewline_esc^0)
10+
11+
local constant = token(l.CONSTANT, word_match{
12+
'true', 'false',
13+
})
14+
15+
local identifier = token(l.IDENTIFIER, l.word)
16+
17+
local keyword = token(l.KEYWORD, word_match{
18+
'let', 'if', 'then', 'else', 'elseif', 'end', 'for', 'in', 'do', 'while',
19+
'function', 'return', 'not', 'and', 'or', 'true', 'false', 'nil', 'break',
20+
'self',
21+
})
22+
23+
local operator = token(l.OPERATOR, word_match{
24+
'and', 'or', 'not',
25+
} + S('+-/*%<>!=[]'))
26+
27+
local number = token(l.NUMBER, l.float + l.integer)
28+
29+
local sq_str = l.delimited_range("'", true)
30+
local dq_str = l.delimited_range('"', true)
31+
local string = token(l.STRING, sq_str + dq_str)
32+
33+
local type = token(l.TYPE, word_match{
34+
'int', 'char', 'float', 'string', 'bool', 'array', 'dict',
35+
})
36+
37+
local ws = token(l.WHITESPACE, l.space^1)
38+
39+
M._rules = {
40+
{'constant', constant},
41+
{'comment', comment},
42+
{'keyword', keyword},
43+
{'number', number},
44+
{'operator', operator},
45+
{'string', string},
46+
{'type', type},
47+
{'whitespace', ws},
48+
{'identifier', identifier},
49+
}
50+
51+
return M

syntax-highlight/vis/hush_detect.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vis.ftdetect.filetypes.hush = {
2+
ext = { "%.hsh$" },
3+
}

0 commit comments

Comments
 (0)