1 -- Copyright 2006-2013 Brian "Sir Alaran" Schott. See LICENSE.
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'}
12 local ws
= token(l
.WHITESPACE
, l
.space^
1)
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
)
20 local sq_str
= l
.delimited_range("'")
21 local dq_str
= l
.delimited_range('"')
22 local string = token(l
.STRING
, sq_str
+ dq_str
)
25 local number = token(l
.NUMBER
, l
.digit^
1 + l
.float
)
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',
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',
49 local identifier
= token(l
.IDENTIFIER
, l
.word
)
52 local operator
= token(l
.OPERATOR
, S('->()[]{};'))
59 {'identifier', identifier
},
62 {'operator', operator
},
66 _patterns
= {'[{}]', '/%*', '%*/', '//'},
67 [l
.OPERATOR
] = {['{'] = 1, ['}'] = -1},
68 [l
.COMMENT
] = {['/*'] = 1, ['*/'] = -1, ['//'] = l
.fold_line_comments('//')}