~martanne/vis

ref: c3cfeacc22abae245047dbf429413e265f92bc3c vis/lua/lexers/typescript.lua -rw-r--r-- 690 bytes
c3cfeaccMarc André Tanner lexers/typescript: add new upstream lexer revision 28e2b60 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Copyright 2021 Mitchell. See LICENSE.
-- TypeScript LPeg lexer.

local lexer = require('lexer')
local token, word_match = lexer.token, lexer.word_match
local P, S = lpeg.P, lpeg.S

local lex = lexer.new('typescript', {inherit = lexer.load('javascript')})

-- Whitespace
lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))

-- Keywords.
lex:modify_rule('keyword', token(lexer.KEYWORD, word_match[[
  abstract as constructor declare is module namespace require type
]]) + lex:get_rule('keyword'))

-- Types.
lex:modify_rule('type', token(lexer.TYPE, word_match[[
  boolean number bigint string unknown any void never symbol object
]]) + lex:get_rule('type'))

return lex