Skip to content

Commit

Permalink
try to improve clarity with naming
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Mar 2, 2020
1 parent e09c990 commit 9b0fcb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/highlight.js
Expand Up @@ -210,7 +210,7 @@ const HLJS = function(hljs) {
}

function doIgnore(lexeme) {
if (top.terminators.startAt === 0) {
if (top.matcher.regexIndex === 0) {
// no more regexs to potentially match here, so we move the cursor forward one
// space
mode_buffer += lexeme[0];
Expand Down Expand Up @@ -377,16 +377,16 @@ const HLJS = function(hljs) {

try {
var findNextRegexMatch = false;
top.terminators.startAt = 0;
top.matcher.regexIndex = 0;

while (true) {
top.terminators.lastIndex = index;
top.matcher.lastIndex = index;
if (findNextRegexMatch) {
findNextRegexMatch = false;
} else {
top.terminators.startAt = 0;
top.matcher.regexIndex = 0;
}
match = top.terminators.exec(codeToHighlight);
match = top.matcher.exec(codeToHighlight);
// console.log("match", match[0], match.rule && match.rule.begin)
if (!match)
break;
Expand Down
14 changes: 7 additions & 7 deletions src/lib/mode_compiler.js
Expand Up @@ -103,7 +103,7 @@ export function compileLanguage(language) {
this.count = 0;

this.lastIndex = 0;
this.startAt = 0;
this.regexIndex = 0;
}

getMatcher(index) {
Expand All @@ -122,16 +122,16 @@ export function compileLanguage(language) {
}

exec(s) {
let m = this.getMatcher(this.startAt);
let m = this.getMatcher(this.regexIndex);
m.lastIndex = this.lastIndex;
let result = m.exec(s);
if (result) {
this.startAt += result.position + 1;
if (this.startAt === this.count) // wrap-around
this.startAt = 0;
this.regexIndex += result.position + 1;
if (this.regexIndex === this.count) // wrap-around
this.regexIndex = 0;
}

// this.startAt = 0;
// this.regexIndex = 0;
return result;
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ export function compileLanguage(language) {
compileMode(mode.starts, parent);
}

mode.terminators = buildModeRegex(mode);
mode.matcher = buildModeRegex(mode);
}

// self is not valid at the top-level
Expand Down

0 comments on commit 9b0fcb5

Please sign in to comment.