Skip to content

Commit 8fce444

Browse files
authored
Merge pull request #60 from highlightjs/restrict-verbatim
Restrict highlighting of verbatim to standalone Yul
2 parents a292682 + 2481114 commit 8fce444

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/common.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,6 @@ function baseAssembly(hljs) {
100100
//in assembly, identifiers can contain periods (but may not start with them)
101101
var SOL_ASSEMBLY_LEXEMES_RE = /[A-Za-z_$][A-Za-z_$0-9.]*/;
102102

103-
var SOL_ASSEMBLY_VERBATIM_RE = /\bverbatim_[1-9]?[0-9]i_[1-9]?[0-9]o\b(?!\$)/;
104-
if (isNegativeLookbehindAvailable()) {
105-
//replace just first \b
106-
SOL_ASSEMBLY_VERBATIM_RE = SOL_ASSEMBLY_VERBATIM_RE.source.replace(/\\b/, '(?<!\\$)\\b');
107-
}
108-
109-
//highlights the "verbatim" builtin. making a separate mode for this due to
110-
//its variability.
111-
var SOL_ASSEMBLY_VERBATIM_MODE = {
112-
className: "built_in",
113-
begin: SOL_ASSEMBLY_VERBATIM_RE
114-
};
115-
116103
var SOL_ASSEMBLY_TITLE_MODE =
117104
hljs.inherit(hljs.TITLE_MODE, {
118105
begin: /[A-Za-z$_][0-9A-Za-z$_]*/,
@@ -153,7 +140,6 @@ function baseAssembly(hljs) {
153140
HEX_QUOTE_STRING_MODE,
154141
hljs.C_LINE_COMMENT_MODE,
155142
hljs.C_BLOCK_COMMENT_MODE,
156-
SOL_ASSEMBLY_VERBATIM_MODE,
157143
SOL_NUMBER,
158144
SOL_ASSEMBLY_OPERATORS,
159145
{ // functions

src/languages/yul.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
* @since: 2016-07-01
99
*/
1010

11-
const { SOL_ASSEMBLY_KEYWORDS, baseAssembly } = require("../common.js");
11+
const {
12+
SOL_ASSEMBLY_KEYWORDS,
13+
baseAssembly,
14+
isNegativeLookbehindAvailable
15+
} = require("../common.js");
1216

1317
function hljsDefineYul(hljs) {
1418

@@ -22,9 +26,29 @@ function hljsDefineYul(hljs) {
2226
literal: SOL_ASSEMBLY_KEYWORDS.literal
2327
};
2428

29+
var YUL_VERBATIM_RE = /\bverbatim_[1-9]?[0-9]i_[1-9]?[0-9]o\b(?!\$)/;
30+
if (isNegativeLookbehindAvailable()) {
31+
//replace just first \b
32+
YUL_VERBATIM_RE = YUL_VERBATIM_RE.source.replace(/\\b/, '(?<!\\$)\\b');
33+
}
34+
35+
//highlights the "verbatim" builtin. making a separate mode for this due to
36+
//its variability.
37+
var YUL_VERBATIM_MODE = {
38+
className: "built_in",
39+
begin: YUL_VERBATIM_RE
40+
};
41+
42+
var BASE_ASSEMBLY_ENVIRONMENT = baseAssembly(hljs);
43+
2544
return hljs.inherit(
26-
baseAssembly(hljs),
27-
{ keywords: YUL_KEYWORDS }
45+
BASE_ASSEMBLY_ENVIRONMENT,
46+
{
47+
keywords: YUL_KEYWORDS,
48+
contains: BASE_ASSEMBLY_ENVIRONMENT.contains.concat([
49+
YUL_VERBATIM_MODE
50+
])
51+
}
2852
);
2953
}
3054

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ it('yul operators', function () {
102102
});
103103

104104
it('verbatim', function () {
105+
this.timeout(4000);
105106
for (let inArgs = 0; inArgs < 100; inArgs++) {
106107
for (let outArgs = 0; outArgs < 100; outArgs++) {
107108
const verbatim = `verbatim_${inArgs}i_${outArgs}o`;

0 commit comments

Comments
 (0)