aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/typescript.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lexers/typescript.lua')
-rw-r--r--lua/lexers/typescript.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/lua/lexers/typescript.lua b/lua/lexers/typescript.lua
new file mode 100644
index 0000000..414acf1
--- /dev/null
+++ b/lua/lexers/typescript.lua
@@ -0,0 +1,23 @@
+-- Copyright 2021-2022 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