From fa286aa57f04c2e88370b9b717e5ea6d35c70334 Mon Sep 17 00:00:00 2001 From: Golmote Date: Fri, 17 Jul 2015 08:39:15 +0200 Subject: [PATCH] Erlang: Fixed quoted functions and quoted atoms. Fixed variables pattern so that it does not break atoms. Fixed operator <=. --- components/prism-erlang.js | 18 ++++++++++++------ components/prism-erlang.min.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/prism-erlang.js b/components/prism-erlang.js index deea6aa054..5baa9d77a4 100644 --- a/components/prism-erlang.js +++ b/components/prism-erlang.js @@ -2,11 +2,11 @@ Prism.languages.erlang = { 'comment': /%.+/, 'string': /"(?:\\?.)*?"/, 'quoted-function': { - pattern: /'[^']+'(?=\()/, + pattern: /'(?:\\.|[^'\\])+'(?=\()/, alias: 'function' }, 'quoted-atom': { - pattern: /'[^']+'/, + pattern: /'(?:\\.|[^'\\])+'/, alias: 'atom' }, 'boolean': /\b(?:true|false)\b/, @@ -17,15 +17,21 @@ Prism.languages.erlang = { /(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/ ], 'function': /\b[a-z][\w@]*(?=\()/, - 'variable': /(?:\b|\?)[A-Z_][\w@]*/, + 'variable': { + // Look-behind is used to prevent wrong highlighting of atoms containing "@" + pattern: /(^|[^@])(?:\b|\?)[A-Z_][\w@]*/, + lookbehind: true + }, 'operator': [ - /[=\/>:]=|>=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/, + /[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/, { - pattern: /(^|(?!<).)<(?!<)/, + // We don't want to match << + pattern: /(^|[^<])<(?!<)/, lookbehind: true }, { - pattern: /(^|(?!>).)>(?!>)/, + // We don't want to match >> + pattern: /(^|[^>])>(?!>)/, lookbehind: true } ], diff --git a/components/prism-erlang.min.js b/components/prism-erlang.min.js index 6a072b6296..613f0f955c 100644 --- a/components/prism-erlang.min.js +++ b/components/prism-erlang.min.js @@ -1 +1 @@ -Prism.languages.erlang={comment:/%.+/,string:/"(?:\\?.)*?"/,"quoted-function":{pattern:/'[^']+'(?=\()/,alias:"function"},"quoted-atom":{pattern:/'[^']+'/,alias:"atom"},"boolean":/\b(?:true|false)\b/,keyword:/\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,number:[/\$\\?./,/\d+#[a-z0-9]+/i,/(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/],"function":/\b[a-z][\w@]*(?=\()/,variable:/(?:\b|\?)[A-Z_][\w@]*/,operator:[/[=\/>:]=|>=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,{pattern:/(^|(?!<).)<(?!<)/,lookbehind:!0},{pattern:/(^|(?!>).)>(?!>)/,lookbehind:!0}],atom:/\b[a-z][\w@]*/,punctuation:/[()[\]{}:;,.#|]|<<|>>/}; \ No newline at end of file +Prism.languages.erlang={comment:/%.+/,string:/"(?:\\?.)*?"/,"quoted-function":{pattern:/'(?:\\.|[^'\\])+'(?=\()/,alias:"function"},"quoted-atom":{pattern:/'(?:\\.|[^'\\])+'/,alias:"atom"},"boolean":/\b(?:true|false)\b/,keyword:/\b(?:fun|when|case|of|end|if|receive|after|try|catch)\b/,number:[/\$\\?./,/\d+#[a-z0-9]+/i,/(?:\b|-)\d*\.?\d+([Ee][+-]?\d+)?\b/],"function":/\b[a-z][\w@]*(?=\()/,variable:{pattern:/(^|[^@])(?:\b|\?)[A-Z_][\w@]*/,lookbehind:!0},operator:[/[=\/<>:]=|=[:\/]=|\+\+?|--?|[=*\/!]|\b(?:bnot|div|rem|band|bor|bxor|bsl|bsr|not|and|or|xor|orelse|andalso)\b/,{pattern:/(^|[^<])<(?!<)/,lookbehind:!0},{pattern:/(^|[^>])>(?!>)/,lookbehind:!0}],atom:/\b[a-z][\w@]*/,punctuation:/[()[\]{}:;,.#|]|<<|>>/}; \ No newline at end of file