Skip to content

Commit

Permalink
Merge branch 'master' into lgtm
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Nov 15, 2020
2 parents 73efecd + c776c4b commit f63fa52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
@@ -1,4 +1,8 @@
## Version 10.4.0 (work in process)
## Version 10.4.0 (a work in process)

Parser:

- enh(parser) use negative look-ahead for `beginKeywords` support (#2813) [Josh Goebel][]

Deprecations:

Expand Down
11 changes: 5 additions & 6 deletions src/lib/mode_compiler.js
Expand Up @@ -240,18 +240,17 @@ 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
* special _internal_ 'on:begin' callback for modes with `beginKeywords`
* @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();
}
}
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions 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');
});

0 comments on commit f63fa52

Please sign in to comment.