aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/gnuplot.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lexers/gnuplot.lua')
-rw-r--r--lua/lexers/gnuplot.lua109
1 files changed, 45 insertions, 64 deletions
diff --git a/lua/lexers/gnuplot.lua b/lua/lexers/gnuplot.lua
index 4ee72de..a3d93dd 100644
--- a/lua/lexers/gnuplot.lua
+++ b/lua/lexers/gnuplot.lua
@@ -1,80 +1,61 @@
--- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
+-- Copyright 2006-2022 Mitchell. See LICENSE.
-- Gnuplot LPeg lexer.
-local l = require('lexer')
-local token, word_match = l.token, l.word_match
-local P, R, S = lpeg.P, lpeg.R, lpeg.S
+local lexer = require('lexer')
+local token, word_match = lexer.token, lexer.word_match
+local P, S = lpeg.P, lpeg.S
-local M = {_NAME = 'gnuplot'}
+local lex = lexer.new('gnuplot')
-- Whitespace.
-local ws = token(l.WHITESPACE, l.space^1)
-
--- Comments.
-local comment = token(l.COMMENT, '#' * l.nonnewline^0)
-
--- Strings.
-local sq_str = l.delimited_range("'")
-local dq_str = l.delimited_range('"')
-local bk_str = l.delimited_range('[]', true)
-local bc_str = l.delimited_range('{}', true)
-local string = token(l.STRING, sq_str + dq_str + bk_str + bc_str)
+lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
-- Keywords.
-local keyword = token(l.KEYWORD, word_match{
- 'cd', 'call', 'clear', 'exit', 'fit', 'help', 'history', 'if', 'load',
- 'pause', 'plot', 'using', 'with', 'index', 'every', 'smooth', 'thru', 'print',
- 'pwd', 'quit', 'replot', 'reread', 'reset', 'save', 'set', 'show', 'unset',
- 'shell', 'splot', 'system', 'test', 'unset', 'update'
-})
+lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
+ 'cd', 'call', 'clear', 'exit', 'fit', 'help', 'history', 'if', 'load', 'pause', 'plot', 'using',
+ 'with', 'index', 'every', 'smooth', 'thru', 'print', 'pwd', 'quit', 'replot', 'reread', 'reset',
+ 'save', 'set', 'show', 'unset', 'shell', 'splot', 'system', 'test', 'unset', 'update'
+}))
-- Functions.
-local func = token(l.FUNCTION, word_match{
- 'abs', 'acos', 'acosh', 'arg', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
- 'besj0', 'besj1', 'besy0', 'besy1', 'ceil', 'cos', 'cosh', 'erf', 'erfc',
- 'exp', 'floor', 'gamma', 'ibeta', 'inverf', 'igamma', 'imag', 'invnorm',
- 'int', 'lambertw', 'lgamma', 'log', 'log10', 'norm', 'rand', 'real', 'sgn',
- 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'column', 'defined', 'tm_hour',
- 'tm_mday', 'tm_min', 'tm_mon', 'tm_sec', 'tm_wday', 'tm_yday', 'tm_year',
- 'valid'
-})
+lex:add_rule('function', token(lexer.FUNCTION, word_match{
+ 'abs', 'acos', 'acosh', 'arg', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'besj0', 'besj1',
+ 'besy0', 'besy1', 'ceil', 'cos', 'cosh', 'erf', 'erfc', 'exp', 'floor', 'gamma', 'ibeta',
+ 'inverf', 'igamma', 'imag', 'invnorm', 'int', 'lambertw', 'lgamma', 'log', 'log10', 'norm',
+ 'rand', 'real', 'sgn', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'column', 'defined', 'tm_hour',
+ 'tm_mday', 'tm_min', 'tm_mon', 'tm_sec', 'tm_wday', 'tm_yday', 'tm_year', 'valid'
+}))
-- Variables.
-local variable = token(l.VARIABLE, word_match{
- 'angles', 'arrow', 'autoscale', 'bars', 'bmargin', 'border', 'boxwidth',
- 'clabel', 'clip', 'cntrparam', 'colorbox', 'contour', 'datafile ',
- 'decimalsign', 'dgrid3d', 'dummy', 'encoding', 'fit', 'fontpath', 'format',
- 'functions', 'function', 'grid', 'hidden3d', 'historysize', 'isosamples',
- 'key', 'label', 'lmargin', 'loadpath', 'locale', 'logscale', 'mapping',
- 'margin', 'mouse', 'multiplot', 'mx2tics', 'mxtics', 'my2tics', 'mytics',
- 'mztics', 'offsets', 'origin', 'output', 'parametric', 'plot', 'pm3d',
- 'palette', 'pointsize', 'polar', 'print', 'rmargin', 'rrange', 'samples',
- 'size', 'style', 'surface', 'terminal', 'tics', 'ticslevel', 'ticscale',
- 'timestamp', 'timefmt', 'title', 'tmargin', 'trange', 'urange', 'variables',
- 'version', 'view', 'vrange', 'x2data', 'x2dtics', 'x2label', 'x2mtics',
- 'x2range', 'x2tics', 'x2zeroaxis', 'xdata', 'xdtics', 'xlabel', 'xmtics',
- 'xrange', 'xtics', 'xzeroaxis', 'y2data', 'y2dtics', 'y2label', 'y2mtics',
- 'y2range', 'y2tics', 'y2zeroaxis', 'ydata', 'ydtics', 'ylabel', 'ymtics',
- 'yrange', 'ytics', 'yzeroaxis', 'zdata', 'zdtics', 'cbdata', 'cbdtics',
- 'zero', 'zeroaxis', 'zlabel', 'zmtics', 'zrange', 'ztics', 'cblabel',
- 'cbmtics', 'cbrange', 'cbtics'
-})
+lex:add_rule('variable', token(lexer.VARIABLE, word_match{
+ 'angles', 'arrow', 'autoscale', 'bars', 'bmargin', 'border', 'boxwidth', 'clabel', 'clip',
+ 'cntrparam', 'colorbox', 'contour', 'datafile', 'decimalsign', 'dgrid3d', 'dummy', 'encoding',
+ 'fit', 'fontpath', 'format', 'functions', 'function', 'grid', 'hidden3d', 'historysize',
+ 'isosamples', 'key', 'label', 'lmargin', 'loadpath', 'locale', 'logscale', 'mapping', 'margin',
+ 'mouse', 'multiplot', 'mx2tics', 'mxtics', 'my2tics', 'mytics', 'mztics', 'offsets', 'origin',
+ 'output', 'parametric', 'plot', 'pm3d', 'palette', 'pointsize', 'polar', 'print', 'rmargin',
+ 'rrange', 'samples', 'size', 'style', 'surface', 'terminal', 'tics', 'ticslevel', 'ticscale',
+ 'timestamp', 'timefmt', 'title', 'tmargin', 'trange', 'urange', 'variables', 'version', 'view',
+ 'vrange', 'x2data', 'x2dtics', 'x2label', 'x2mtics', 'x2range', 'x2tics', 'x2zeroaxis', 'xdata',
+ 'xdtics', 'xlabel', 'xmtics', 'xrange', 'xtics', 'xzeroaxis', 'y2data', 'y2dtics', 'y2label',
+ 'y2mtics', 'y2range', 'y2tics', 'y2zeroaxis', 'ydata', 'ydtics', 'ylabel', 'ymtics', 'yrange',
+ 'ytics', 'yzeroaxis', 'zdata', 'zdtics', 'cbdata', 'cbdtics', 'zero', 'zeroaxis', 'zlabel',
+ 'zmtics', 'zrange', 'ztics', 'cblabel', 'cbmtics', 'cbrange', 'cbtics'
+}))
-- Identifiers.
-local identifier = token(l.IDENTIFIER, l.word)
+lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
--- Operators.
-local operator = token(l.OPERATOR, S('-+~!$*%=<>&|^?:()'))
+-- Strings.
+local sq_str = lexer.range("'")
+local dq_str = lexer.range('"')
+local br_str = lexer.range('[', ']', true) + lexer.range('{', '}', true)
+lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + br_str))
+
+-- Comments.
+lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
-M._rules = {
- {'whitespace', ws},
- {'keyword', keyword},
- {'function', func},
- {'variable', variable},
- {'identifier', identifier},
- {'string', string},
- {'comment', comment},
- {'operator', operator},
-}
+-- Operators.
+lex:add_rule('operator', token(lexer.OPERATOR, S('-+~!$*%=<>&|^?:()')))
-return M
+return lex