Skip to content

Commit f41bcf2

Browse files
authoredDec 5, 2021
Haxe: Improved tokenization (#3211)
1 parent f11b86e commit f41bcf2

16 files changed

+772
-152
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@
535535
"haxe": {
536536
"title": "Haxe",
537537
"require": "clike",
538+
"optional": "regex",
538539
"owner": "Golmote"
539540
},
540541
"hcl": {

‎components/prism-haxe.js

+54-21
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,78 @@
11
Prism.languages.haxe = Prism.languages.extend('clike', {
2-
// Strings can be multi-line
32
'string': {
4-
pattern: /(["'])(?:(?!\1)[^\\]|\\[\s\S])*\1/,
3+
// Strings can be multi-line
4+
pattern: /"(?:[^"\\]|\\[\s\S])*"/,
5+
greedy: true
6+
},
7+
'class-name': [
8+
{
9+
pattern: /(\b(?:abstract|class|enum|extends|implements|interface|new|typedef)\s+)[A-Z_]\w*/,
10+
lookbehind: true,
11+
},
12+
// based on naming convention
13+
/\b[A-Z]\w*/
14+
],
15+
// The final look-ahead prevents highlighting of keywords if expressions such as "haxe.macro.Expr"
16+
'keyword': /\bthis\b|\b(?:abstract|as|break|case|cast|catch|class|continue|default|do|dynamic|else|enum|extends|extern|final|for|from|function|if|implements|import|in|inline|interface|macro|new|null|operator|overload|override|package|private|public|return|static|super|switch|throw|to|try|typedef|untyped|using|var|while)(?!\.)\b/,
17+
'function': {
18+
pattern: /\b[a-z_]\w*(?=\s*(?:<[^<>]*>\s*)?\()/i,
19+
greedy: true
20+
},
21+
'operator': /\.{3}|\+\+|--|&&|\|\||->|=>|(?:<<?|>{1,3}|[-+*/%!=&|^])=?|[?:~]/
22+
});
23+
24+
Prism.languages.insertBefore('haxe', 'string', {
25+
'string-interpolation': {
26+
pattern: /'(?:[^'\\]|\\[\s\S])*'/,
527
greedy: true,
628
inside: {
729
'interpolation': {
8-
pattern: /(^|[^\\])\$(?:\w+|\{[^}]+\})/,
30+
pattern: /(^|[^\\])\$(?:\w+|\{[^{}]+\})/,
931
lookbehind: true,
1032
inside: {
11-
'interpolation': {
12-
pattern: /^\$\w*/,
13-
alias: 'variable'
14-
}
15-
// See rest below
33+
'interpolation-punctuation': {
34+
pattern: /^\$\{?|\}$/,
35+
alias: 'punctuation'
36+
},
37+
'expression': {
38+
pattern: /[\s\S]+/,
39+
inside: Prism.languages.haxe
40+
},
1641
}
17-
}
42+
},
43+
'string': /[\s\S]+/
1844
}
19-
},
20-
// The final look-ahead prevents highlighting of keywords if expressions such as "haxe.macro.Expr"
21-
'keyword': /\bthis\b|\b(?:abstract|as|break|case|cast|catch|class|continue|default|do|dynamic|else|enum|extends|extern|for|from|function|if|implements|import|in|inline|interface|macro|new|null|override|private|public|return|static|super|switch|throw|to|try|typedef|using|var|while)(?!\.)\b/,
22-
'operator': /\.{3}|\+\+?|-[->]?|[=!]=?|&&?|\|\|?|<[<=]?|>[>=]?|[*\/%~^]/
45+
}
2346
});
47+
2448
Prism.languages.insertBefore('haxe', 'class-name', {
2549
'regex': {
26-
pattern: /~\/(?:[^\/\\\r\n]|\\.)+\/[igmsu]*/,
27-
greedy: true
50+
pattern: /~\/(?:[^\/\\\r\n]|\\.)+\/[a-z]*/,
51+
greedy: true,
52+
inside: {
53+
'regex-flags': /\b[a-z]+$/,
54+
'regex-source': {
55+
pattern: /^(~\/)[\s\S]+(?=\/$)/,
56+
lookbehind: true,
57+
alias: 'language-regex',
58+
inside: Prism.languages.regex
59+
},
60+
'regex-delimiter': /^~\/|\/$/,
61+
}
2862
}
2963
});
64+
3065
Prism.languages.insertBefore('haxe', 'keyword', {
3166
'preprocessor': {
32-
pattern: /#\w+/,
33-
alias: 'builtin'
67+
pattern: /#(?:else|elseif|end|if)\b.*/,
68+
alias: 'property'
3469
},
3570
'metadata': {
36-
pattern: /@:?\w+/,
71+
pattern: /@:?[\w.]+/,
3772
alias: 'symbol'
3873
},
3974
'reification': {
4075
pattern: /\$(?:\w+|(?=\{))/,
41-
alias: 'variable'
76+
alias: 'important'
4277
}
4378
});
44-
Prism.languages.haxe['string'].inside['interpolation'].inside.rest = Prism.languages.haxe;
45-
delete Prism.languages.haxe['class-name'];

‎components/prism-haxe.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
~/ha\/xe/i
2+
~/[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z][A-Z][A-Z]?/i
3+
~/(dog|fox)/igmsu
4+
5+
----------------------------------------------------
6+
7+
[
8+
["regex", [
9+
["regex-delimiter", "~/"],
10+
["regex-source", [
11+
"ha",
12+
["escape", "\\/"],
13+
"xe"
14+
]],
15+
["regex-delimiter", "/"],
16+
["regex-flags", "i"]
17+
]],
18+
["regex", [
19+
["regex-delimiter", "~/"],
20+
["regex-source", [
21+
["char-class", [
22+
["char-class-punctuation", "["],
23+
["range", [
24+
"A",
25+
["range-punctuation", "-"],
26+
"Z"
27+
]],
28+
["range", [
29+
"0",
30+
["range-punctuation", "-"],
31+
"9"
32+
]],
33+
"._%-",
34+
["char-class-punctuation", "]"]
35+
]],
36+
["quantifier", "+"],
37+
"@",
38+
["char-class", [
39+
["char-class-punctuation", "["],
40+
["range", [
41+
"A",
42+
["range-punctuation", "-"],
43+
"Z"
44+
]],
45+
["range", [
46+
"0",
47+
["range-punctuation", "-"],
48+
"9"
49+
]],
50+
".-",
51+
["char-class-punctuation", "]"]
52+
]],
53+
["quantifier", "+"],
54+
["char-set", "."],
55+
["char-class", [
56+
["char-class-punctuation", "["],
57+
["range", [
58+
"A",
59+
["range-punctuation", "-"],
60+
"Z"
61+
]],
62+
["char-class-punctuation", "]"]
63+
]],
64+
["char-class", [
65+
["char-class-punctuation", "["],
66+
["range", [
67+
"A",
68+
["range-punctuation", "-"],
69+
"Z"
70+
]],
71+
["char-class-punctuation", "]"]
72+
]],
73+
["char-class", [
74+
["char-class-punctuation", "["],
75+
["range", [
76+
"A",
77+
["range-punctuation", "-"],
78+
"Z"
79+
]],
80+
["char-class-punctuation", "]"]
81+
]],
82+
["quantifier", "?"]
83+
]],
84+
["regex-delimiter", "/"],
85+
["regex-flags", "i"]
86+
]],
87+
["regex", [
88+
["regex-delimiter", "~/"],
89+
["regex-source", [
90+
["group", ["("]],
91+
"dog",
92+
["alternation", "|"],
93+
"fox",
94+
["group", ")"]
95+
]],
96+
["regex-delimiter", "/"],
97+
["regex-flags", "igmsu"]
98+
]]
99+
]

0 commit comments

Comments
 (0)
Please sign in to comment.