MCPcopy Index your code
hub / github.com/socketstream/socketstream / sourceDecorator

Function sourceDecorator

docs/js/google-code-prettify.js:799–948  ·  view source on GitHub ↗

returns a function that produces a list of decorations from source text. * * This code treats ", ', and ` as string delimiters, and \ as a string * escape. It does not recognize perl's qq() style strings. * It has no special handling for double delimiter escapes as in basic, or

(options)

Source from the content-addressed store, hash-verified

797 * in the input job and builds the decoration list.
798 */
799 function sourceDecorator(options) {
800 var shortcutStylePatterns = [], fallthroughStylePatterns = [];
801 if (options['tripleQuotedStrings']) {
802 // '''multi-line-string''', 'single-line-string', and double-quoted
803 shortcutStylePatterns.push(
804 [PR_STRING, /^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,
805 null, '\'"']);
806 } else if (options['multiLineStrings']) {
807 // 'multi-line-string', "multi-line-string"
808 shortcutStylePatterns.push(
809 [PR_STRING, /^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,
810 null, '\'"`']);
811 } else {
812 // 'single-line-string', "single-line-string"
813 shortcutStylePatterns.push(
814 [PR_STRING,
815 /^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,
816 null, '"\'']);
817 }
818 if (options['verbatimStrings']) {
819 // verbatim-string-literal production from the C# grammar. See issue 93.
820 fallthroughStylePatterns.push(
821 [PR_STRING, /^@\"(?:[^\"]|\"\")*(?:\"|$)/, null]);
822 }
823 var hc = options['hashComments'];
824 if (hc) {
825 if (options['cStyleComments']) {
826 if (hc > 1) { // multiline hash comments
827 shortcutStylePatterns.push(
828 [PR_COMMENT, /^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/, null, '#']);
829 } else {
830 // Stop C preprocessor declarations at an unclosed open comment
831 shortcutStylePatterns.push(
832 [PR_COMMENT, /^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\r\n]*)/,
833 null, '#']);
834 }
835 // #include <stdio.h>
836 fallthroughStylePatterns.push(
837 [PR_STRING,
838 /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,
839 null]);
840 } else {
841 shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']);
842 }
843 }
844 if (options['cStyleComments']) {
845 fallthroughStylePatterns.push([PR_COMMENT, /^\/\/[^\r\n]*/, null]);
846 fallthroughStylePatterns.push(
847 [PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null]);
848 }
849 if (options['regexLiterals']) {
850 /**
851 * @const
852 */
853 var REGEX_LITERAL = (
854 // A regular expression literal starts with a slash that is
855 // not followed by * or / so that it is not confused with
856 // comments.

Callers 1

Calls 1

createSimpleLexerFunction · 0.85

Tested by

no test coverage detected