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