aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/desktop.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lexers/desktop.lua')
-rw-r--r--lua/lexers/desktop.lua81
1 files changed, 36 insertions, 45 deletions
diff --git a/lua/lexers/desktop.lua b/lua/lexers/desktop.lua
index d6d40f5..2c824e0 100644
--- a/lua/lexers/desktop.lua
+++ b/lua/lexers/desktop.lua
@@ -1,62 +1,53 @@
--- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
+-- Copyright 2006-2022 Mitchell. See LICENSE.
-- Desktop Entry LPeg lexer.
-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 = 'desktop'}
+local lex = lexer.new('desktop')
-- Whitespace.
-local ws = token(l.WHITESPACE, l.space^1)
+lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
--- Comments.
-local comment = token(l.COMMENT, '#' * l.nonnewline^0)
+-- Keys.
+lex:add_rule('key', token('key', word_match{
+ 'Type', 'Version', 'Name', 'GenericName', 'NoDisplay', 'Comment', 'Icon', 'Hidden', 'OnlyShowIn',
+ 'NotShowIn', 'TryExec', 'Exec', 'Exec', 'Path', 'Terminal', 'MimeType', 'Categories',
+ 'StartupNotify', 'StartupWMClass', 'URL'
+}))
+lex:add_style('key', lexer.styles.keyword)
--- Strings.
-local string = token(l.STRING, l.delimited_range('"'))
+-- Values.
+lex:add_rule('value', token('value', word_match('true false')))
+lex:add_style('value', lexer.styles.constant)
+
+-- Identifiers.
+lex:add_rule('identifier', lexer.token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('_-'))^0))
-- Group headers.
-local group_header = l.starts_line(token(l.STRING,
- l.delimited_range('[]', false, true)))
+local bracketed = lexer.range('[', ']')
+lex:add_rule('header', lexer.starts_line(token('header', bracketed)))
+lex:add_style('header', lexer.styles.label)
--- Numbers.
-local number = token(l.NUMBER, (l.float + l.integer))
+-- Locales.
+lex:add_rule('locale', token('locale', bracketed))
+lex:add_style('locale', lexer.styles.class)
--- Keywords.
-local keyword = token(l.KEYWORD, word_match{'true', 'false'})
+-- Strings.
+lex:add_rule('string', token(lexer.STRING, lexer.range('"')))
--- Locales.
-local locale = token(l.CLASS, l.delimited_range('[]', false, true))
+-- Comments.
+lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
--- Keys.
-local key = token(l.VARIABLE, word_match{
- 'Type', 'Version', 'Name', 'GenericName', 'NoDisplay', 'Comment', 'Icon',
- 'Hidden', 'OnlyShowIn', 'NotShowIn', 'TryExec', 'Exec', 'Exec', 'Path',
- 'Terminal', 'MimeType', 'Categories', 'StartupNotify', 'StartupWMClass', 'URL'
-})
+-- Numbers.
+lex:add_rule('number', token(lexer.NUMBER, lexer.number))
-- Field codes.
-local code = l.token(l.CONSTANT, P('%') * S('fFuUdDnNickvm'))
-
--- Identifiers.
-local identifier = l.token(l.IDENTIFIER, l.alpha * (l.alnum + S('_-'))^0)
+lex:add_rule('code', lexer.token('code', '%' * S('fFuUdDnNickvm')))
+lex:add_style('code', lexer.styles.variable)
-- Operators.
-local operator = token(l.OPERATOR, S('='))
-
-M._rules = {
- {'whitespace', ws},
- {'keyword', keyword},
- {'key', key},
- {'identifier', identifier},
- {'group_header', group_header},
- {'locale', locale},
- {'string', string},
- {'comment', comment},
- {'number', number},
- {'code', code},
- {'operator', operator},
-}
-
-return M
+lex:add_rule('operator', token(lexer.OPERATOR, S('=')))
+
+return lex