forked from hush-shell/hush
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hush-shell#32 from caioraposo/vis-syntax
Add vis editor syntax highlighter
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vis.ftdetect.filetypes.hush = { | ||
ext = { "%.hsh$" }, | ||
} |