vis

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

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

bibtex.lua

(1589B)


      1 -- Copyright 2006-2025 Mitchell. See LICENSE.
      2 -- Bibtex LPeg lexer.
      3 
      4 local lexer = lexer
      5 local P, S = lpeg.P, lpeg.S
      6 
      7 local lex = lexer.new(...)
      8 
      9 -- Fields.
     10 lex:add_rule('field', lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match(lexer.VARIABLE_BUILTIN, true)))
     11 
     12 -- Identifiers.
     13 lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
     14 
     15 -- Strings.
     16 local dq_str = lexer.range('"')
     17 local br_str = lexer.range('{', '}', false, false, true)
     18 lex:add_rule('string', lex:tag(lexer.STRING, dq_str + br_str))
     19 
     20 -- Operators.
     21 lex:add_rule('operator', lex:tag(lexer.OPERATOR, S(',=')))
     22 
     23 -- Embedded in Latex.
     24 local latex = lexer.load('latex')
     25 
     26 -- Embedded Bibtex.
     27 local entry = lex:tag(lexer.PREPROCESSOR, '@' * lex:word_match('entry', true))
     28 local bibtex_start_rule = entry * lex:get_rule('whitespace')^0 * lex:tag(lexer.OPERATOR, '{')
     29 local bibtex_end_rule = lex:tag(lexer.OPERATOR, '}')
     30 latex:embed(lex, bibtex_start_rule, bibtex_end_rule)
     31 
     32 -- Word lists.
     33 lex:set_word_list(lexer.VARIABLE_BUILTIN, {
     34 	'author', 'title', 'journal', 'year', 'volume', 'number', 'pages', 'month', 'note', 'key',
     35 	'publisher', 'editor', 'series', 'address', 'edition', 'howpublished', 'booktitle',
     36 	'organization', 'chapter', 'school', 'institution', 'type', 'isbn', 'issn', 'affiliation',
     37 	'issue', 'keyword', 'url'
     38 })
     39 
     40 lex:set_word_list('entry', {
     41 	'string', --
     42 	'book', 'article', 'booklet', 'conference', 'inbook', 'incollection', 'inproceedings', 'manual',
     43 	'mastersthesis', 'lambda', 'misc', 'phdthesis', 'proceedings', 'techreport', 'unpublished'
     44 })
     45 
     46 lexer.property['scintillua.comment'] = '%'
     47 
     48 return lex