build: set version to 0.5
[vis.git] / lua / lexers / gnuplot.lua
blob4ee72de282b77a41b6de31539ce4c94a1e679033
1 -- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Gnuplot 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 = 'gnuplot'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, '#' * l.nonnewline^0)
16 -- Strings.
17 local sq_str = l.delimited_range("'")
18 local dq_str = l.delimited_range('"')
19 local bk_str = l.delimited_range('[]', true)
20 local bc_str = l.delimited_range('{}', true)
21 local string = token(l.STRING, sq_str + dq_str + bk_str + bc_str)
23 -- Keywords.
24 local keyword = token(l.KEYWORD, word_match{
25 'cd', 'call', 'clear', 'exit', 'fit', 'help', 'history', 'if', 'load',
26 'pause', 'plot', 'using', 'with', 'index', 'every', 'smooth', 'thru', 'print',
27 'pwd', 'quit', 'replot', 'reread', 'reset', 'save', 'set', 'show', 'unset',
28 'shell', 'splot', 'system', 'test', 'unset', 'update'
31 -- Functions.
32 local func = token(l.FUNCTION, word_match{
33 'abs', 'acos', 'acosh', 'arg', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
34 'besj0', 'besj1', 'besy0', 'besy1', 'ceil', 'cos', 'cosh', 'erf', 'erfc',
35 'exp', 'floor', 'gamma', 'ibeta', 'inverf', 'igamma', 'imag', 'invnorm',
36 'int', 'lambertw', 'lgamma', 'log', 'log10', 'norm', 'rand', 'real', 'sgn',
37 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'column', 'defined', 'tm_hour',
38 'tm_mday', 'tm_min', 'tm_mon', 'tm_sec', 'tm_wday', 'tm_yday', 'tm_year',
39 'valid'
42 -- Variables.
43 local variable = token(l.VARIABLE, word_match{
44 'angles', 'arrow', 'autoscale', 'bars', 'bmargin', 'border', 'boxwidth',
45 'clabel', 'clip', 'cntrparam', 'colorbox', 'contour', 'datafile ',
46 'decimalsign', 'dgrid3d', 'dummy', 'encoding', 'fit', 'fontpath', 'format',
47 'functions', 'function', 'grid', 'hidden3d', 'historysize', 'isosamples',
48 'key', 'label', 'lmargin', 'loadpath', 'locale', 'logscale', 'mapping',
49 'margin', 'mouse', 'multiplot', 'mx2tics', 'mxtics', 'my2tics', 'mytics',
50 'mztics', 'offsets', 'origin', 'output', 'parametric', 'plot', 'pm3d',
51 'palette', 'pointsize', 'polar', 'print', 'rmargin', 'rrange', 'samples',
52 'size', 'style', 'surface', 'terminal', 'tics', 'ticslevel', 'ticscale',
53 'timestamp', 'timefmt', 'title', 'tmargin', 'trange', 'urange', 'variables',
54 'version', 'view', 'vrange', 'x2data', 'x2dtics', 'x2label', 'x2mtics',
55 'x2range', 'x2tics', 'x2zeroaxis', 'xdata', 'xdtics', 'xlabel', 'xmtics',
56 'xrange', 'xtics', 'xzeroaxis', 'y2data', 'y2dtics', 'y2label', 'y2mtics',
57 'y2range', 'y2tics', 'y2zeroaxis', 'ydata', 'ydtics', 'ylabel', 'ymtics',
58 'yrange', 'ytics', 'yzeroaxis', 'zdata', 'zdtics', 'cbdata', 'cbdtics',
59 'zero', 'zeroaxis', 'zlabel', 'zmtics', 'zrange', 'ztics', 'cblabel',
60 'cbmtics', 'cbrange', 'cbtics'
63 -- Identifiers.
64 local identifier = token(l.IDENTIFIER, l.word)
66 -- Operators.
67 local operator = token(l.OPERATOR, S('-+~!$*%=<>&|^?:()'))
69 M._rules = {
70 {'whitespace', ws},
71 {'keyword', keyword},
72 {'function', func},
73 {'variable', variable},
74 {'identifier', identifier},
75 {'string', string},
76 {'comment', comment},
77 {'operator', operator},
80 return M