vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit ebba98dec62af9f7cb0f8e69a202a5c31d849edb parent 916cc9702b76d49561a34b4a354347ad6a904874 Author: orbitalquark <70453897+orbitalquark@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:42:10 -0400 Rename 'ansi_c', 'dmd', and 'rstats' lexers to 'c', 'd', and 'r' Originally this was to prevent clashes with Textadept's language-specific key handling, but this is no longer applicable. Diffstat:
| R | lua/lexers/ansi_c.lua -> lua/lexers/c.lua | | | 0 | |
| R | lua/lexers/dmd.lua -> lua/lexers/d.lua | | | 0 | |
| M | lua/lexers/glsl.lua | | | 2 | +- |
| M | lua/lexers/lexer.lua | | | 12 | ++++-------- |
| M | lua/lexers/output.lua | | | 2 | +- |
| A | lua/lexers/r.lua | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| D | lua/lexers/rstats.lua | | | 52 | ---------------------------------------------------- |
7 files changed, 58 insertions(+), 62 deletions(-)
diff --git a/lua/lexers/ansi_c.lua b/lua/lexers/c.lua diff --git a/lua/lexers/dmd.lua b/lua/lexers/d.lua diff --git a/lua/lexers/glsl.lua b/lua/lexers/glsl.lua @@ -4,7 +4,7 @@ local lexer = lexer local P, S = lpeg.P, lpeg.S -local lex = lexer.new(..., {inherit = lexer.load('ansi_c')}) +local lex = lexer.new(..., {inherit = lexer.load('c')}) -- Word lists. lex:set_word_list(lexer.KEYWORD, { diff --git a/lua/lexers/lexer.lua b/lua/lexers/lexer.lua @@ -50,9 +50,6 @@ -- lexer should be the name of your programming language in lower case followed by a *.lua* -- extension. For example, a new Lua lexer has the name *lua.lua*. -- --- Note: Try to refrain from using one-character language names like "c", "d", or "r". For --- example, Scintillua uses "ansi_c", "dmd", and "rstats", respectively. --- -- #### New Lexer Template -- -- There is a *lexers/template.txt* file that contains a simple template for a new lexer. Feel @@ -1612,8 +1609,8 @@ function M.detect(filename, line) bib = 'bibtex', -- boo = 'boo', -- cs = 'csharp', -- - c = 'ansi_c', C = 'ansi_c', cc = 'cpp', cpp = 'cpp', cxx = 'cpp', ['c++'] = 'cpp', h = 'cpp', - hh = 'cpp', hpp = 'cpp', hxx = 'cpp', ['h++'] = 'cpp', -- + c = 'c', C = 'c', cc = 'cpp', cpp = 'cpp', cxx = 'cpp', ['c++'] = 'cpp', h = 'cpp', hh = 'cpp', + hpp = 'cpp', hxx = 'cpp', ['h++'] = 'cpp', -- ck = 'chuck', -- clj = 'clojure', cljs = 'clojure', cljc = 'clojure', edn = 'clojure', -- ['CMakeLists.txt'] = 'cmake', cmake = 'cmake', ['cmake.in'] = 'cmake', ctest = 'cmake', @@ -1622,7 +1619,7 @@ function M.detect(filename, line) cr = 'crystal', -- css = 'css', -- cu = 'cuda', cuh = 'cuda', -- - d = 'dmd', di = 'dmd', -- + d = 'd', di = 'd', -- dart = 'dart', -- desktop = 'desktop', -- diff = 'diff', patch = 'diff', -- @@ -1700,8 +1697,7 @@ function M.detect(filename, line) proto = 'protobuf', -- pure = 'pure', -- sc = 'python', py = 'python', pyw = 'python', -- - R = 'rstats', Rout = 'rstats', Rhistory = 'rstats', Rt = 'rstats', ['Rout.save'] = 'rstats', - ['Rout.fail'] = 'rstats', -- + R = 'r', Rout = 'r', Rhistory = 'r', Rt = 'r', ['Rout.save'] = 'r', ['Rout.fail'] = 'r', -- re = 'reason', -- r = 'rebol', reb = 'rebol', -- rst = 'rest', -- diff --git a/lua/lexers/output.lua b/lua/lexers/output.lua @@ -66,7 +66,7 @@ lex:add_rule('python', local lparen, rparen = text('('), text(')') local d_filename = filename((lexer.nonnewline - '(')^1) local d_error = message(lexer.to_eol(S('Ee') * 'rror')) * mark_error -lex:add_rule('dmd', starts_line(d_filename) * lparen * line * rparen * colon * d_error) +lex:add_rule('d', starts_line(d_filename) * lparen * line * rparen * colon * d_error) -- "filename" line X: message (gnuplot) local gp_filename = filename((lexer.nonnewline - '"')^1) diff --git a/lua/lexers/r.lua b/lua/lexers/r.lua @@ -0,0 +1,52 @@ +-- Copyright 2006-2024 Mitchell. See LICENSE. +-- R LPeg lexer. + +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('r') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch', 'try', 'while', -- + 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE', 'F', 'T', + -- Frequently used operators. + '|>', '%%', '%*%', '%/%', '%in%', '%o%', '%x%' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'array', 'character', 'closure', 'complex', 'data.frame', 'double', 'environment', 'expression', + 'externalptr', 'factor', 'function', 'integer', 'list', 'logical', 'matrix', 'numeric', + 'pairlist', 'promise', 'raw', 'symbol', 'vector' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, (lexer.number * P('i')^-1) * P('L')^-1)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('<->+*/^=.,:;|$()[]{}'))) + +-- Folding +lex:add_fold_point(lexer.OPERATOR, '(', ')') +lex:add_fold_point(lexer.OPERATOR, '[', ']') +lex:add_fold_point(lexer.OPERATOR, '{', '}') + +lexer.property['scintillua.comment'] = '#' + +return lex diff --git a/lua/lexers/rstats.lua b/lua/lexers/rstats.lua @@ -1,52 +0,0 @@ --- Copyright 2006-2024 Mitchell. See LICENSE. --- R LPeg lexer. - -local lexer = require('lexer') -local token, word_match = lexer.token, lexer.word_match -local P, S = lpeg.P, lpeg.S - -local lex = lexer.new('rstats') - --- Whitespace. -lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) - --- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ - 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch', 'try', 'while', -- - 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE', 'F', 'T', - -- Frequently used operators. - '|>', '%%', '%*%', '%/%', '%in%', '%o%', '%x%' -})) - --- Types. -lex:add_rule('type', token(lexer.TYPE, word_match{ - 'array', 'character', 'closure', 'complex', 'data.frame', 'double', 'environment', 'expression', - 'externalptr', 'factor', 'function', 'integer', 'list', 'logical', 'matrix', 'numeric', - 'pairlist', 'promise', 'raw', 'symbol', 'vector' -})) - --- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) - --- Strings. -local sq_str = lexer.range("'", true) -local dq_str = lexer.range('"', true) -lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) - --- Comments. -lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) - --- Numbers. -lex:add_rule('number', token(lexer.NUMBER, (lexer.number * P('i')^-1) * P('L')^-1)) - --- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S('<->+*/^=.,:;|$()[]{}'))) - --- Folding -lex:add_fold_point(lexer.OPERATOR, '(', ')') -lex:add_fold_point(lexer.OPERATOR, '[', ']') -lex:add_fold_point(lexer.OPERATOR, '{', '}') - -lexer.property['scintillua.comment'] = '#' - -return lex