-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #982 from Golmote/prism-livescript
Add support for LiveScript
- Loading branch information
Showing
18 changed files
with
626 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
Prism.languages.livescript = { | ||
'interpolated-string': { | ||
pattern: /("""|")(?:\\[\s\S]|(?!\1)[^\\])*\1/, | ||
greedy: true, | ||
inside: { | ||
'variable': { | ||
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|\d)*/m, | ||
lookbehind: true | ||
}, | ||
'interpolation': { | ||
pattern: /(^|[^\\])#\{[^}]+\}/m, | ||
lookbehind: true, | ||
inside: { | ||
'interpolation-punctuation': { | ||
pattern: /^#\{|\}$/, | ||
alias: 'variable' | ||
} | ||
// See rest below | ||
} | ||
}, | ||
'string': /[\s\S]+/ | ||
} | ||
}, | ||
'comment': [ | ||
{ | ||
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
{ | ||
pattern: /(^|[^\\])#.*/, | ||
lookbehind: true, | ||
greedy: true | ||
} | ||
], | ||
'string': [ | ||
{ | ||
pattern: /('''|')(?:\\[\s\S]|(?!\1)[^\\])*\1/, | ||
greedy: true | ||
}, | ||
{ | ||
pattern: /<\[[\s\S]*?\]>/, | ||
greedy: true | ||
}, | ||
/\\[^\s,;\])}]+/ | ||
], | ||
'regex': [ | ||
{ | ||
pattern: /\/\/(\[.+?]|\\.|(?!\/\/)[^\\])+\/\/[gimyu]{0,5}/, | ||
greedy: true, | ||
inside: { | ||
'comment': { | ||
pattern: /(^|[^\\])#.*/, | ||
lookbehind: true | ||
} | ||
} | ||
}, | ||
{ | ||
pattern: /\/(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}/, | ||
greedy: true | ||
} | ||
], | ||
'keyword': { | ||
pattern: /(^|(?!-).)\b(?:break|case|catch|class|const|continue|default|do|else|extends|fallthrough|finally|for(?: ever)?|function|if|implements|it|let|loop|new|null|otherwise|own|return|super|switch|that|then|this|throw|try|unless|until|var|void|when|while|yield)(?!-)\b/m, | ||
lookbehind: true | ||
}, | ||
'keyword-operator': { | ||
pattern: /(^|[^-])\b(?:(?:delete|require|typeof)!|(?:and|by|delete|export|from|import(?: all)?|in|instanceof|is(?:nt| not)?|not|of|or|til|to|typeof|with|xor)(?!-)\b)/m, | ||
lookbehind: true, | ||
alias: 'operator' | ||
}, | ||
'boolean': { | ||
pattern: /(^|[^-])\b(?:false|no|off|on|true|yes)(?!-)\b/m, | ||
lookbehind: true | ||
}, | ||
'argument': { | ||
// Don't match .&. nor && | ||
pattern: /(^|(?!\.&\.)[^&])&(?!&)\d*/m, | ||
lookbehind: true, | ||
alias: 'variable' | ||
}, | ||
'number': /\b(?:\d+~[\da-z]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[a-z]\w*)?)/i, | ||
'identifier': /[a-z_](?:-?[a-z]|\d)*/i, | ||
'operator': [ | ||
// Spaced . | ||
{ | ||
pattern: /( )\.(?= )/, | ||
lookbehind: true | ||
}, | ||
// Full list, in order: | ||
// .= .~ .. ... | ||
// .&. .^. .<<. .>>. .>>>. | ||
// := :: ::= | ||
// && | ||
// || |> | ||
// < << <<< <<<< | ||
// <- <-- <-! <--! | ||
// <~ <~~ <~! <~~! | ||
// <| <= <? | ||
// > >> >= >? | ||
// - -- -> --> | ||
// + ++ | ||
// @ @@ | ||
// % %% | ||
// * ** | ||
// ! != !~= | ||
// !~> !~~> | ||
// !-> !--> | ||
// ~ ~> ~~> ~= | ||
// = == | ||
// ^ ^^ | ||
// / ? | ||
/\.(?:[=~]|\.\.?)|\.(?:[&|^]|<<|>>>?)\.|:(?:=|:=?)|&&|\|[|>]|<(?:<<?<?|--?!?|~~?!?|[|=?])?|>[>=?]?|-(?:->?|>)?|\+\+?|@@?|%%?|\*\*?|!(?:~?=|--?>|~?~>)?|~(?:~?>|=)?|==?|\^\^?|[\/?]/ | ||
], | ||
'punctuation': /[(){}\[\]|.,:;`]/ | ||
}; | ||
|
||
Prism.languages.livescript['interpolated-string'].inside['interpolation'].inside.rest = Prism.languages.livescript; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<h1>LiveScript</h1> | ||
<p>To use this language, use the class "language-livescript".</p> | ||
|
||
<h2>Comments</h2> | ||
<pre><code># This is a single line comment | ||
/* This is a | ||
multi line comment */</code></pre> | ||
|
||
<h2>Numbers</h2> | ||
<pre><code>42 | ||
42km | ||
3.754km_2 | ||
16~BadFace | ||
36~azertyuiop0123456789</code></pre> | ||
|
||
<h2>Strings and interpolation</h2> | ||
<pre><code>'' | ||
'''''' | ||
"" | ||
"""""" | ||
'Foo \' bar | ||
baz' | ||
'''Foo \''' bar | ||
bar''' | ||
"Foo #bar \" | ||
#{2 + 2}\"" | ||
"""#foobar \""" #{ if /test/ == 'test' then 3 else 4} | ||
baz"""</code></pre> | ||
|
||
<h2>Regex</h2> | ||
<pre><code>/foobar/ig | ||
// | ||
^foo # foo | ||
[bar]*bA?z # barbaz | ||
//m</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code># example from Str.ls | ||
|
||
split = (sep, str) --> | ||
str.split sep | ||
|
||
join = (sep, xs) --> | ||
xs.join sep | ||
|
||
lines = (str) -> | ||
return [] unless str.length | ||
str.split '\n' | ||
|
||
unlines = (.join '\n') | ||
|
||
words = (str) -> | ||
return [] unless str.length | ||
str.split /[ ]+/ | ||
|
||
unwords = (.join ' ') | ||
|
||
chars = (.split '') | ||
|
||
unchars = (.join '') | ||
|
||
reverse = (str) -> | ||
str.split '' .reverse!.join '' | ||
|
||
repeat = (n, str) --> | ||
result = '' | ||
for til n | ||
result += str | ||
result | ||
|
||
capitalize = (str) -> | ||
(str.char-at 0).to-upper-case! + str.slice 1 | ||
|
||
camelize = (.replace /[-_]+(.)?/g, (, c) -> (c ? '').to-upper-case!) | ||
|
||
# convert camelCase to camel-case, and setJSON to set-JSON | ||
dasherize = (str) -> | ||
str | ||
.replace /([^-A-Z])([A-Z]+)/g, (, lower, upper) -> | ||
"#{lower}-#{if upper.length > 1 then upper else upper.to-lower-case!}" | ||
.replace /^([A-Z]+)/, (, upper) -> | ||
if upper.length > 1 then "#upper-" else upper.to-lower-case! | ||
|
||
module.exports = { | ||
split, join, lines, unlines, words, unwords, chars, unchars, reverse, | ||
repeat, capitalize, camelize, dasherize, | ||
}</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.