logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

bibtex.lua (1596B)


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