32 lines
1.2 KiB
Lua
32 lines
1.2 KiB
Lua
-- Copyright 2006-2025 Mitchell. See LICENSE.
|
|
-- go with SQL LPeg lexer.
|
|
|
|
local lexer = lexer
|
|
local starts_line = lexer.starts_line
|
|
local B, P, S = lpeg.B, lpeg.P, lpeg.S
|
|
|
|
local lex = lexer.new(..., {inherit = lexer.load('go')})
|
|
|
|
local open_brace = lex:tag(lexer.OPERATOR, P('{'))
|
|
local close_brace = lex:tag(lexer.OPERATOR, P('}'))
|
|
local backtick = lex:tag(lexer.CODE, P('`'))
|
|
local ws = lex:get_rule('whitespace')
|
|
|
|
local tpl = lexer.new("template")
|
|
tpl:add_rule('keyword', lex:tag(lexer.KEYWORD, lexer.word_match('if else end with range break define continue template block')))
|
|
tpl:add_rule('constant', lex:get_rule('constant'))
|
|
tpl:add_rule('operator', lex:get_rule('operator') + lex:tag(lexer.OPERATOR, S('$')))
|
|
local func = lexer.after_set(' \t\n{|', lexer.word)
|
|
tpl:add_rule('function', lex:tag(lexer.FUNCTION, func))
|
|
tpl:add_rule('identifier', lex:get_rule('identifier'))
|
|
tpl:add_rule('string', lex:get_rule('string'))
|
|
tpl:add_rule('number', lex:get_rule('number'))
|
|
|
|
local sql = lexer.load('sql')
|
|
local sql_kwd = lexer.word_match('ALTER CREATE DELETE DROP GRANT INSERT SELECT UPDATE WITH')
|
|
sql:embed(tpl, open_brace * open_brace, close_brace * close_brace)
|
|
|
|
lex:embed(sql, backtick * #(ws^0 * sql_kwd), backtick)
|
|
|
|
return lex
|