From 9a9a4b4fbeae0689e4d834d9b471e8c676fb58dd Mon Sep 17 00:00:00 2001 From: Caio Raposo Date: Thu, 14 Jul 2022 17:12:42 -0300 Subject: [PATCH] Add vis editor syntax highlighter Replace tabs with spaces --- syntax-highlight/vis/README.md | 7 ++++ syntax-highlight/vis/hush.lua | 51 ++++++++++++++++++++++++++++ syntax-highlight/vis/hush_detect.lua | 3 ++ 3 files changed, 61 insertions(+) create mode 100644 syntax-highlight/vis/README.md create mode 100644 syntax-highlight/vis/hush.lua create mode 100644 syntax-highlight/vis/hush_detect.lua diff --git a/syntax-highlight/vis/README.md b/syntax-highlight/vis/README.md new file mode 100644 index 0000000..299a2b2 --- /dev/null +++ b/syntax-highlight/vis/README.md @@ -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. diff --git a/syntax-highlight/vis/hush.lua b/syntax-highlight/vis/hush.lua new file mode 100644 index 0000000..6791605 --- /dev/null +++ b/syntax-highlight/vis/hush.lua @@ -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 diff --git a/syntax-highlight/vis/hush_detect.lua b/syntax-highlight/vis/hush_detect.lua new file mode 100644 index 0000000..77b78a6 --- /dev/null +++ b/syntax-highlight/vis/hush_detect.lua @@ -0,0 +1,3 @@ +vis.ftdetect.filetypes.hush = { + ext = { "%.hsh$" }, +}