diff options
| author | qiu-x <alex@alexslomka.xyz> | 2022-06-29 07:56:51 +0200 |
|---|---|---|
| committer | Felix Van der Jeugt <felix.vanderjeugt@posteo.net> | 2022-11-29 21:57:18 +0100 |
| commit | 8a420ecc4c1ed50111464ec66901bd983eaf2dbd (patch) | |
| tree | f31d2186cafaee6e7f18d32fe99144c3e8148c00 /lua/lexers/fantom.lua | |
| parent | 981b90a203484182feace48471fe2b53dae7676f (diff) | |
| download | vis-8a420ecc4c1ed50111464ec66901bd983eaf2dbd.tar.gz vis-8a420ecc4c1ed50111464ec66901bd983eaf2dbd.tar.xz | |
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
Diffstat (limited to 'lua/lexers/fantom.lua')
| -rw-r--r-- | lua/lexers/fantom.lua | 119 |
1 files changed, 49 insertions, 70 deletions
diff --git a/lua/lexers/fantom.lua b/lua/lexers/fantom.lua index 7056620..776c597 100644 --- a/lua/lexers/fantom.lua +++ b/lua/lexers/fantom.lua @@ -1,32 +1,27 @@ +-- Copyright 2018-2022 Simeon Maryasin (MarSoft). See LICENSE. -- Fantom LPeg lexer. --- Based on Java LPeg lexer by Mitchell mitchell.att.foicica.com and Vim's Fantom syntax. --- By MarSoft. +-- Based on Java LPeg lexer by Mitchell and Vim's Fantom syntax. -local l = require('lexer') -local token, word_match = l.token, l.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S -local M = {_NAME = 'fantom'} +local lex = lexer.new('fantom') -- Whitespace. -local ws = token(l.WHITESPACE, l.space^2) +local ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', ws) --- Comments. -local line_comment = '//' * l.nonnewline_esc^0 -local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1 -local doc_comment = '**' * l.nonnewline_esc^0 -local comment = token(l.COMMENT, line_comment + block_comment + doc_comment) - --- Strings. -local sq_str = l.delimited_range("'", true) -local dq_str = l.delimited_range('"', true) -local string = token(l.STRING, sq_str + dq_str) - --- Numbers. -local number = token(l.NUMBER, (l.float + l.integer) * S('LlFfDd')^-1) +-- Classes. +local type = token(lexer.TYPE, lexer.word) +lex:add_rule('class_sequence', + token(lexer.KEYWORD, 'class') * ws * type * ( -- at most one inheritance spec + ws * token(lexer.OPERATOR, ':') * ws * type * + ( -- at least 0 (i.e. any number) of additional classes + ws^-1 * token(lexer.OPERATOR, ',') * ws^-1 * type)^0)^-1) -- Keywords. -local keyword = token(l.KEYWORD, word_match{ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ 'using', 'native', -- external 'goto', 'void', 'serializable', 'volatile', -- error 'if', 'else', 'switch', -- conditional @@ -35,7 +30,9 @@ local keyword = token(l.KEYWORD, word_match{ 'null', -- constant 'this', 'super', -- typedef 'new', 'is', 'isnot', 'as', -- operator - 'plus', 'minus', 'mult', 'div', 'mod', 'get', 'set', 'slice', 'lshift', 'rshift', 'and', 'or', 'xor', 'inverse', 'negate', 'increment', 'decrement', 'equals', 'compare', -- long operator + 'plus', 'minus', 'mult', 'div', 'mod', 'get', 'set', 'slice', 'lshift', 'rshift', 'and', 'or', + 'xor', 'inverse', 'negate', -- + 'increment', 'decrement', 'equals', 'compare', -- long operator 'return', -- stmt 'static', 'const', 'final', -- storage class 'virtual', 'override', 'once', -- slot @@ -44,62 +41,44 @@ local keyword = token(l.KEYWORD, word_match{ 'assert', -- assert 'class', 'enum', 'mixin', -- typedef 'break', 'continue', -- branch - 'default', 'case', -- labels - 'public', 'internal', 'protected', 'private', 'abstract', -- scope decl -}) + 'default', 'case', -- labels + 'public', 'internal', 'protected', 'private', 'abstract' -- scope decl +})) -- Types. -local type = token(l.TYPE, word_match{ - 'Void', 'Bool', 'Int', 'Float', 'Decimal', - 'Str', 'Duration', 'Uri', 'Type', 'Range', - 'List', 'Map', 'Obj', - 'Err', 'Env', -}) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'Void Bool Int Float Decimal Str Duration Uri Type Range List Map Obj Err Env'))) --- Identifiers. -local identifier = token(l.IDENTIFIER, l.word) +-- Functions. +-- lex:add_rule('function', token(lexer.FUNCTION, lexer.word) * #P('(')) --- Operators. -local operator = token(l.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}#')) +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) --- Annotations. -local facet = token('facet', '@' * l.word) +-- Strings. +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +local bq_str = lexer.range('`', true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str)) --- Functions. -local func = token(l.FUNCTION, l.word) * #P('(') +-- Comments. +local line_comment = lexer.to_eol('//', true) +local block_comment = lexer.range('/*', '*/') +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) --- Classes. -local class_sequence = token(l.KEYWORD, P('class')) * ws^1 * - token(l.TYPE, l.word) * ( -- at most one inheritance spec - ws^1 * token(l.OPERATOR, P(':')) * ws^1 * - token(l.TYPE, l.word) * - ( -- at least 0 (i.e. any number) of additional classes - ws^0 * token(l.OPERATOR, P(',')) * ws^0 * token(l.TYPE, l.word) - )^0 - )^-1 +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlFfDd')^-1)) -M._rules = { - {'whitespace', ws}, - {'class', class_sequence}, - {'keyword', keyword}, - {'type', type}, - {'function', func}, - {'identifier', identifier}, - {'string', string}, - {'comment', comment}, - {'number', number}, - {'facet', facet}, - {'operator', operator}, -} +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}#'))) -M._tokenstyles = { - facet = l.STYLE_PREPROCESSOR -} +-- Annotations. +lex:add_rule('facet', token('facet', '@' * lexer.word)) +lex:add_style('facet', lexer.styles.preprocessor) -M._foldsymbols = { - _patterns = {'[{}]', '/%*', '%*/', '//'}, - [l.OPERATOR] = {['{'] = 1, ['}'] = -1}, - [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')} -} +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, '/*', '*/') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) -return M +return lex |
