139 {
141
144
146 std::string_view lastTokenText = " ";
147 int lineWidth = 1;
148 for (;;) {
149 token = lexer.
next();
150 if (token.
fKind == TokenKind::TK_END_OF_FILE) {
151 break;
152 }
153 if (token.
fKind == TokenKind::TK_LINE_COMMENT ||
154 token.
fKind == TokenKind::TK_BLOCK_COMMENT ||
155 token.
fKind == TokenKind::TK_WHITESPACE) {
156 continue;
157 }
159 if (token.
fKind == TokenKind::TK_INVALID) {
160 printf(
"%.*s: unable to parse '%.*s' at offset %d\n",
161 (int)inputPath.size(), inputPath.data(),
162 (int)thisTokenText.size(), thisTokenText.data(),
164 return false;
165 }
166 if (thisTokenText.empty()) {
167 continue;
168 }
169 if (token.
fKind == TokenKind::TK_FLOAT_LITERAL) {
170
172 while (thisTokenText.back() == '0' && thisTokenText.size() >= 3) {
173 thisTokenText.remove_suffix(1);
174 }
175 }
176
178 thisTokenText.remove_prefix(1);
179 }
180 }
183
184 out.writeText(
"\"\n\"");
185 lineWidth = 1;
186 }
187
188
189 bool adjacentIdentifiers =
191
192
193
194 bool adjacentPlusOrMinus =
196
197
198 if (adjacentIdentifiers || adjacentPlusOrMinus) {
200 lineWidth++;
201 }
202 out.write(thisTokenText.data(), thisTokenText.size());
203 lineWidth += thisTokenText.size();
204 lastTokenText = thisTokenText;
205 }
206
207 return true;
208}
static std::string_view stringize(const SkSL::Token &token, std::string_view text)
static bool maybe_identifier(char c)
static bool is_plus_or_minus(char c)
void start(std::string_view text)
constexpr bool starts_with(std::string_view str, std::string_view prefix)
constexpr bool contains(std::string_view str, std::string_view needle)