vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
apdl.lua
(4348B)
1 -- Copyright 2006-2025 Mitchell. See LICENSE.
2 -- APDL LPeg lexer.
3
4 local lexer = require('lexer')
5 local token, word_match = lexer.token, lexer.word_match
6 local P, S = lpeg.P, lpeg.S
7
8 local lex = lexer.new('apdl', {case_insensitive_fold_points = true})
9
10 -- Whitespace.
11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
12
13 -- Keywords.
14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
15 '*abbr', '*abb', '*afun', '*afu', '*ask', '*cfclos', '*cfc', '*cfopen', '*cfo', '*cfwrite',
16 '*cfw', '*create', '*cre', '*cycle', '*cyc', '*del', '*dim', '*do', '*elseif', '*else', '*enddo',
17 '*endif', '*end', '*eval', '*eva', '*exit', '*exi', '*get', '*go', '*if', '*list', '*lis',
18 '*mfouri', '*mfo', '*mfun', '*mfu', '*mooney', '*moo', '*moper', '*mop', '*msg', '*repeat',
19 '*rep', '*set', '*status', '*sta', '*tread', '*tre', '*ulib', '*uli', '*use', '*vabs', '*vab',
20 '*vcol', '*vco', '*vcum', '*vcu', '*vedit', '*ved', '*vfact', '*vfa', '*vfill', '*vfi', '*vfun',
21 '*vfu', '*vget', '*vge', '*vitrp', '*vit', '*vlen', '*vle', '*vmask', '*vma', '*voper', '*vop',
22 '*vplot', '*vpl', '*vput', '*vpu', '*vread', '*vre', '*vscfun', '*vsc', '*vstat', '*vst',
23 '*vwrite', '*vwr', --
24 '/anfile', '/anf', '/angle', '/ang', '/annot', '/ann', '/anum', '/anu', '/assign', '/ass',
25 '/auto', '/aut', '/aux15', '/aux2', '/aux', '/axlab', '/axl', '/batch', '/bat', '/clabel', '/cla',
26 '/clear', '/cle', '/clog', '/clo', '/cmap', '/cma', '/color', '/col', '/com', '/config',
27 '/contour', '/con', '/copy', '/cop', '/cplane', '/cpl', '/ctype', '/cty', '/cval', '/cva',
28 '/delete', '/del', '/devdisp', '/device', '/dev', '/dist', '/dis', '/dscale', '/dsc', '/dv3d',
29 '/dv3', '/edge', '/edg', '/efacet', '/efa', '/eof', '/erase', '/era', '/eshape', '/esh', '/exit',
30 '/exi', '/expand', '/exp', '/facet', '/fac', '/fdele', '/fde', '/filname', '/fil', '/focus',
31 '/foc', '/format', '/for', '/ftype', '/fty', '/gcmd', '/gcm', '/gcolumn', '/gco', '/gfile',
32 '/gfi', '/gformat', '/gfo', '/gline', '/gli', '/gmarker', '/gma', '/golist', '/gol', '/gopr',
33 '/gop', '/go', '/graphics', '/gra', '/gresume', '/gre', '/grid', '/gri', '/gropt', '/gro',
34 '/grtyp', '/grt', '/gsave', '/gsa', '/gst', '/gthk', '/gth', '/gtype', '/gty', '/header', '/hea',
35 '/input', '/inp', '/larc', '/lar', '/light', '/lig', '/line', '/lin', '/lspec', '/lsp',
36 '/lsymbol', '/lsy', '/menu', '/men', '/mplib', '/mpl', '/mrep', '/mre', '/mstart', '/mst',
37 '/nerr', '/ner', '/noerase', '/noe', '/nolist', '/nol', '/nopr', '/nop', '/normal', '/nor',
38 '/number', '/num', '/opt', '/output', '/out', '/page', '/pag', '/pbc', '/pbf', '/pcircle', '/pci',
39 '/pcopy', '/pco', '/plopts', '/plo', '/pmacro', '/pma', '/pmeth', '/pme', '/pmore', '/pmo',
40 '/pnum', '/pnu', '/polygon', '/pol', '/post26', '/post1', '/pos', '/prep7', '/pre', '/psearch',
41 '/pse', '/psf', '/pspec', '/psp', '/pstatus', '/pst', '/psymb', '/psy', '/pwedge', '/pwe',
42 '/quit', '/qui', '/ratio', '/rat', '/rename', '/ren', '/replot', '/rep', '/reset', '/res', '/rgb',
43 '/runst', '/run', '/seclib', '/sec', '/seg', '/shade', '/sha', '/showdisp', '/show', '/sho',
44 '/shrink', '/shr', '/solu', '/sol', '/sscale', '/ssc', '/status', '/sta', '/stitle', '/sti',
45 '/syp', '/sys', '/title', '/tit', '/tlabel', '/tla', '/triad', '/tri', '/trlcy', '/trl', '/tspec',
46 '/tsp', '/type', '/typ', '/ucmd', '/ucm', '/uis', '/ui', '/units', '/uni', '/user', '/use',
47 '/vcone', '/vco', '/view', '/vie', '/vscale', '/vsc', '/vup', '/wait', '/wai', '/window', '/win',
48 '/xrange', '/xra', '/yrange', '/yra', '/zoom', '/zoo'
49 }, true)))
50
51 -- Identifiers.
52 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
53
54 -- Strings.
55 lex:add_rule('string', token(lexer.STRING, lexer.range("'", true, false)))
56
57 -- Numbers.
58 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
59
60 -- Functions.
61 lex:add_rule('function', token(lexer.FUNCTION, lexer.range('%', true, false)))
62
63 -- Labels.
64 lex:add_rule('label', token(lexer.LABEL, lexer.starts_line(':') * lexer.word))
65
66 -- Comments.
67 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('!')))
68
69 -- Operators.
70 lex:add_rule('operator', token(lexer.OPERATOR, S('+-*/$=,;()')))
71
72 -- Fold points.
73 lex:add_fold_point(lexer.KEYWORD, '*if', '*endif')
74 lex:add_fold_point(lexer.KEYWORD, '*do', '*enddo')
75 lex:add_fold_point(lexer.KEYWORD, '*dowhile', '*enddo')
76
77 lexer.property['scintillua.comment'] = '!'
78
79 return lex