- update to r223 of google-code-prettify (issue 165: hashes after curly brackets should not be treated as a line comment in bash/perl)
diff --git a/src/prettify/parser/Prettify.java b/src/prettify/parser/Prettify.java index 2f0a093..0acb9b7 100644 --- a/src/prettify/parser/Prettify.java +++ b/src/prettify/parser/Prettify.java
@@ -618,7 +618,7 @@ } else { // Stop C preprocessor declarations at an unclosed open comment shortcutStylePatterns.add(Arrays.asList(new Object[]{PR_COMMENT, - Pattern.compile("^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\\b|[^\r\n]*)"), + Pattern.compile("^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\\b|[^\r\n]*)"), null, "#"})); } @@ -710,8 +710,45 @@ fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_PLAIN, Pattern.compile("^\\\\[\\s\\S]?"), null})); + + // The Bash man page says + + // A word is a sequence of characters considered as a single + // unit by GRUB. Words are separated by metacharacters, + // which are the following plus space, tab, and newline: { } + // | & $ ; < > + // ... + + // A word beginning with # causes that word and all remaining + // characters on that line to be ignored. + + // which means that only a '#' after /(?:^|[{}|&$;<>\s])/ starts a + // comment but empirically + // $ echo {#} + // {#} + // $ echo \$# + // $# + // $ echo }# + // }# + + // so /(?:^|[|&;<>\s])/ is more appropriate. + + // http://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC3 + // suggests that this definition is compatible with a + // default mode that tries to use a single token definition + // to recognize both bash/python style comments and C + // preprocessor directives. + + // This definition of punctuation does not include # in the list of + // follow-on exclusions, so # will not be broken before if preceeded + // by a punctuation character. We could try to exclude # after + // [|&;<>] but that doesn't seem to cause many major problems. + // If that does turn out to be a problem, we should change the below + // when hc is truthy to include # in the run of punctuation characters + // only when not followint [|&;<>]. + final String punctation = "^.[^\\s\\w\\.$@\\'\\\"\\`\\/\\\\]*"; fallthroughStylePatterns.add(Arrays.asList(new Object[]{PR_PUNCTUATION, - Pattern.compile("^.[^\\s\\w\\.$@\\'\\\"\\`\\/\\#\\\\]*"), + Pattern.compile(punctation), null})); return new CreateSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns);
diff --git a/test/prettify/PrettifyTest.java b/test/prettify/PrettifyTest.java index a1f7562..77dddcd 100644 --- a/test/prettify/PrettifyTest.java +++ b/test/prettify/PrettifyTest.java
@@ -121,6 +121,7 @@ test("js", "issue12_lang", false); test(null, "issue14a", false); test(null, "issue14b", false); + test("sh", "issue165", false); test(null, "issue20", false); test("c", "issue201", false); test(null, "issue21", false);
diff --git a/test/prettify/PrettifyTest/result/issue165.txt b/test/prettify/PrettifyTest/result/issue165.txt new file mode 100644 index 0000000..fe6b2b8 --- /dev/null +++ b/test/prettify/PrettifyTest/result/issue165.txt
@@ -0,0 +1,3 @@ +`COM# Comment`END`PLN +`END`KWDlocal`END`PLN $x `END`PUN=`END`PLN $`END`PUN{#`END`PLNx`END`PUN[@]}`END`PLN `END`COM# Previous is not a comment`END`PLN +`END`COM# A comment`END
diff --git a/test/prettify/PrettifyTest/source/issue165.txt b/test/prettify/PrettifyTest/source/issue165.txt new file mode 100644 index 0000000..324f751 --- /dev/null +++ b/test/prettify/PrettifyTest/source/issue165.txt
@@ -0,0 +1,3 @@ +# Comment +local $x = ${#x[@]} # Previous is not a comment +# A comment \ No newline at end of file