From be0c036f89724e1d88764425ec0af1fead8e4b8a Mon Sep 17 00:00:00 2001 From: Katrina Grace Date: Sat, 11 Jun 2022 16:54:26 -0600 Subject: Add support for SQL strings to language_php --- plugins/language_php.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'plugins') diff --git a/plugins/language_php.lua b/plugins/language_php.lua index 83bd901..d00ea8f 100644 --- a/plugins/language_php.lua +++ b/plugins/language_php.lua @@ -24,6 +24,87 @@ syntax.add { { pattern = "//.-\n", type = "comment" }, { pattern = "#.-\n", type = "comment" }, { pattern = { "/%*", "%*/" }, type = "comment" }, + -- SQL strings + { + pattern = { '"[cC][rR][eE][aA][tT][eE]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[cC][rR][eE][aA][tT][eE]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[sS][eE][lL][eE][cC][tT]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[sS][eE][lL][eE][cC][tT]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[iI][nN][sS][eE][rR][tT]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[iI][nN][sS][eE][rR][tT]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[uU][pP][dD][aA][tT][eE]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[uU][pP][dD][aA][tT][eE]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[rR][eE][pP][lL][aA][cC][eE]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[rR][eE][pP][lL][aA][cC][eE]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[dD][eE][lL][eE][tT][eE]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[dD][eE][lL][eE][tT][eE]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[dD][rR][oO][pP]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[dD][rR][oO][pP]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '"[aA][lL][tT][eE][rR]%s+', '"', '\\' }, + syntax = '.sql', + type = "keyword" + }, + { + pattern = { '\'[aA][lL][tT][eE][rR]%s+', '\'', '\\' }, + syntax = '.sql', + type = "keyword" + }, -- The '\\' is for escaping to work on " or ' { pattern = { '"', '"', '\\' }, type = "string" }, { pattern = { "'", "'", '\\' }, type = "string" }, -- cgit v1.2.3 From 9f7398e2a926e188919b23dd68dd60df2da6fb1c Mon Sep 17 00:00:00 2001 From: Katrina Grace Date: Sat, 11 Jun 2022 17:49:41 -0600 Subject: Change to regex for language_php SQL strings --- plugins/language_php.lua | 91 ++++++++---------------------------------------- 1 file changed, 15 insertions(+), 76 deletions(-) (limited to 'plugins') diff --git a/plugins/language_php.lua b/plugins/language_php.lua index d00ea8f..5ef4f22 100644 --- a/plugins/language_php.lua +++ b/plugins/language_php.lua @@ -10,6 +10,15 @@ local syntax = require "core.syntax" require "plugins.language_css" require "plugins.language_js" +-- generate SQL string marker regex +local sql_markers = { 'create', 'select', 'insert', 'update', 'replace', 'delete', 'drop', 'alter' } +local sql_regex = {} +for _,marker in ipairs(sql_markers) do + table.insert(sql_regex, marker) + table.insert(sql_regex, string.upper(marker)) +end +sql_regex = table.concat(sql_regex, '|') + -- define the core php syntax coloring syntax.add { name = "PHP Source", @@ -26,84 +35,14 @@ syntax.add { { pattern = { "/%*", "%*/" }, type = "comment" }, -- SQL strings { - pattern = { '"[cC][rR][eE][aA][tT][eE]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[cC][rR][eE][aA][tT][eE]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[sS][eE][lL][eE][cC][tT]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[sS][eE][lL][eE][cC][tT]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[iI][nN][sS][eE][rR][tT]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[iI][nN][sS][eE][rR][tT]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[uU][pP][dD][aA][tT][eE]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[uU][pP][dD][aA][tT][eE]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[rR][eE][pP][lL][aA][cC][eE]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[rR][eE][pP][lL][aA][cC][eE]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[dD][eE][lL][eE][tT][eE]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[dD][eE][lL][eE][tT][eE]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[dD][rR][oO][pP]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '\'[dD][rR][oO][pP]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" - }, - { - pattern = { '"[aA][lL][tT][eE][rR]%s+', '"', '\\' }, - syntax = '.sql', - type = "keyword" + regex = { '"(?=(?:'..sql_regex..')\\s+)', '"', '\\' }, + syntax = '.sql', + type = "string" }, { - pattern = { '\'[aA][lL][tT][eE][rR]%s+', '\'', '\\' }, - syntax = '.sql', - type = "keyword" + regex = { '\'(?=(?:'..sql_regex..')\\s+)', '\'', '\\' }, + syntax = '.sql', + type = "string" }, -- The '\\' is for escaping to work on " or ' { pattern = { '"', '"', '\\' }, type = "string" }, -- cgit v1.2.3