diff --git a/components/prism-c.js b/components/prism-c.js index f65e54fd1d..de4e13f145 100644 --- a/components/prism-c.js +++ b/components/prism-c.js @@ -1,7 +1,7 @@ Prism.languages.c = Prism.languages.extend('clike', { 'keyword': /\b(asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/, 'operator': /\-[>-]?|\+\+?|!=?|<>?=?|==?|&&?|\|?\||[~^%?*\/]/, - 'number': /\b-?(0x[\da-f]+|\d*\.?\d+(e[+-]?\d+)?)[fFuUlL]*\b/i + 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i }); Prism.languages.insertBefore('c', 'string', { diff --git a/components/prism-c.min.js b/components/prism-c.min.js index b621206cb3..4392c5cfbc 100644 --- a/components/prism-c.min.js +++ b/components/prism-c.min.js @@ -1 +1 @@ -Prism.languages.c=Prism.languages.extend("clike",{keyword:/\b(asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,operator:/\-[>-]?|\+\+?|!=?|<>?=?|==?|&&?|\|?\||[~^%?*\/]/,number:/\b-?(0x[\da-f]+|\d*\.?\d+(e[+-]?\d+)?)[fFuUlL]*\b/i}),Prism.languages.insertBefore("c","string",{macro:{pattern:/(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,lookbehind:!0,alias:"property",inside:{string:{pattern:/(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,lookbehind:!0}}}}),delete Prism.languages.c["class-name"],delete Prism.languages.c["boolean"]; \ No newline at end of file +Prism.languages.c=Prism.languages.extend("clike",{keyword:/\b(asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,operator:/\-[>-]?|\+\+?|!=?|<>?=?|==?|&&?|\|?\||[~^%?*\/]/,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)[ful]*\b/i}),Prism.languages.insertBefore("c","string",{macro:{pattern:/(^\s*)#\s*[a-z]+([^\r\n\\]|\\.|\\(?:\r\n?|\n))*/im,lookbehind:!0,alias:"property",inside:{string:{pattern:/(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,lookbehind:!0}}}}),delete Prism.languages.c["class-name"],delete Prism.languages.c["boolean"]; \ No newline at end of file diff --git a/components/prism-clike.js b/components/prism-clike.js index 052089e3d5..5745341f7d 100644 --- a/components/prism-clike.js +++ b/components/prism-clike.js @@ -20,7 +20,7 @@ Prism.languages.clike = { 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/, 'boolean': /\b(true|false)\b/, 'function': /[a-z0-9_]+(?=\()/i, - 'number': /\b-?(0x[\da-f]+|\d*\.?\d+(e[+-]?\d+)?)\b/i, + 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i, 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/, 'punctuation': /[{}[\];(),.:]/ }; diff --git a/components/prism-clike.min.js b/components/prism-clike.min.js index 828c6e7694..b437bab33b 100644 --- a/components/prism-clike.min.js +++ b/components/prism-clike.min.js @@ -1 +1 @@ -Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:/("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,"class-name":{pattern:/((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,"boolean":/\b(true|false)\b/,"function":/[a-z0-9_]+(?=\()/i,number:/\b-?(0x[\da-f]+|\d*\.?\d+(e[+-]?\d+)?)\b/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,punctuation:/[{}[\];(),.:]/}; \ No newline at end of file +Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:/("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,"class-name":{pattern:/((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,"boolean":/\b(true|false)\b/,"function":/[a-z0-9_]+(?=\()/i,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,punctuation:/[{}[\];(),.:]/}; \ No newline at end of file diff --git a/prism.js b/prism.js index b2e3c47a8d..c5b3de6177 100644 --- a/prism.js +++ b/prism.js @@ -574,7 +574,7 @@ Prism.languages.clike = { 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/, 'boolean': /\b(true|false)\b/, 'function': /[a-z0-9_]+(?=\()/i, - 'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/, + 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i, 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/, 'punctuation': /[{}[\];(),.:]/ }; diff --git a/tests/languages/c/number_feature.test b/tests/languages/c/number_feature.test index e69de29bb2..0542683404 100644 --- a/tests/languages/c/number_feature.test +++ b/tests/languages/c/number_feature.test @@ -0,0 +1,35 @@ +42 +3.14159 +4e10 +2.1e-10 +0.4e+2 +0xbabe +0xBABE +42f +42F +42u +42U +42l +42L + +---------------------------------------------------- + +[ + ["number", "42"], + ["number", "3.14159"], + ["number", "4e10"], + ["number", "2.1e-10"], + ["number", "0.4e+2"], + ["number", "0xbabe"], + ["number", "0xBABE"], + ["number", "42f"], + ["number", "42F"], + ["number", "42u"], + ["number", "42U"], + ["number", "42l"], + ["number", "42L"] +] + +---------------------------------------------------- + +Checks for decimal numbers and hexadecimal numbers. \ No newline at end of file diff --git a/tests/languages/clike/number_feature.test b/tests/languages/clike/number_feature.test index 002a5c92c2..f6bcc0b662 100644 --- a/tests/languages/clike/number_feature.test +++ b/tests/languages/clike/number_feature.test @@ -2,6 +2,7 @@ 3.14159 4e10 2.1e-10 +0.4e+2 0xbabe 0xBABE @@ -12,6 +13,7 @@ ["number", "3.14159"], ["number", "4e10"], ["number", "2.1e-10"], + ["number", "0.4e+2"], ["number", "0xbabe"], ["number", "0xBABE"] ]