Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScaladocParser: add EnclosedJavaTag as a text part #3342

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ object ScaladocParser {

private def textParser[_: P](indent: Int, mdOffset: Int = 0): P[Text] = P {
def end = P(nl ~/ nextPartParser(indent, mdOffset))
def part: P[TextPart] = P(codeExprParser | linkParser | wordParser)
def part: P[TextPart] = P(codeExprParser | linkParser | enclosedJavaTagParser | wordParser)
def sep = P(!end ~ nl.? ~ hspaces0)
hspaces0 ~ part.rep(1, sep = sep).map(x => Text(x))
}
Expand All @@ -153,6 +153,15 @@ object ScaladocParser {
}
}

private def enclosedJavaTagParser[_: P]: P[EnclosedJavaTag] = P {
def enclosed = (!(space | "}") ~ AnyChar).rep(1)
def ltBrace = "{" ~ hspaces0
def rtBrace = hspaces0 ~ "}"
def tag = ("@" ~ enclosed).!
def desc = (hspaces1 ~ enclosed.!).rep
(ltBrace ~ tag ~ desc ~ rtBrace).map { case (tag, desc) => EnclosedJavaTag(tag, desc) }
}

private def listBlockParser[_: P](indent: Int = 0): P[ListBlock] = P {
/* https://docs.scala-lang.org/overviews/scaladoc/for-library-authors.html#other-formatting-notes
* For list blocks, "you must have extra space in front", hence min `indent + 1`. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ object Scaladoc {
override def syntax: String = s"{{{$code}}}$punct"
}

/** Represents an enclosed tagged documentation remark */
final case class EnclosedJavaTag(tag: String, desc: Seq[String] = Nil) extends TextPart {
override def syntax: String = desc.mkString(s"{@$tag", " ", "}")
}

/** A block of one or more lines of code */
final case class CodeBlock(code: Seq[String]) extends Term

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,36 @@ class ScaladocParserSuite extends FunSuite {
assertEquals(result, expectation)
}

test("enclosed java tag") {
assertEquals(
parseString(
"""
/**
* {@tag1}
* {@tag2 with desc}
* {@not a
* tag}
*/
"""
),
Option(
Scaladoc(
Paragraph(
Text(
Seq(
EnclosedJavaTag("@tag1"),
EnclosedJavaTag("@tag2", List("with", "desc")),
Word("{@not"),
Word("a"),
Word("tag}")
)
) :: Nil
) :: Nil
)
)
)
}

test("table escaped pipe") {
val result = parseString(
"""
Expand Down