ui: make primary cursor blink even if no lua theme has been loaded
[vis.git] / lexers / dot.lua
blob5ff845b5055e0e45af3f8974b7c075fb5d0a89ed
1 -- Copyright 2006-2013 Brian "Sir Alaran" Schott. See LICENSE.
2 -- Dot LPeg lexer.
3 -- Based off of lexer code by Mitchell.
5 local l = require('lexer')
6 local token, word_match = l.token, l.word_match
7 local P, R, S = lpeg.P, lpeg.R, lpeg.S
9 local M = {_NAME = 'dot'}
11 -- Whitespace.
12 local ws = token(l.WHITESPACE, l.space^1)
14 -- Comments.
15 local line_comment = '//' * l.nonnewline_esc^0
16 local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1
17 local comment = token(l.COMMENT, line_comment + block_comment)
19 -- Strings.
20 local sq_str = l.delimited_range("'")
21 local dq_str = l.delimited_range('"')
22 local string = token(l.STRING, sq_str + dq_str)
24 -- Numbers.
25 local number = token(l.NUMBER, l.digit^1 + l.float)
27 -- Keywords.
28 local keyword = token(l.KEYWORD, word_match{
29 'graph', 'node', 'edge', 'digraph', 'fontsize', 'rankdir',
30 'fontname', 'shape', 'label', 'arrowhead', 'arrowtail', 'arrowsize',
31 'color', 'comment', 'constraint', 'decorate', 'dir', 'headlabel', 'headport',
32 'headURL', 'labelangle', 'labeldistance', 'labelfloat', 'labelfontcolor',
33 'labelfontname', 'labelfontsize', 'layer', 'lhead', 'ltail', 'minlen',
34 'samehead', 'sametail', 'style', 'taillabel', 'tailport', 'tailURL', 'weight',
35 'subgraph'
38 -- Types.
39 local type = token(l.TYPE, word_match{
40 'box', 'polygon', 'ellipse', 'circle', 'point', 'egg', 'triangle',
41 'plaintext', 'diamond', 'trapezium', 'parallelogram', 'house', 'pentagon',
42 'hexagon', 'septagon', 'octagon', 'doublecircle', 'doubleoctagon',
43 'tripleoctagon', 'invtriangle', 'invtrapezium', 'invhouse', 'Mdiamond',
44 'Msquare', 'Mcircle', 'rect', 'rectangle', 'none', 'note', 'tab', 'folder',
45 'box3d', 'record'
48 -- Identifiers.
49 local identifier = token(l.IDENTIFIER, l.word)
51 -- Operators.
52 local operator = token(l.OPERATOR, S('->()[]{};'))
54 M._rules = {
55 {'whitespace', ws},
56 {'comment', comment},
57 {'keyword', keyword},
58 {'type', type},
59 {'identifier', identifier},
60 {'number', number},
61 {'string', string},
62 {'operator', operator},
65 M._foldsymbols = {
66 _patterns = {'[{}]', '/%*', '%*/', '//'},
67 [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
68 [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')}
71 return M