From 8a420ecc4c1ed50111464ec66901bd983eaf2dbd Mon Sep 17 00:00:00 2001 From: qiu-x Date: Wed, 29 Jun 2022 07:56:51 +0200 Subject: Resync the lexers with Scintillua - Resync the lexers with Scintillua - Update the lexer readme - Update `zenburn` theme to fix some highlighting issues - lexers: redirect print function to vis:info() - Fix support for custom style names - As per error message "lexer.delimited_range() is deprecated, use lexer.range()". - Remove remaining `lexer.delimited_range()` call - Set syntax to `nil` if the file type has no matching lexer - Updated Go lexer for Go 1.18. - lexers/dsv: convert to new lexer format (cherry picked from commit 9edbc3cd9ea1d7142b1305840432a3d2739e755a) - lexers/gemini: disable legacy gemini lexer This reverts commit 468f9ee1b027a7ce98b1a249fa1af5888feeb989. It is in legacy format and of questionable quality. Ideally it should be contributed upstream from where it will eventually trickle down to us. - lexers/git-rebase: convert to new lexer format (cherry picked from commit 4000a4cc9ac4a4c2869dfae772b977a82aee8d8c) - lexers/strace: convert to new lexer format (cherry picked from commit e420451320d97eb164f5629c1bcfab0b595be29d) - lexers/typescript: add new upstream lexer revision 28e2b60 (cherry picked from commit 7326e6deecdaa75fa94ae9ebdb653f9f907b33f2) - use `package.searchpath` instead of a local `searchpath` function - Restore `filetype: support filetype detection via hashbang` - Remove redundant comment - Restore gemini lexer --- lua/lexers/strace.lua | 59 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'lua/lexers/strace.lua') diff --git a/lua/lexers/strace.lua b/lua/lexers/strace.lua index 3547dd2..846c4fc 100644 --- a/lua/lexers/strace.lua +++ b/lua/lexers/strace.lua @@ -1,34 +1,35 @@ -- Copyright 2017-2021 Marc André Tanner. See LICENSE. -- strace(1) output lexer -local l = require('lexer') -local token, word_match = l.token, l.word_match +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match local S, B = lpeg.S, lpeg.B -local M = {_NAME = 'strace'} - -local ws = token(l.WHITESPACE, l.space^1) -local string = token(l.STRING, l.delimited_range('"', true) + l.delimited_range("'", true)) -local number = token(l.NUMBER, l.float + l.integer) -local constant = token(l.CONSTANT, (l.upper + '_') * (l.upper + l.digit + '_')^0) -local syscall = token(l.KEYWORD, l.starts_line(l.word)) -local operator = token(l.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}')) -local comment = token(l.COMMENT, l.nested_pair('/*', '*/') + (l.delimited_range('()') * l.newline)) -local result = token(l.TYPE, B(' = ') * l.integer) -local identifier = token(l.IDENTIFIER, l.word) - -M._rules = { - {'whitespace', ws}, - {'syscall', syscall}, - {'constant', constant}, - {'string', string}, - {'comment', comment}, - {'result', result}, - {'identifier', identifier}, - {'number', number}, - {'operator', operator}, -} - -M._LEXBYLINE = true - -return M +local lex = lexer.new('strace', {lex_by_line = true}) + +-- Whitespace +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Syscall +lex:add_rule('syscall', token(lexer.KEYWORD, lexer.starts_line(lexer.word))) + +-- Upper case constants +lex:add_rule('constant', token(lexer.CONSTANT, + (lexer.upper + '_') * (lexer.upper + lexer.digit + '_')^0)) + +-- Single and double quoted 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 and text in parentheses at the line end +local comment = lexer.range('/*', '*/') +local description = lexer.range('(', ')') * lexer.newline +lex:add_rule('comment', token(lexer.COMMENT, comment + description)) + +lex:add_rule('result', token(lexer.TYPE, B(' = ') * lexer.integer)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) +lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer)) +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}'))) + +return lex -- cgit v1.2.3