vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

gettext.lua

(833B)


      1 -- Copyright 2006-2025 Mitchell. See LICENSE.
      2 -- Gettext LPeg lexer.
      3 
      4 local lexer = require('lexer')
      5 local token, word_match = lexer.token, lexer.word_match
      6 local P, S = lpeg.P, lpeg.S
      7 
      8 local lex = lexer.new('gettext')
      9 
     10 -- Whitespace.
     11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
     12 
     13 -- Keywords.
     14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match(
     15 	'msgid msgid_plural msgstr fuzzy c-format no-c-format', true)))
     16 
     17 -- Identifiers.
     18 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
     19 
     20 -- Variables.
     21 lex:add_rule('variable', token(lexer.VARIABLE, S('%$@') * lexer.word))
     22 
     23 -- Strings.
     24 lex:add_rule('string', token(lexer.STRING, lexer.range('"', true)))
     25 
     26 -- Comments.
     27 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#' * S(': .~'))))
     28 
     29 lexer.property['scintillua.comment'] = '#'
     30 
     31 return lex