ui: fall back to xterm-256color if term initialization fails
[vis.git] / lexers / rebol.lua
blobecedd5a4823798dfb58bcd3ab8d329a81c92afbf
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Rebol 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 = 'rebol'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = ';' * l.nonnewline^0;
15 local block_comment = 'comment' * P(' ')^-1 *
16 l.delimited_range('{}', false, true)
17 local comment = token(l.COMMENT, line_comment + block_comment)
19 -- Strings.
20 local sl_string = l.delimited_range('"', true)
21 local ml_string = l.delimited_range('{}')
22 local lit_string = "'" * l.word
23 local string = token(l.STRING, sl_string + ml_string + lit_string)
25 -- Keywords.
26 local keyword = token(l.KEYWORD, word_match({
27 'abs', 'absolute', 'add', 'and~', 'at', 'back', 'change', 'clear',
28 'complement', 'copy', 'cp', 'divide', 'fifth', 'find', 'first', 'fourth',
29 'head', 'insert', 'last', 'make', 'max', 'maximum', 'min', 'minimum',
30 'multiply', 'negate', 'next', 'or~', 'pick', 'poke', 'power', 'random',
31 'remainder', 'remove', 'second', 'select', 'skip', 'sort', 'subtract', 'tail',
32 'third', 'to', 'trim', 'xor~', 'alias', 'all', 'any', 'arccosine', 'arcsine',
33 'arctangent', 'bind', 'break', 'browse', 'call', 'caret-to-offset', 'catch',
34 'checksum', 'close', 'comment', 'compose', 'compress', 'cosine', 'debase',
35 'decompress', 'dehex', 'detab', 'dh-compute-key', 'dh-generate-key',
36 'dh-make-key', 'difference', 'disarm', 'do', 'dsa-generate-key',
37 'dsa-make-key', 'dsa-make-signature', 'dsa-verify-signature', 'either',
38 'else', 'enbase', 'entab', 'exclude', 'exit', 'exp', 'foreach', 'form',
39 'free', 'get', 'get-modes', 'halt', 'hide', 'if', 'in', 'intersect', 'load',
40 'log-10', 'log-2', 'log-e', 'loop', 'lowercase', 'maximum-of', 'minimum-of',
41 'mold', 'not', 'now', 'offset-to-caret', 'open', 'parse', 'prin', 'print',
42 'protect', 'q', 'query', 'quit', 'read', 'read-io', 'recycle', 'reduce',
43 'repeat', 'return', 'reverse', 'rsa-encrypt', 'rsa-generate-key',
44 'rsa-make-key', 'save', 'secure', 'set', 'set-modes', 'show', 'sine',
45 'size-text', 'square-root', 'tangent', 'textinfo', 'throw', 'to-hex',
46 'to-local-file', 'to-rebol-file', 'trace', 'try', 'union', 'unique',
47 'unprotect', 'unset', 'until', 'update', 'uppercase', 'use', 'wait', 'while',
48 'write', 'write-io', 'basic-syntax-header', 'crlf', 'font-fixed',
49 'font-sans-serif', 'font-serif', 'list-words', 'outstr', 'val', 'value',
50 'about', 'alert', 'alter', 'append', 'array', 'ask', 'boot-prefs',
51 'build-tag', 'center-face', 'change-dir', 'charset', 'choose', 'clean-path',
52 'clear-fields', 'confine', 'confirm', 'context', 'cvs-date', 'cvs-version',
53 'decode-cgi', 'decode-url', 'deflag-face', 'delete', 'demo', 'desktop',
54 'dirize', 'dispatch', 'do-boot', 'do-events', 'do-face', 'do-face-alt',
55 'does', 'dump-face', 'dump-pane', 'echo', 'editor', 'emailer', 'emit',
56 'extract', 'find-by-type', 'find-key-face', 'find-window', 'flag-face',
57 'flash', 'focus', 'for', 'forall', 'forever', 'forskip', 'func', 'function',
58 'get-net-info', 'get-style', 'has', 'help', 'hide-popup', 'import-email',
59 'inform', 'input', 'insert-event-func', 'join', 'launch', 'launch-thru',
60 'layout', 'license', 'list-dir', 'load-image', 'load-prefs', 'load-thru',
61 'make-dir', 'make-face', 'net-error', 'open-events', 'parse-email-addrs',
62 'parse-header', 'parse-header-date', 'parse-xml', 'path-thru', 'probe',
63 'protect-system', 'read-net', 'read-thru', 'reboot', 'reform', 'rejoin',
64 'remold', 'remove-event-func', 'rename', 'repend', 'replace', 'request',
65 'request-color', 'request-date', 'request-download', 'request-file',
66 'request-list', 'request-pass', 'request-text', 'resend', 'save-prefs',
67 'save-user', 'scroll-para', 'send', 'set-font', 'set-net', 'set-para',
68 'set-style', 'set-user', 'set-user-name', 'show-popup', 'source',
69 'split-path', 'stylize', 'switch', 'throw-on-error', 'to-binary',
70 'to-bitset', 'to-block', 'to-char', 'to-date', 'to-decimal', 'to-email',
71 'to-event', 'to-file', 'to-get-word', 'to-hash', 'to-idate', 'to-image',
72 'to-integer', 'to-issue', 'to-list', 'to-lit-path', 'to-lit-word', 'to-logic',
73 'to-money', 'to-none', 'to-pair', 'to-paren', 'to-path', 'to-refinement',
74 'to-set-path', 'to-set-word', 'to-string', 'to-tag', 'to-time', 'to-tuple',
75 'to-url', 'to-word', 'unfocus', 'uninstall', 'unview', 'upgrade', 'Usage',
76 'vbug', 'view', 'view-install', 'view-prefs', 'what', 'what-dir',
77 'write-user', 'return', 'at', 'space', 'pad', 'across', 'below', 'origin',
78 'guide', 'tabs', 'indent', 'style', 'styles', 'size', 'sense', 'backcolor',
79 'do', 'none',
80 'action?', 'any-block?', 'any-function?', 'any-string?', 'any-type?',
81 'any-word?', 'binary?', 'bitset?', 'block?', 'char?', 'datatype?', 'date?',
82 'decimal?', 'email?', 'empty?', 'equal?', 'error?', 'even?', 'event?',
83 'file?', 'function?', 'get-word?', 'greater-or-equal?', 'greater?', 'hash?',
84 'head?', 'image?', 'index?', 'integer?', 'issue?', 'length?',
85 'lesser-or-equal?', 'lesser?', 'library?', 'list?', 'lit-path?', 'lit-word?',
86 'logic?', 'money?', 'native?', 'negative?', 'none?', 'not-equal?', 'number?',
87 'object?', 'odd?', 'op?', 'pair?', 'paren?', 'path?', 'port?', 'positive?',
88 'refinement?', 'routine?', 'same?', 'series?', 'set-path?', 'set-word?',
89 'strict-equal?', 'strict-not-equal?', 'string?', 'struct?', 'tag?', 'tail?',
90 'time?', 'tuple?', 'unset?', 'url?', 'word?', 'zero?', 'connected?',
91 'crypt-strength?', 'exists-key?', 'input?', 'script?', 'type?', 'value?', '?',
92 '??', 'dir?', 'exists-thru?', 'exists?', 'flag-face?', 'found?', 'in-window?',
93 'info?', 'inside?', 'link-app?', 'link?', 'modified?', 'offset?', 'outside?',
94 'screen-offset?', 'size?', 'span?', 'view?', 'viewed?', 'win-offset?',
95 'within?',
96 'action!', 'any-block!', 'any-function!', 'any-string!', 'any-type!',
97 'any-word!', 'binary!', 'bitset!', 'block!', 'char!', 'datatype!', 'date!',
98 'decimal!', 'email!', 'error!', 'event!', 'file!', 'function!', 'get-word!',
99 'hash!', 'image!', 'integer!', 'issue!', 'library!', 'list!', 'lit-path!',
100 'lit-word!', 'logic!', 'money!', 'native!', 'none!', 'number!', 'object!',
101 'op!', 'pair!', 'paren!', 'path!', 'port!', 'refinement!', 'routine!',
102 'series!', 'set-path!', 'set-word!', 'string!', 'struct!', 'symbol!', 'tag!',
103 'time!', 'tuple!', 'unset!', 'url!', 'word!',
104 'true', 'false', 'self'
105 }, '~-?!'))
107 -- Identifiers.
108 local word = (l.alpha + '-') * (l.alnum + '-')^0
109 local identifier = token(l.IDENTIFIER, word)
111 -- Operators.
112 local operator = token(l.OPERATOR, S('=<>+/*:()[]'))
114 M._rules = {
115 {'whitespace', ws},
116 {'comment', comment},
117 {'keyword', keyword},
118 {'identifier', identifier},
119 {'string', string},
120 {'operator', operator},
123 M._foldsymbols = {
124 _patterns = {'[%[%]{}]', ';'},
125 [l.COMMENT] = {['{'] = 1, ['}'] = -1, [';'] = l.fold_line_comments(';')},
126 [l.OPERATOR] = {['['] = 1, [']'] = -1, ['{'] = 1, ['}'] = -1}
129 return M