Skip to content

Commit

Permalink
Fix #50 Support triple backticks as DocString prefix/suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
racodond committed Dec 23, 2016
1 parent 9c321e6 commit c741ea2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ private static void syntax(LexerlessGrammarBuilder b, String language) {
+ "|@|\\|))"
+ trimmedSentence));

b.rule(DOC_STRING_PREFIX).is(SPACING, "\"\"\"");
b.rule(DOC_STRING_SUFFIX).is(SPACING_NO_COMMENTS, "\"\"\"");
b.rule(DOC_STRING_DATA_ROW).is(SPACING_NO_COMMENTS, b.regexp("^(?!\"\"\").+"));
b.rule(DOC_STRING_PREFIX).is(SPACING, b.firstOf("\"\"\"", "```"));
b.rule(DOC_STRING_SUFFIX).is(SPACING_NO_COMMENTS, b.firstOf("\"\"\"", "```"));
b.rule(DOC_STRING_DATA_ROW).is(SPACING_NO_COMMENTS, b.regexp("^(?!(\"\"\"|```)).+"));
b.rule(DOC_STRING_CONTENT_TYPE).is(b.regexp(".+"));

b.rule(TABLE_DATA_ROW).is(SPACING, b.regexp("\\|.*\\|"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void docString() throws Exception {

tree = checkParsed("\"\"\"\n\"\"\"");
assertThat(tree.contentType()).isNull();
assertThat(tree.prefix().text()).isEqualTo("\"\"\"");
assertThat(tree.suffix().text()).isEqualTo("\"\"\"");
assertThat(tree.data()).hasSize(0);

tree = checkParsed(" \"\"\"\n \"\"\"");
Expand Down Expand Up @@ -63,6 +65,18 @@ public void docString() throws Exception {
assertThat(tree.contentType()).isNotNull();
assertThat(tree.contentType().text()).isEqualTo("type");
assertThat(tree.data()).hasSize(2);

tree = checkParsed("```\n```");
assertThat(tree.contentType()).isNull();
assertThat(tree.prefix().text()).isEqualTo("```");
assertThat(tree.suffix().text()).isEqualTo("```");

tree = checkParsed("```string\nblabla...\nblabla...\n```");
assertThat(tree.contentType()).isNotNull();
assertThat(tree.contentType().text()).isEqualTo("string");
assertThat(tree.data()).hasSize(2);
assertThat(tree.prefix().text()).isEqualTo("```");
assertThat(tree.suffix().text()).isEqualTo("```");
}

@Test
Expand Down

0 comments on commit c741ea2

Please sign in to comment.