julia.lua (1283B)
1 -- ? LPeg lexer. 2 3 local l = require('lexer') 4 local token, word_match = l.token, l.word_match 5 local P, R, S = lpeg.P, lpeg.R, lpeg.S 6 7 local M = {_NAME = 'julia'} 8 9 -- Whitespace. 10 local ws = token(l.WHITESPACE, l.space^1) 11 12 -- Comments. 13 local comment = token(l.COMMENT, '#' * l.nonnewline_esc^0) 14 15 -- Strings. 16 local dq_str = P('U')^-1 * l.delimited_range('"', true) 17 local triple_dq_str = '"""' * (l.any - '"""')^0 * P('"""')^-1 18 local string = token(l.STRING, triple_dq_str + dq_str) 19 20 -- Keywords from `reserved-words` in Julia 21 local keyword = token(l.KEYWORD, word_match{ 22 'begin', 'while', 'if', 'for', 'try', 'return', 'break', 'continue', 23 'function', 'macro', 'quote', 'let', 'local' ', 'global', 'const', 'do', 24 'struct', 'type', 'immutable', 'importall', 'module', 'baremodule', 'using', 25 'import', 'export', 'end', 'else', 'catch', 'finally', 'true', 'false' 26 }) 27 28 -- Operators. 29 local operator = token(l.OPERATOR, S('!%^&*()[]{}-=+/|:;.,?<>~`')) 30 31 M._rules = { 32 {'whitespace', ws}, 33 {'keyword', keyword}, 34 -- {'function', func}, 35 -- {'constant', constant}, 36 -- {'self', self}, 37 -- {'identifier', identifier}, 38 {'comment', comment}, 39 -- {'string', string}, 40 -- {'number', number}, 41 -- {'decorator', decorator}, 42 {'operator', operator}, 43 } 44 45 M._tokenstyles = { 46 47 } 48 49 return M