Skip to content

Commit c581049

Browse files
committed
LiveScript: Make interpolated strings greedy + fix variable and identifier regexps
1 parent aa426b0 commit c581049

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

components/prism-livescript.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
Prism.languages.livescript = {
2+
'comment': [
3+
{
4+
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
5+
lookbehind: true
6+
},
7+
{
8+
pattern: /(^|[^\\])#.*/,
9+
lookbehind: true
10+
}
11+
],
212
'interpolated-string': {
3-
pattern: /("""|")(?:\\[\s\S]|(?!\1)[^\\])*\1/,
13+
/* Look-behind and look-ahead prevents wrong behavior of the greedy pattern
14+
* forcing it to match """-quoted string when it would otherwise match "-quoted first. */
15+
pattern: /(^|[^"])("""|")(?:\\[\s\S]|(?!\2)[^\\])*\2(?!")/,
16+
lookbehind: true,
417
greedy: true,
518
inside: {
619
'variable': {
7-
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|\d)*/m,
20+
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|[\d_])*/m,
821
lookbehind: true
922
},
1023
'interpolation': {
@@ -21,18 +34,6 @@ Prism.languages.livescript = {
2134
'string': /[\s\S]+/
2235
}
2336
},
24-
'comment': [
25-
{
26-
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
27-
lookbehind: true,
28-
greedy: true
29-
},
30-
{
31-
pattern: /(^|[^\\])#.*/,
32-
lookbehind: true,
33-
greedy: true
34-
}
35-
],
3637
'string': [
3738
{
3839
pattern: /('''|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
@@ -80,7 +81,7 @@ Prism.languages.livescript = {
8081
alias: 'variable'
8182
},
8283
'number': /\b(?:\d+~[\da-z]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[a-z]\w*)?)/i,
83-
'identifier': /[a-z_](?:-?[a-z]|\d)*/i,
84+
'identifier': /[a-z_](?:-?[a-z]|[\d_])*/i,
8485
'operator': [
8586
// Spaced .
8687
{

components/prism-livescript.min.js

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

tests/languages/livescript/identifier_feature.test

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ foo-bar42-baz
44
yes-no
55
function-case
66
delete-by
7+
a-b2
8+
_-a_
79

810
----------------------------------------------------
911

@@ -13,7 +15,9 @@ delete-by
1315
["identifier", "foo-bar42-baz"],
1416
["identifier", "yes-no"],
1517
["identifier", "function-case"],
16-
["identifier", "delete-by"]
18+
["identifier", "delete-by"],
19+
["identifier", "a-b2"],
20+
["identifier", "_-a_"]
1721
]
1822

1923
----------------------------------------------------

0 commit comments

Comments
 (0)