MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / scan_jsx_text

Function scan_jsx_text

tools/tree-sitter-javascript/src/scanner.c:292–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292static bool scan_jsx_text(TSLexer *lexer) {
293 // saw_text will be true if we see any non-whitespace content, or any whitespace content that is not a newline and
294 // does not immediately follow a newline.
295 bool saw_text = false;
296 // at_newline will be true if we are currently at a newline, or if we are at whitespace that is not a newline but
297 // immediately follows a newline.
298 bool at_newline = false;
299
300 while (lexer->lookahead != 0 && lexer->lookahead != '<' && lexer->lookahead != '>' && lexer->lookahead != '{' &&
301 lexer->lookahead != '}' && lexer->lookahead != '&') {
302 bool is_wspace = iswspace(lexer->lookahead);
303 if (lexer->lookahead == '\n') {
304 at_newline = true;
305 } else {
306 // If at_newline is already true, and we see some whitespace, then it must stay true.
307 // Otherwise, it should be false.
308 //
309 // See the table below to determine the logic for computing `saw_text`.
310 //
311 // |------------------------------------|
312 // | at_newline | is_wspace | saw_text |
313 // |------------|-----------|-----------|
314 // | false (0) | false (0) | true (1) |
315 // | false (0) | true (1) | true (1) |
316 // | true (1) | false (0) | true (1) |
317 // | true (1) | true (1) | false (0) |
318 // |------------------------------------|
319
320 at_newline &= is_wspace;
321 if (!at_newline) {
322 saw_text = true;
323 }
324 }
325
326 advance(lexer);
327 }
328
329 lexer->result_symbol = JSX_TEXT;
330 return saw_text;
331}
332
333bool tree_sitter_javascript_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
334 if (valid_symbols[TEMPLATE_CHARS]) {

Calls 1

advanceFunction · 0.70

Tested by

no test coverage detected