-
Notifications
You must be signed in to change notification settings - Fork 593
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
Simplify Comment Parsing Code #3399
Simplify Comment Parsing Code #3399
Conversation
@@ -648,48 +648,44 @@ namespace | |||
if (stripMarkup) | |||
{ | |||
// Strip HTML markup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to a while loop lets us avoid a redundant check for pos != string::npos
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes anything between <
and >
is an html tag.
What about something like:
a < b or x > y
, won't this strip the comment to something like a y
?
It is not a new problem, but would be nice to fix now that we are looking at this code.
We can fix in a separate PR.
} while (pos != string::npos); | ||
comment.erase(pos, endpos - pos + 1); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic was nested inside if (stripMarkup)
. This doesn't seem right to me.
XML escaping should be unrelated to markdown striping.
@@ -742,35 +738,27 @@ namespace | |||
return result; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function took a bool namedTag
parameter which was always hard-coded.
And even worse, it took a const string& name
which was only used some of the time based on the bool.
So I split it into 2 functions: parseNamedCommentLine
and parseCommentLine
. No more bool.
@@ -803,94 +807,69 @@ Slice::Contained::parseDocComment(function<string(string, string)> linkFormatter | |||
|
|||
DocCommentPtr comment = make_shared<DocComment>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the remaining code below this is where we parse the actual tags (@param
etc) into their respective fields on DocComment
. Before, we had an entire state machine, but this was overkill.
I removed all this logic, and replaced it with a StringList* currentSection
,
which points to whichever part of the doc-comment we're currently parsing.
At the beginning it points to the overview, but as we encounter tags, we re-point it appropiately.
I find this approach simpler than using a state-machine, and switching on the state to determine where we're writing to.
@@ -648,48 +648,44 @@ namespace | |||
if (stripMarkup) | |||
{ | |||
// Strip HTML markup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes anything between <
and >
is an html tag.
What about something like:
a < b or x > y
, won't this strip the comment to something like a y
?
It is not a new problem, but would be nice to fix now that we are looking at this code.
We can fix in a separate PR.
I agree, it's also a problem I noticed, but didn't want to fix in this PR. |
This PR simplifies the implementation of
parseDocComment
, which is the part oflibSlice
responsible for converting a rawstring comment
into a structuredDocComment
.It's not meant to be a perfect cleanup.
But just to simplify some things before I add the last validation logic/fix the issues related to how
@link
s are formatted.I used my compiler-comparison script to check, and the generated code is identical before and after my changes here.