diff --git a/gherkin-frontend/src/main/java/org/sonar/gherkin/parser/GherkinLexicalGrammar.java b/gherkin-frontend/src/main/java/org/sonar/gherkin/parser/GherkinLexicalGrammar.java index a5d7490..6733c58 100644 --- a/gherkin-frontend/src/main/java/org/sonar/gherkin/parser/GherkinLexicalGrammar.java +++ b/gherkin-frontend/src/main/java/org/sonar/gherkin/parser/GherkinLexicalGrammar.java @@ -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("\\|.*\\|")); diff --git a/gherkin-frontend/src/test/java/org/sonar/gherkin/parser/DocStringTreeTest.java b/gherkin-frontend/src/test/java/org/sonar/gherkin/parser/DocStringTreeTest.java index e89ac45..d65fd09 100644 --- a/gherkin-frontend/src/test/java/org/sonar/gherkin/parser/DocStringTreeTest.java +++ b/gherkin-frontend/src/test/java/org/sonar/gherkin/parser/DocStringTreeTest.java @@ -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 \"\"\""); @@ -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