travis: try to fix build by using local built dependencies
[vis.git] / lexers / rexx.lua
blob6e13dd3ab4d189b5c5bd23aa04e0422e76910276
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Rexx 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 = 'rexx'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = '--' * l.nonnewline_esc^0
15 local block_comment = l.nested_pair('/*', '*/')
16 local comment = token(l.COMMENT, line_comment + block_comment)
18 -- Strings.
19 local sq_str = l.delimited_range("'", true)
20 local dq_str = l.delimited_range('"', true)
21 local string = token(l.STRING, sq_str + dq_str)
23 -- Numbers.
24 local number = token(l.NUMBER, l.float + l.integer)
26 -- Preprocessor.
27 local preproc = token(l.PREPROCESSOR, l.starts_line('#') * l.nonnewline^0)
29 -- Keywords.
30 local keyword = token(l.KEYWORD, word_match({
31 'address', 'arg', 'by', 'call', 'class', 'do', 'drop', 'else', 'end', 'exit',
32 'expose', 'forever', 'forward', 'guard', 'if', 'interpret', 'iterate',
33 'leave', 'method', 'nop', 'numeric', 'otherwise', 'parse', 'procedure',
34 'pull', 'push', 'queue', 'raise', 'reply', 'requires', 'return', 'routine',
35 'result', 'rc', 'say', 'select', 'self', 'sigl', 'signal', 'super', 'then',
36 'to', 'trace', 'use', 'when', 'while', 'until'
37 }, nil, true))
39 -- Functions.
40 local func = token(l.FUNCTION, word_match({
41 'abbrev', 'abs', 'address', 'arg', 'beep', 'bitand', 'bitor', 'bitxor', 'b2x',
42 'center', 'changestr', 'charin', 'charout', 'chars', 'compare', 'consition',
43 'copies', 'countstr', 'c2d', 'c2x', 'datatype', 'date', 'delstr', 'delword',
44 'digits', 'directory', 'd2c', 'd2x', 'errortext', 'filespec', 'form',
45 'format', 'fuzz', 'insert', 'lastpos', 'left', 'length', 'linein', 'lineout',
46 'lines', 'max', 'min', 'overlay', 'pos', 'queued', 'random', 'reverse',
47 'right', 'sign', 'sourceline', 'space', 'stream', 'strip', 'substr',
48 'subword', 'symbol', 'time', 'trace', 'translate', 'trunc', 'value', 'var',
49 'verify', 'word', 'wordindex', 'wordlength', 'wordpos', 'words', 'xrange',
50 'x2b', 'x2c', 'x2d', 'rxfuncadd', 'rxfuncdrop', 'rxfuncquery', 'rxmessagebox',
51 'rxwinexec', 'sysaddrexxmacro', 'sysbootdrive', 'sysclearrexxmacrospace',
52 'syscloseeventsem', 'sysclosemutexsem', 'syscls', 'syscreateeventsem',
53 'syscreatemutexsem', 'syscurpos', 'syscurstate', 'sysdriveinfo',
54 'sysdrivemap', 'sysdropfuncs', 'sysdroprexxmacro', 'sysdumpvariables',
55 'sysfiledelete', 'sysfilesearch', 'sysfilesystemtype', 'sysfiletree',
56 'sysfromunicode', 'systounicode', 'sysgeterrortext', 'sysgetfiledatetime',
57 'sysgetkey', 'sysini', 'sysloadfuncs', 'sysloadrexxmacrospace', 'sysmkdir',
58 'sysopeneventsem', 'sysopenmutexsem', 'sysposteventsem', 'syspulseeventsem',
59 'sysqueryprocess', 'sysqueryrexxmacro', 'sysreleasemutexsem',
60 'sysreorderrexxmacro', 'sysrequestmutexsem', 'sysreseteventsem', 'sysrmdir',
61 'syssaverexxmacrospace', 'syssearchpath', 'syssetfiledatetime',
62 'syssetpriority', 'syssleep', 'sysstemcopy', 'sysstemdelete', 'syssteminsert',
63 'sysstemsort', 'sysswitchsession', 'syssystemdirectory', 'systempfilename',
64 'systextscreenread', 'systextscreensize', 'sysutilversion', 'sysversion',
65 'sysvolumelabel', 'syswaiteventsem', 'syswaitnamedpipe', 'syswindecryptfile',
66 'syswinencryptfile', 'syswinver'
67 }, '2', true))
69 -- Identifiers.
70 local word = l.alpha * (l.alnum + S('@#$\\.!?_')^0)
71 local identifier = token(l.IDENTIFIER, word)
73 -- Operators.
74 local operator = token(l.OPERATOR, S('=!<>+-/\\*%&|^~.,:;(){}'))
76 M._rules = {
77 {'whitespace', ws},
78 {'keyword', keyword},
79 {'function', func},
80 {'identifier', identifier},
81 {'string', string},
82 {'comment', comment},
83 {'number', number},
84 {'preproc', preproc},
85 {'operator', operator},
88 M._foldsymbols = {
89 _patterns = {'[a-z]+', '/%*', '%*/', '%-%-', ':'},
90 [l.KEYWORD] = {['do'] = 1, select = 1, ['end'] = -1, ['return'] = -1},
91 [l.COMMENT] = {
92 ['/*'] = 1, ['*/'] = -1, ['--'] = l.fold_line_comments('--')
94 [l.OPERATOR] = {[':'] = 1}
97 return M