diff --git a/lib/index.js b/lib/index.js index 954d54c..95f3768 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,3 @@ -/* eslint-disable no-regex-spaces */ 'use strict' const keywords = require('./keywords') @@ -23,37 +22,32 @@ const DEFAULT_OPTIONS = { const DEFAULT_KEYWORD = 'default' 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' )