ui: make primary cursor blink even if no lua theme has been loaded
[vis.git] / lexers / chuck.lua
blob3efe70429c91db4a68f8dfb0adb04eeb7567f017
1 --------------------------------------------------------------------------------
2 -- The MIT License
3 --
4 -- Copyright (c) 2010 Martin Morawetz
5 --
6 -- Permission is hereby granted, free of charge, to any person obtaining a copy
7 -- of this software and associated documentation files (the "Software"), to deal
8 -- in the Software without restriction, including without limitation the rights
9 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 -- copies of the Software, and to permit persons to whom the Software is
11 -- furnished to do so, subject to the following conditions:
13 -- The above copyright notice and this permission notice shall be included in
14 -- all copies or substantial portions of the Software.
16 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 -- THE SOFTWARE.
23 --------------------------------------------------------------------------------
25 -- Based on lexer code from Mitchell mitchell.att.foicica.com.
27 local l = require('lexer')
28 local token, word_match = l.token, l.word_match
29 local P, R, S = lpeg.P, lpeg.R, lpeg.S
31 local M = {_NAME = 'chuck'}
33 -- Whitespace.
34 local ws = token(l.WHITESPACE, l.space^1)
36 -- Comments.
37 local line_comment = '//' * l.nonnewline_esc^0
38 local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1
39 local comment = token(l.COMMENT, line_comment + block_comment)
41 -- Strings.
42 local sq_str = P('L')^-1 * l.delimited_range("'", true)
43 local dq_str = P('L')^-1 * l.delimited_range('"', true)
44 local string = token(l.STRING, sq_str + dq_str)
46 -- Numbers.
47 local number = token(l.NUMBER, l.float + l.integer)
49 -- Constants.
50 local constant = token(l.CONSTANT, word_match{
51 -- special values
52 'false', 'maybe', 'me', 'null', 'NULL', 'pi', 'true'
55 -- Special special value.
56 local now = token('now', P('now'))
58 -- Times.
59 local time = token('time', word_match{
60 'samp', 'ms', 'second', 'minute', 'hour', 'day', 'week'
63 -- Keywords.
64 local keyword = token(l.KEYWORD, word_match{
65 -- Control structures.
66 'break', 'continue', 'else', 'for', 'if', 'repeat', 'return', 'switch',
67 'until', 'while',
68 -- Other chuck keywords.
69 'function', 'fun', 'spork', 'const', 'new'
72 -- Classes.
73 local class = token(l.CLASS, word_match{
74 -- Class keywords.
75 'class', 'extends', 'implements', 'interface', 'private', 'protected',
76 'public', 'pure', 'super', 'static', 'this'
79 -- Types.
80 local types = token(l.TYPE, word_match{
81 'float', 'int', 'time', 'dur', 'void', 'same'
84 -- Global ugens.
85 local ugen = token('ugen', word_match{'dac', 'adc', 'blackhole'})
87 -- Identifiers.
88 local identifier = token(l.IDENTIFIER, l.word)
90 -- Operators.
91 local operator = token(l.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}@'))
93 M._rules = {
94 {'whitespace', ws},
95 {'string', string},
96 {'keyword', keyword},
97 {'constant', constant},
98 {'type', types},
99 {'class', class},
100 {'ugen', ugen},
101 {'time', time},
102 {'now', now},
103 {'identifier', identifier},
104 {'comment', comment},
105 {'number', number},
106 {'operator', operator},
109 M._tokenstyles = {
110 ugen = l.STYLE_CONSTANT,
111 time = l.STYLE_NUMBER,
112 now = l.STYLE_CONSTANT..',bold'
115 return M