MCPcopy Create free account
hub / github.com/Koihik/LuaFormatter / commentAfter

Method commentAfter

src/FormatVisitor.cpp:93–126  ·  view source on GitHub ↗

commentAfter returns comments between a ParseTreeNode and the next Node. expect: return expect string if no comments found

Source from the content-addressed store, hash-verified

91// commentAfter returns comments between a ParseTreeNode and the next Node.
92// expect: return expect string if no comments found
93std::string FormatVisitor::commentAfter(tree::ParseTree* node, const std::string& expect) {
94 int l = lastNodeIndex(node);
95 std::stringstream ss;
96 // No space on left of first comment
97 bool lastComment = node != nullptr;
98 for (unsigned int i = l + 1; i < tokens_.size(); i++) {
99 auto* token = tokens_[i];
100 if (token->getType() == LuaLexer::COMMENT) {
101 if (lastComment) {
102 ss << " ";
103 }
104 ss << token->getText();
105 lastComment = true;
106 } else if (token->getType() == LuaLexer::LINE_COMMENT) {
107 if (lastComment) {
108 ss << " ";
109 }
110 ss << formatLineComment(token);
111 ss << indent();
112 lastComment = false;
113 } else if (token->getType() == LuaLexer::SHEBANG) {
114 ss << token->getText() << "\n\n";
115 } else if (token->getType() == LuaLexer::WS) {
116 } else {
117 break;
118 }
119 }
120 if (ss.tellp() == 0) {
121 ss << expect;
122 } else if (lastComment) {
123 ss << " ";
124 }
125 return ss.str();
126}
127
128// commentAfterNewLine returns comments between a ParseTreeNode and the next Node.
129// This function always expect a line break.

Callers

nothing calls this directly

Calls 2

lastNodeIndexFunction · 0.85
strMethod · 0.80

Tested by

no test coverage detected