From fa00d2bfe86c9aa938a4b41978a0ddf73986f2bc Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Wed, 4 Oct 2023 07:22:19 +0900 Subject: [PATCH] Remove spaces from regexps in anticipation of identical change on https://github.com/scriptcoded/sql-highlight/pull/141. --- lib/index.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index 17a3a05..ac012e2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,3 @@ -/* eslint-disable no-regex-spaces */ 'use strict' const keywords = require('./keywords') @@ -21,37 +20,32 @@ const DEFAULT_OPTIONS = { } const highlighters = [ - /\b(? \d+ (?:\.\d+)? )\b/, + /\b(?\d+(?:\.\d+)?)\b/, // Note: Repeating string escapes like 'sql''server' will also work as they are just repeating strings - /(? '(?: [^'\\] | \\. )*' | "(?: [^"\\] | \\. )*" )/, + /(?'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")/, - /(? --[^\n\r]* | #[^\n\r]* | \/\* (?: [^*] | \* (?!\/) )* \*\/ )/, + /(?--[^\n\r]*|#[^\n\r]*|\/\*(?:[^*]|\*(?!\/))*\*\/)/, // Future improvement: Comments should be allowed between the function name and the opening parenthesis - /\b(? \w+ ) (?= \s*\( )/, + /\b(?\w+)(?=\s*\()/, - /(? [()] )/, + /(?[()])/, - /(? != | [=%*/\-+,;:<>.] )/, + /(?!=|[=%*/\-+,;:<>.])/, - /(? \b\w+\b | `(?: [^`\\] | \\. )*`)/, + /(?\b\w+\b|`(?:[^`\\]|\\.)*`)/, - /(? \s+ )/, + /(?\s+)/, - /(? \.+? )/ + /(?\.+?)/ ] -function getRegexString (regex) { - const str = regex.toString() - return str.replace(/^\/|\/\w*$|[\t ]+/g, '') -} - // Regex of the shape /((?...)|(?...)|...|$)/g const tokenizer = new RegExp( '(' + '\\b(?' + keywords.join('|') + ')\\b|' + - highlighters.map(getRegexString).join('|') + + highlighters.map(regex => regex.source).join('|') + ')', 'gis' )