From 6fc7f49449cb237e1aa37eb1025461fe3ea39589 Mon Sep 17 00:00:00 2001 From: seraphim <18ycm9tx@anonaddy.me> Date: Thu, 27 Aug 2026 11:50:43 +0700 Subject: . --- .config/vis/lexers/kdl.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .config/vis/lexers/kdl.lua (limited to '.config/vis/lexers') diff --git a/.config/vis/lexers/kdl.lua b/.config/vis/lexers/kdl.lua new file mode 100644 index 0000000..f9d324e --- /dev/null +++ b/.config/vis/lexers/kdl.lua @@ -0,0 +1,48 @@ +-- KDL LPeg lexer for vis. +-- Covers: // and /* */ comments, slashdash /-, quoted and raw strings, +-- type annotations (type), keywords, numbers, node/property identifiers. + +local lexer = lexer +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new(..., {fold_by_indentation = true}) + +-- Comments. +local line_comment = lexer.to_eol('//') +local block_comment = lexer.range('/*', '*/', false, false, true) +lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment)) + +-- Slashdash node suppression. +lex:add_rule('slashdash', lex:tag(lexer.OPERATOR, P('/-'))) + +-- Keywords. +lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lexer.word_match({'true', 'false', 'null'}))) + +-- Strings: raw #"..."# first so the hash prefixes are not split off, +-- then regular "..." strings. +local raw_str = lexer.range(P('#')^1 * '"', '"' * P('#')^1) +local dq_str = lexer.range('"') +lex:add_rule('string', lex:tag(lexer.STRING, raw_str + dq_str)) + +-- Type annotations like (path)file or (const). +local type_ann = P('(') * lexer.word * P(')') +lex:add_rule('type', lex:tag(lexer.TYPE, type_ann)) + +-- Numbers (int/float/hex/oct/bin; underscores are tolerated inside). +local num_pattern = + (lexer.number * + (S('_')^0 * lexer.number)^0) + + '0x' * (lpeg.R('09') + lpeg.R('af') + lpeg.R('AF') + '_')^1 + + '0o' * lpeg.R('07')^1 + + '0b' * lpeg.R('01')^1 +lex:add_rule('number', lex:tag(lexer.NUMBER, num_pattern)) + +-- Identifiers (node names, property keys). +lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) + +-- Operators / punctuation. +lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('{}()=;,/+\\'))) + +lexer.property['scintillua.comment'] = '//' + +return lex -- cgit v1.2.3