Skip to content

Commit

Permalink
Add vis editor syntax highlighter
Browse files Browse the repository at this point in the history
Replace tabs with spaces
  • Loading branch information
caioraposo committed Jul 14, 2022
1 parent 1fc19f5 commit 9a9a4b4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions syntax-highlight/vis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# hush.lua

Vis editor syntax highlighting for _Hush_.

## Installation

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.
51 changes: 51 additions & 0 deletions syntax-highlight/vis/hush.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- ? LPeg lexer.

local l = require('lexer')
local token, word_match = l.token, l.word_match
local P, R, S = lpeg.P, lpeg.R, lpeg.S

local M = {_NAME = 'hush'}

local comment = token(l.COMMENT, '#' * l.nonnewline_esc^0)

local constant = token(l.CONSTANT, word_match{
'true', 'false',
})

local identifier = token(l.IDENTIFIER, l.word)

local keyword = token(l.KEYWORD, word_match{
'let', 'if', 'then', 'else', 'elseif', 'end', 'for', 'in', 'do', 'while',
'function', 'return', 'not', 'and', 'or', 'true', 'false', 'nil', 'break',
'self',
})

local operator = token(l.OPERATOR, word_match{
'and', 'or', 'not',
} + S('+-/*%<>!=[]'))

local number = token(l.NUMBER, l.float + l.integer)

local sq_str = l.delimited_range("'", true)
local dq_str = l.delimited_range('"', true)
local string = token(l.STRING, sq_str + dq_str)

local type = token(l.TYPE, word_match{
'int', 'char', 'float', 'string', 'bool', 'array', 'dict',
})

local ws = token(l.WHITESPACE, l.space^1)

M._rules = {
{'constant', constant},
{'comment', comment},
{'keyword', keyword},
{'number', number},
{'operator', operator},
{'string', string},
{'type', type},
{'whitespace', ws},
{'identifier', identifier},
}

return M
3 changes: 3 additions & 0 deletions syntax-highlight/vis/hush_detect.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vis.ftdetect.filetypes.hush = {
ext = { "%.hsh$" },
}

0 comments on commit 9a9a4b4

Please sign in to comment.