diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-21 16:06:25 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-06-21 16:06:25 +0200 |
commit | 10e12bbe481af7974739060f51210f7948fc1df9 (patch) | |
tree | 83722aca11901a5bf7ad433aac6a6b0ba05cf79a /config/essentials/vis/vis-ultisnips/testlpeg-snipmate.lua | |
parent | 4775688e796faece72c6621bcd94f6eb4ebac5ff (diff) | |
parent | c9cc72113521b793d1baa0d2f558b97478a6acf4 (diff) |
Merge branch 'main' of debuc.com:dotfiles
Diffstat (limited to 'config/essentials/vis/vis-ultisnips/testlpeg-snipmate.lua')
-rw-r--r-- | config/essentials/vis/vis-ultisnips/testlpeg-snipmate.lua | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/config/essentials/vis/vis-ultisnips/testlpeg-snipmate.lua b/config/essentials/vis/vis-ultisnips/testlpeg-snipmate.lua new file mode 100644 index 0000000..997365f --- /dev/null +++ b/config/essentials/vis/vis-ultisnips/testlpeg-snipmate.lua @@ -0,0 +1,160 @@ +local lpeg = require("lpeg") + +-------------------------------------------------------------------------------- + +-- Base definitions +-- local tws = lpeg.S(" ") ^ 1 +local tnewline = lpeg.S("\n") +-- local tlowcasedword = lpeg.R("az") ^ 1 +local tdigit = lpeg.locale()["digit"] +local talphanum = lpeg.locale()["alnum"] +local tanyprintable = lpeg.locale()["print"] +-- local tcontrol = lpeg.locale()["cntrl"] +local ttabtrigger = tanyprintable ^ 1 +local ttag = lpeg.Cg(lpeg.Cp(), "selstart") + * lpeg.P("${") + * lpeg.Cg(tdigit ^ 1, "tag-order") + * ((lpeg.S(":") * lpeg.Cg(talphanum ^ 1, "default-value") * lpeg.S("}")) + lpeg.S("}")) + * lpeg.Cg(lpeg.Cp(), "selend") +local tsnippetdecl = lpeg.P("snippet") * lpeg.S(" ") * lpeg.Cg(ttabtrigger, "tabtrigger") * tnewline +local tsnippetcontent = lpeg.C(lpeg.Cp() * (lpeg.S("\t ") ^ 1 * (lpeg.Ct(ttag) + tanyprintable) ^ 1 * tnewline) ^ 1) + +-- Constructs +local tsnippet = tsnippetdecl * tsnippetcontent +local tcomment = lpeg.S("#") * tanyprintable ^ 0 * tnewline + +-- The way grammar captures: +-- Every snippet gets its own table, and every table has: +-- 'tabtrigger' - the tabtrigger +-- [1] - full content +-- [2..n] - tags +local tsnippetsfile = lpeg.Ct((tcomment + lpeg.Ct(tsnippet) + tnewline) ^ 1) +-------------------------------------------------------------------------------- + +-- local testsingle = [[ +-- snippet sim +-- ${1:public} static int Main(string[] args) +-- { +-- ${0} +-- return 0; +-- } +-- ]] + +-- local testmulti = [[ +-- snippet sim +-- ${1:public} static int Main(string[] args) +-- { +-- ${0} +-- return 0; +-- } +-- snippet simc +-- public class Application +-- { +-- ${1:public} static int Main(string[] args) +-- { +-- ${0} +-- return 0; +-- } +-- } +-- snippet svm +-- ${1:public} static void Main(string[] args) +-- { +-- ${0} +-- } +-- ]] + +local testfile = [[ +# I'll most propably add more stuff in here like +# * List/Array constructio +# * Mostly used generics +# * Linq +# * Funcs, Actions, Predicates +# * Lambda +# * Events +# +# Feedback is welcome! +# +# Main +snippet sim + ${1:public} static int Main(string[] args) + { + ${0} + return 0; + } +snippet simc + public class Application + { + ${1:public} static int Main(string[] args) + { + ${0} + return 0; + } + } +snippet svm + ${1:public} static void Main(string[] args) + { + ${0} + } +# if condition +snippet if + if (${1:true}) + { + ${0:${VISUAL}} + } +snippet el + else + { + ${0:${VISUAL}} + } +]] + +-------------------------------------------------------------------------------- +-- Test + +local function print_table(tableau, tabwidth) + if tabwidth == nil then + tabwidth = 0 + end + + -- Iterate + for k, v in pairs(tableau) do + local tabs = ("\t"):rep(tabwidth) + + print(tabs .. k .. ':"' .. tostring(v) .. '"') + if type(v) == "table" then + print_table(v, tabwidth + 1) + end + end +end + +--print("------------ header ------------------------------------") +--p = lpeg.Ct(tsnippetdecl) +--t = p:match([[ +--snippet classy +--]]) +--print_table(t) +--print("--------------------------------------------------------------") + +--print("------------ tag ------------------------------------") +--print_table( +-- lpeg.Ct(ttag):match('${0:VISUAL}') +--) +--print_table( +-- lpeg.Ct(ttag):match('${12:Badonkadong}') +--) +--print_table( +-- lpeg.Ct(ttag):match('${1}') +--) +--print("--------------------------------------------------------------") + +--print("------------ single snippet test ------------------------------------") +--print_table(lpeg.Ct(tsnippet):match(testsingle)) +--print("--------------------------------------------------------------") + +--print("------------ multi snippet test ------------------------------------") +--print_table(lpeg.Ct(tsnippetsfile):match(testmulti)) +--print("--------------------------------------------------------------") + +print("------------ file with comments -------------------------------------") +print_table(tsnippetsfile:match(testfile)) +print("--------------------------------------------------------------") |