travis: try to fix build by using local built dependencies
[vis.git] / lexers / bibtex.lua
blob992667a1135c98bc5ea7e117ca7ea9440eb0fd4e
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Bibtex LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'bibtex'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Strings.
14 local string = token(l.STRING, l.delimited_range('"') +
15 l.delimited_range('{}', false, true, true))
17 -- Fields.
18 local field = token('field', word_match{
19 'author', 'title', 'journal', 'year', 'volume', 'number', 'pages', 'month',
20 'note', 'key', 'publisher', 'editor', 'series', 'address', 'edition',
21 'howpublished', 'booktitle', 'organization', 'chapter', 'school',
22 'institution', 'type', 'isbn', 'issn', 'affiliation', 'issue', 'keyword',
23 'url'
26 -- Identifiers.
27 local identifier = token(l.IDENTIFIER, l.word)
29 -- Operators.
30 local operator = token(l.OPERATOR, S(',='))
32 M._rules = {
33 {'whitespace', ws},
34 {'field', field},
35 {'identifier', identifier},
36 {'string', string},
37 {'operator', operator},
40 -- Embedded in Latex.
41 local latex = l.load('latex')
43 -- Embedded Bibtex.
44 local entry = token('entry', P('@') * word_match({
45 'book', 'article', 'booklet', 'conference', 'inbook', 'incollection',
46 'inproceedings', 'manual', 'mastersthesis', 'lambda', 'misc', 'phdthesis',
47 'proceedings', 'techreport', 'unpublished'
48 }, nil, true))
49 local bibtex_start_rule = entry * ws^0 * token(l.OPERATOR, P('{'))
50 local bibtex_end_rule = token(l.OPERATOR, P('}'))
51 l.embed_lexer(latex, M, bibtex_start_rule, bibtex_end_rule)
53 M._tokenstyles = {
54 field = l.STYLE_CONSTANT,
55 entry = l.STYLE_PREPROCESSOR
58 return M