[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | module.exports = livescript
|
---|
| 4 | livescript.displayName = 'livescript'
|
---|
| 5 | livescript.aliases = []
|
---|
| 6 | function livescript(Prism) {
|
---|
| 7 | Prism.languages.livescript = {
|
---|
| 8 | comment: [
|
---|
| 9 | {
|
---|
| 10 | pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
|
---|
| 11 | lookbehind: true
|
---|
| 12 | },
|
---|
| 13 | {
|
---|
| 14 | pattern: /(^|[^\\])#.*/,
|
---|
| 15 | lookbehind: true
|
---|
| 16 | }
|
---|
| 17 | ],
|
---|
| 18 | 'interpolated-string': {
|
---|
| 19 | /* Look-behind and look-ahead prevents wrong behavior of the greedy pattern
|
---|
| 20 | * forcing it to match """-quoted string when it would otherwise match "-quoted first. */
|
---|
| 21 | pattern: /(^|[^"])("""|")(?:\\[\s\S]|(?!\2)[^\\])*\2(?!")/,
|
---|
| 22 | lookbehind: true,
|
---|
| 23 | greedy: true,
|
---|
| 24 | inside: {
|
---|
| 25 | variable: {
|
---|
| 26 | pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|[\d_])*/m,
|
---|
| 27 | lookbehind: true
|
---|
| 28 | },
|
---|
| 29 | interpolation: {
|
---|
| 30 | pattern: /(^|[^\\])#\{[^}]+\}/m,
|
---|
| 31 | lookbehind: true,
|
---|
| 32 | inside: {
|
---|
| 33 | 'interpolation-punctuation': {
|
---|
| 34 | pattern: /^#\{|\}$/,
|
---|
| 35 | alias: 'variable'
|
---|
| 36 | } // See rest below
|
---|
| 37 | }
|
---|
| 38 | },
|
---|
| 39 | string: /[\s\S]+/
|
---|
| 40 | }
|
---|
| 41 | },
|
---|
| 42 | string: [
|
---|
| 43 | {
|
---|
| 44 | pattern: /('''|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
|
---|
| 45 | greedy: true
|
---|
| 46 | },
|
---|
| 47 | {
|
---|
| 48 | pattern: /<\[[\s\S]*?\]>/,
|
---|
| 49 | greedy: true
|
---|
| 50 | },
|
---|
| 51 | /\\[^\s,;\])}]+/
|
---|
| 52 | ],
|
---|
| 53 | regex: [
|
---|
| 54 | {
|
---|
| 55 | pattern: /\/\/(?:\[[^\r\n\]]*\]|\\.|(?!\/\/)[^\\\[])+\/\/[gimyu]{0,5}/,
|
---|
| 56 | greedy: true,
|
---|
| 57 | inside: {
|
---|
| 58 | comment: {
|
---|
| 59 | pattern: /(^|[^\\])#.*/,
|
---|
| 60 | lookbehind: true
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | },
|
---|
| 64 | {
|
---|
| 65 | pattern: /\/(?:\[[^\r\n\]]*\]|\\.|[^/\\\r\n\[])+\/[gimyu]{0,5}/,
|
---|
| 66 | greedy: true
|
---|
| 67 | }
|
---|
| 68 | ],
|
---|
| 69 | keyword: {
|
---|
| 70 | pattern:
|
---|
| 71 | /(^|(?!-).)\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,
|
---|
| 72 | lookbehind: true
|
---|
| 73 | },
|
---|
| 74 | 'keyword-operator': {
|
---|
| 75 | pattern:
|
---|
| 76 | /(^|[^-])\b(?:(?:delete|require|typeof)!|(?:and|by|delete|export|from|import(?: all)?|in|instanceof|is(?: not|nt)?|not|of|or|til|to|typeof|with|xor)(?!-)\b)/m,
|
---|
| 77 | lookbehind: true,
|
---|
| 78 | alias: 'operator'
|
---|
| 79 | },
|
---|
| 80 | boolean: {
|
---|
| 81 | pattern: /(^|[^-])\b(?:false|no|off|on|true|yes)(?!-)\b/m,
|
---|
| 82 | lookbehind: true
|
---|
| 83 | },
|
---|
| 84 | argument: {
|
---|
| 85 | // Don't match .&. nor &&
|
---|
| 86 | pattern: /(^|(?!\.&\.)[^&])&(?!&)\d*/m,
|
---|
| 87 | lookbehind: true,
|
---|
| 88 | alias: 'variable'
|
---|
| 89 | },
|
---|
| 90 | number: /\b(?:\d+~[\da-z]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[a-z]\w*)?)/i,
|
---|
| 91 | identifier: /[a-z_](?:-?[a-z]|[\d_])*/i,
|
---|
| 92 | operator: [
|
---|
| 93 | // Spaced .
|
---|
| 94 | {
|
---|
| 95 | pattern: /( )\.(?= )/,
|
---|
| 96 | lookbehind: true
|
---|
| 97 | }, // Full list, in order:
|
---|
| 98 | // .= .~ .. ...
|
---|
| 99 | // .&. .^. .<<. .>>. .>>>.
|
---|
| 100 | // := :: ::=
|
---|
| 101 | // &&
|
---|
| 102 | // || |>
|
---|
| 103 | // < << <<< <<<<
|
---|
| 104 | // <- <-- <-! <--!
|
---|
| 105 | // <~ <~~ <~! <~~!
|
---|
| 106 | // <| <= <?
|
---|
| 107 | // > >> >= >?
|
---|
| 108 | // - -- -> -->
|
---|
| 109 | // + ++
|
---|
| 110 | // @ @@
|
---|
| 111 | // % %%
|
---|
| 112 | // * **
|
---|
| 113 | // ! != !~=
|
---|
| 114 | // !~> !~~>
|
---|
| 115 | // !-> !-->
|
---|
| 116 | // ~ ~> ~~> ~=
|
---|
| 117 | // = ==
|
---|
| 118 | // ^ ^^
|
---|
| 119 | // / ?
|
---|
| 120 | /\.(?:[=~]|\.\.?)|\.(?:[&|^]|<<|>>>?)\.|:(?:=|:=?)|&&|\|[|>]|<(?:<<?<?|--?!?|~~?!?|[|=?])?|>[>=?]?|-(?:->?|>)?|\+\+?|@@?|%%?|\*\*?|!(?:~?=|--?>|~?~>)?|~(?:~?>|=)?|==?|\^\^?|[\/?]/
|
---|
| 121 | ],
|
---|
| 122 | punctuation: /[(){}\[\]|.,:;`]/
|
---|
| 123 | }
|
---|
| 124 | Prism.languages.livescript['interpolated-string'].inside[
|
---|
| 125 | 'interpolation'
|
---|
| 126 | ].inside.rest = Prism.languages.livescript
|
---|
| 127 | }
|
---|