Skip to content

Commit

Permalink
LiveScript: Make interpolated strings greedy + fix variable and ident…
Browse files Browse the repository at this point in the history
…ifier regexps
  • Loading branch information
Golmote committed Oct 22, 2017
1 parent aa426b0 commit c581049
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
31 changes: 16 additions & 15 deletions components/prism-livescript.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
Prism.languages.livescript = {
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
lookbehind: true
},
{
pattern: /(^|[^\\])#.*/,
lookbehind: true
}
],
'interpolated-string': {
pattern: /("""|")(?:\\[\s\S]|(?!\1)[^\\])*\1/,
/* Look-behind and look-ahead prevents wrong behavior of the greedy pattern
* forcing it to match """-quoted string when it would otherwise match "-quoted first. */
pattern: /(^|[^"])("""|")(?:\\[\s\S]|(?!\2)[^\\])*\2(?!")/,
lookbehind: true,
greedy: true,
inside: {
'variable': {
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|\d)*/m,
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|[\d_])*/m,
lookbehind: true
},
'interpolation': {
Expand All @@ -21,18 +34,6 @@ Prism.languages.livescript = {
'string': /[\s\S]+/
}
},
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\])#.*/,
lookbehind: true,
greedy: true
}
],
'string': [
{
pattern: /('''|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
Expand Down Expand Up @@ -80,7 +81,7 @@ Prism.languages.livescript = {
alias: 'variable'
},
'number': /\b(?:\d+~[\da-z]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[a-z]\w*)?)/i,
'identifier': /[a-z_](?:-?[a-z]|\d)*/i,
'identifier': /[a-z_](?:-?[a-z]|[\d_])*/i,
'operator': [
// Spaced .
{
Expand Down
2 changes: 1 addition & 1 deletion components/prism-livescript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tests/languages/livescript/identifier_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ foo-bar42-baz
yes-no
function-case
delete-by
a-b2
_-a_

----------------------------------------------------

Expand All @@ -13,7 +15,9 @@ delete-by
["identifier", "foo-bar42-baz"],
["identifier", "yes-no"],
["identifier", "function-case"],
["identifier", "delete-by"]
["identifier", "delete-by"],
["identifier", "a-b2"],
["identifier", "_-a_"]
]

----------------------------------------------------
Expand Down

0 comments on commit c581049

Please sign in to comment.