vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
rexx.lua
(3814B)
1 -- Copyright 2006-2025 Mitchell. See LICENSE.
2 -- Rexx 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('rexx')
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 'address', 'arg', 'by', 'call', 'class', 'do', 'drop', 'else', 'end', 'exit', 'expose', 'forever',
16 'forward', 'guard', 'if', 'interpret', 'iterate', 'leave', 'method', 'nop', 'numeric',
17 'otherwise', 'parse', 'procedure', 'pull', 'push', 'queue', 'raise', 'reply', 'requires',
18 'return', 'routine', 'result', 'rc', 'say', 'select', 'self', 'sigl', 'signal', 'super', 'then',
19 'to', 'trace', 'use', 'when', 'while', 'until'
20 }, true)))
21
22 -- Functions.
23 lex:add_rule('function', token(lexer.FUNCTION, word_match({
24 'abbrev', 'abs', 'address', 'arg', 'beep', 'bitand', 'bitor', 'bitxor', 'b2x', 'center',
25 'changestr', 'charin', 'charout', 'chars', 'compare', 'consition', 'copies', 'countstr', 'c2d',
26 'c2x', 'datatype', 'date', 'delstr', 'delword', 'digits', 'directory', 'd2c', 'd2x', 'errortext',
27 'filespec', 'form', 'format', 'fuzz', 'insert', 'lastpos', 'left', 'length', 'linein', 'lineout',
28 'lines', 'max', 'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right', 'sign',
29 'sourceline', 'space', 'stream', 'strip', 'substr', 'subword', 'symbol', 'time', 'trace',
30 'translate', 'trunc', 'value', 'var', 'verify', 'word', 'wordindex', 'wordlength', 'wordpos',
31 'words', 'xrange', 'x2b', 'x2c', 'x2d', --
32 'rxfuncadd', 'rxfuncdrop', 'rxfuncquery', 'rxmessagebox', 'rxwinexec', 'sysaddrexxmacro',
33 'sysbootdrive', 'sysclearrexxmacrospace', 'syscloseeventsem', 'sysclosemutexsem', 'syscls',
34 'syscreateeventsem', 'syscreatemutexsem', 'syscurpos', 'syscurstate', 'sysdriveinfo',
35 'sysdrivemap', 'sysdropfuncs', 'sysdroprexxmacro', 'sysdumpvariables', 'sysfiledelete',
36 'sysfilesearch', 'sysfilesystemtype', 'sysfiletree', 'sysfromunicode', 'systounicode',
37 'sysgeterrortext', 'sysgetfiledatetime', 'sysgetkey', 'sysini', 'sysloadfuncs',
38 'sysloadrexxmacrospace', 'sysmkdir', 'sysopeneventsem', 'sysopenmutexsem', 'sysposteventsem',
39 'syspulseeventsem', 'sysqueryprocess', 'sysqueryrexxmacro', 'sysreleasemutexsem',
40 'sysreorderrexxmacro', 'sysrequestmutexsem', 'sysreseteventsem', 'sysrmdir',
41 'syssaverexxmacrospace', 'syssearchpath', 'syssetfiledatetime', 'syssetpriority', 'syssleep',
42 'sysstemcopy', 'sysstemdelete', 'syssteminsert', 'sysstemsort', 'sysswitchsession',
43 'syssystemdirectory', 'systempfilename', 'systextscreenread', 'systextscreensize',
44 'sysutilversion', 'sysversion', 'sysvolumelabel', 'syswaiteventsem', 'syswaitnamedpipe',
45 'syswindecryptfile', 'syswinencryptfile', 'syswinver'
46 }, true)))
47
48 -- Identifiers.
49 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('@#$\\.!?_'))^0))
50
51 -- Strings.
52 local sq_str = lexer.range("'", true, false)
53 local dq_str = lexer.range('"', true, false)
54 lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
55
56 -- Comments.
57 local line_comment = lexer.to_eol('--', true)
58 local block_comment = lexer.range('/*', '*/', false, false, true)
59 lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
60
61 -- Numbers.
62 lex:add_rule('number', token(lexer.NUMBER, lexer.number))
63
64 -- Preprocessor.
65 lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, lexer.to_eol(lexer.starts_line('#'))))
66
67 -- Operators.
68 lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/\\*%&|^~.,:;(){}')))
69
70 -- Fold points
71 lex:add_fold_point(lexer.KEYWORD, 'do', 'end')
72 lex:add_fold_point(lexer.KEYWORD, 'select', 'return')
73 lex:add_fold_point(lexer.COMMENT, '/*', '*/')
74 -- lex:add_fold_point(lexer.OPERATOR, ':', ?)
75
76 lexer.property['scintillua.comment'] = '--'
77
78 return lex