Skip to content

Commit

Permalink
[Java.Interop.Tools.JavaSource] Parse <code/> tags (#1044)
Browse files Browse the repository at this point in the history
Fixes: #1041

Translates Javadoc `<code/>` tags into C# `<c/>` tags, which should
clean up thousands of illegible `&lt;code&gt;foo&lt;/code&gt;`
occurrences.
  • Loading branch information
pjcollins authored Sep 28, 2022
1 parent a0728ed commit 07c95e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
| FormCtrlDeclaration
*/
| InlineHyperLinkDeclaration
| CodeElementDeclaration
| grammar.InlineTagsTerms.AllInlineTerms
| UnknownHtmlElementStart
,
Expand Down Expand Up @@ -136,6 +137,12 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
var aElementValue = new XText (parseNode.ChildNodes [1].AstNode.ToString ());
parseNode.AstNode = aElementValue;
};

CodeElementDeclaration.Rule = CreateStartElement ("code", grammar) + InlineDeclarations + CreateEndElement ("code", grammar);
CodeElementDeclaration.AstConfig.NodeCreator = (context, parseNode) => {
var target = parseNode.ChildNodes [1].AstNode;
parseNode.AstNode = new XElement ("c", target);
};
}

static IEnumerable<XElement> GetParagraphs (ParseTreeNodeList children)
Expand Down Expand Up @@ -205,6 +212,7 @@ static IEnumerable<XElement> GetParagraphs (ParseTreeNodeList children)
public readonly NonTerminal PreBlockDeclaration = new NonTerminal (nameof (PreBlockDeclaration), ConcatChildNodes);
public readonly NonTerminal InlineHyperLinkDeclaration = new NonTerminal (nameof (InlineHyperLinkDeclaration), ConcatChildNodes);
public readonly NonTerminal IgnorableElementDeclaration = new NonTerminal (nameof (IgnorableElementDeclaration), ConcatChildNodes);
public readonly NonTerminal CodeElementDeclaration = new NonTerminal (nameof (CodeElementDeclaration), ConcatChildNodes);

public readonly Terminal InlineHyperLinkOpenTerm = new RegexBasedTerminal ("<a href=", @"(?i)<a\s*href\s*=") {
AstConfig = new AstNodeConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,16 @@ public void HyperLinkDeclaration ()
Assert.AreEqual ("\"AutofillService.html#FieldClassification\"&gt;field classification",
r.Root.AstNode.ToString ());
}

[Test]
public void CodeElementDeclaration ()
{
var p = CreateParser (g => g.HtmlTerms.CodeElementDeclaration);

var r = p.Parse ("<code>input.position()</code>");
Assert.IsFalse (r.HasErrors (), DumpMessages (r, p));
Assert.AreEqual ("<c>input.position()</c>", r.Root.AstNode.ToString ());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ more description here.</para>
new ParseResult {
Javadoc = "Something {@link #method}: description, \"<code>declaration</code>\" or \"<code>another declaration</code>\".\n\n@apiSince 1\n",
FullXml = @"<member>
<summary>Something <c>#method</c>: description, ""&lt;code&gt;declaration&lt;/code&gt;"" or ""&lt;code&gt;another declaration&lt;/code&gt;"".</summary>
<summary>Something <c>#method</c>: description, ""<c>declaration</c>"" or ""<c>another declaration</c>"".</summary>
<remarks>
<para>Something <c>#method</c>: description, ""&lt;code&gt;declaration&lt;/code&gt;"" or ""&lt;code&gt;another declaration&lt;/code&gt;"".</para>
<para>Something <c>#method</c>: description, ""<c>declaration</c>"" or ""<c>another declaration</c>"".</para>
<para>Added in API level 1.</para>
</remarks>
</member>",
IntelliSenseXml = @"<member>
<summary>Something <c>#method</c>: description, ""&lt;code&gt;declaration&lt;/code&gt;"" or ""&lt;code&gt;another declaration&lt;/code&gt;"".</summary>
<summary>Something <c>#method</c>: description, ""<c>declaration</c>"" or ""<c>another declaration</c>"".</summary>
</member>",
},
new ParseResult {
Expand Down

0 comments on commit 07c95e9

Please # to comment.