From 4d5726c76784b987b9c659ba82c4dd03ab515a4e Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sat, 31 Oct 2020 18:10:15 -0400 Subject: [PATCH 1/3] enh(parser) user negative look-ahead for beginKeywords --- src/lib/mode_compiler.js | 11 +++++------ test/api/index.js | 15 ++++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/mode_compiler.js b/src/lib/mode_compiler.js index 5d1df3e6e4..bfa840e5a4 100644 --- a/src/lib/mode_compiler.js +++ b/src/lib/mode_compiler.js @@ -240,7 +240,7 @@ export function compileLanguage(language) { // TODO: We need negative look-behind support to do this properly /** - * Skip a match if it has a preceding or trailing dot + * Skip a match if it has a preceding dot * * This is used for `beginKeywords` to prevent matching expressions such as * `bob.keyword.do()`. The mode compiler automatically wires this up as a @@ -248,10 +248,9 @@ export function compileLanguage(language) { * @param {RegExpMatchArray} match * @param {CallbackResponse} response */ - function skipIfhasPrecedingOrTrailingDot(match, response) { + function skipIfhasPrecedingDot(match, response) { const before = match.input[match.index - 1]; - const after = match.input[match.index + match[0].length]; - if (before === "." || after === ".") { + if (before === ".") { response.ignoreMatch(); } } @@ -331,8 +330,8 @@ export function compileLanguage(language) { // or whitespace - this does no harm in any case since our keyword engine // doesn't allow spaces in keywords anyways and we still check for the boundary // first - mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?=\\b|\\s)'; - mode.__beforeBegin = skipIfhasPrecedingOrTrailingDot; + mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)'; + mode.__beforeBegin = skipIfhasPrecedingDot; } if (!mode.begin) mode.begin = /\B|\b/; cmode.beginRe = langRe(mode.begin); diff --git a/test/api/index.js b/test/api/index.js index 0e4b596dcb..223fbc0e30 100644 --- a/test/api/index.js +++ b/test/api/index.js @@ -1,16 +1,17 @@ 'use strict'; describe('hljs', function() { - require('./ident'); - require('./underscoreIdent'); - require('./number'); - require('./cNumber'); + require('./autoDetection'); + require('./beginKeywords'); require('./binaryNumber'); - require('./starters'); + require('./cNumber'); + require('./fixmarkup'); require('./getLanguage'); - require('./autoDetection'); require('./highlight'); - require('./fixmarkup'); + require('./ident'); require('./keywords'); + require('./number'); require('./registerAlias'); + require('./starters'); + require('./underscoreIdent'); }); From 84b2b6c412118371facad5c50cf011c17a25cca4 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sat, 31 Oct 2020 18:12:40 -0400 Subject: [PATCH 2/3] add changelog --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b713560245..b42f8812f9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ ## Version 10.4.0 (work in process) +Parser: + +- enh(parser) use negative look-ahead for `beginKeywords` support (#2813) [Josh Goebel][] + Language Improvements: - enh(julia) Update keyword lists for Julia 1.x (#2781) [Fredrik Ekre][] From 62459f51fc0656f32f0076d9d921dff3a0487b52 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 2 Nov 2020 16:33:00 -0500 Subject: [PATCH 3/3] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b42f8812f9..3a64cccf39 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -## Version 10.4.0 (work in process) +## Version 10.4.0 (a work in process) Parser: