chunklet.code_chunker._code_structure_extractor
Internal module for extracting code structures from source code files.
Provides functionality to parse and analyze code syntax trees, identifying functions, classes, namespaces, and other structural elements. This module is used by CodeChunker to understand code structure before splitting into chunks.
Classes:
-
CodeStructureExtractor–Extracts structural units from source code.
CodeStructureExtractor
Extracts structural units from source code.
This class provides functionality to parse source code files and identify functions, classes, namespaces, and other structural elements using a language-agnostic approach.
Methods:
-
extract_code_structure–Preprocess and parse code into individual snippet boxes.
Source code in src/chunklet/code_chunker/_code_structure_extractor.py
extract_code_structure
extract_code_structure(
code: str,
include_comments: bool,
docstring_mode: str,
is_python_code: bool = False,
) -> tuple[list[dict], tuple[int, ...]]
Preprocess and parse code into individual snippet boxes.
This function-first extraction identifies functions as primary units while implicitly handling other structures within the function context.
Parameters:
-
(codestr) –Raw code string.
-
(include_commentsbool) –Whether to include comments in output.
-
(docstring_modeLiteral[summary, all, excluded]) –How to handle docstrings.
-
(is_python_codebool, default:False) –Whether the code is Python.
Returns:
-
tuple[list[dict], tuple[int, ...]]–tuple[list[dict], tuple[int, ...]]: A tuple containing the list of extracted code structure boxes and the line lengths.
Source code in src/chunklet/code_chunker/_code_structure_extractor.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |