Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.cbm
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ EXTRACTION_SRCS = \
$(CBM_DIR)/extract_channels.c \
$(CBM_DIR)/extract_k8s.c \
$(CBM_DIR)/extract_dbt.c \
$(CBM_DIR)/php_inline_html.c \
$(CBM_DIR)/helpers.c \
$(CBM_DIR)/result_compact.c \
$(CBM_DIR)/result_spill.c \
Expand Down
14 changes: 14 additions & 0 deletions internal/cbm/cbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,18 @@ CBMFileResult *cbm_extract_file(const char *source, int source_len, CBMLanguage
return r;
}

/* The bytes the grammar parses. PHP that leaves PHP mode (`?> markup <?php`)
* is parsed with its markup blanked (#2000); the rewrite keeps the length and
* every line break, so offsets and line numbers still refer to the file on
* disk. Every other language parses the file as it is. */
static const char *extract_parse_bytes(CBMArena *a, CBMLanguage language, const char *source,
int source_len) {
if (language == CBM_LANG_PHP) {
return cbm_php_mask_inline_html(a, source, source_len);
}
return source;
}

/* Initial block for the per-file traversal scratch arena, chosen by measuring
* arena_grow on a 14k-file TypeScript tree: it fires on one file in 12,000 at
* both this size and at 1 MB, and on most files at 256 KB, where the two
Expand Down Expand Up @@ -2122,6 +2134,8 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
return result;
}

source = extract_parse_bytes(a, language, source, source_len);

// Skip pathologically nested Perl before tree-sitter's recursive GLR stack
// merge overflows a small stack during the parse (see
// cbm_source_nesting_exceeds). Scoped to Perl: its ambiguous call grammar is
Expand Down
4 changes: 4 additions & 0 deletions internal/cbm/cbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ void cbm_extract_definitions_without_module(CBMExtractCtx *ctx);
// per ref()/source() call. No-op unless the file parses as SQL and actually
// contains a dbt builtin call. Defined in extract_dbt.c.
void cbm_extract_dbt(CBMExtractCtx *ctx);
// PHP source with its inline-HTML regions blanked so the php_only grammar can
// parse past `?>` (#2000). Same length and line breaks as the input; returns
// `source` itself when nothing needs rewriting. Defined in php_inline_html.c.
const char *cbm_php_mask_inline_html(CBMArena *arena, const char *source, int source_len);
void cbm_extract_imports(CBMExtractCtx *ctx);
void cbm_extract_usages(CBMExtractCtx *ctx);
void cbm_extract_semantic(CBMExtractCtx *ctx);
Expand Down
4 changes: 4 additions & 0 deletions internal/cbm/lsp/php_lsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "php_lsp.h"
#include "lsp_node_iter.h"
#include "../cbm.h"
#include "../helpers.h"
#include <ctype.h>
#include <stdio.h>
Expand Down Expand Up @@ -4489,6 +4490,9 @@ void cbm_run_php_lsp_cross(CBMArena *arena, const char *source, int source_len,
TSTree *cached_tree, CBMResolvedCallArray *out) {
if (!arena || !source || source_len <= 0 || !out)
return;
/* The retained source is the file on disk; read it the way the per-file
* extract did, so the cached tree and node text agree (#2000). */
source = cbm_php_mask_inline_html(arena, source, source_len);

TSParser *parser = NULL;
TSTree *tree = cached_tree;
Expand Down
Loading