codewiki
Architecture

Parsing & Source Analysis

Overview

The Parsing & Source Analysis feature is responsible for extracting structured information from source files, inferring types, and identifying key symbols (such as components, props, methods, and runtime features) for downstream documentation and code intelligence. It forms the backbone of DeepDoc's evidence assembly, enabling accurate, language-aware documentation generation and symbol indexing.

This module supports multi-language parsing, with specialized logic for Vue Single File Components (SFCs), JavaScript, and TypeScript. It detects business-relevant constructs (like Vue props, emits, composables, and runtime integrations) and normalizes them into a unified symbol model for further processing in the Pipeline & Generation Engine.

Parsing is the first stage in DeepDoc's evidence pipeline. For a high-level overview of how parsed data flows into documentation generation, see DeepDoc Architecture & System Overview.

Files Covered

File PathRoleKey SymbolsResponsibility
deepdoc/parser/vue_parser.pyHandlerparse_vue, _extract_script_block, _extract_options_api_constructs, _extract_script_setup_constructsParses Vue SFCs, extracts script/template blocks, infers component structure and runtime features
deepdoc/parser/__init__.pyServiceparse_file, supported_extensions, ParsedFile, SymbolEntry point for parsing, exposes unified API and supported file types
deepdoc/parser/base.pyModelSymbol, ParsedFileData models for parsed files and symbols
deepdoc/parser/js_ts_parser.pyHandlerparse_js_tsParses JS/TS files, infers symbols and imports

Main Workflows

The primary workflow for source parsing and analysis is as follows:

File Type Detection The entrypoint parse_file() (deepdoc/parser/registry.py) determines the file type and selects the appropriate parser based on extension and content.

Vue SFC Parsing For .vue files, parse_vue() (deepdoc/parser/vue_parser.py:25) extracts <script> and <template> blocks, detects language (JS/TS), and identifies whether the block uses Composition API (<script setup>) or Options API.

Script Block Analysis The script block is delegated to parse_js_ts() (deepdoc/parser/js_ts_parser.py:28) for symbol extraction, type inference, and import detection.

Vue-Specific Construct Extraction Vue-specific constructs (props, emits, expose, model, slots, runtime features) are extracted via _extract_script_setup_constructs() and _extract_options_api_constructs() (deepdoc/parser/vue_parser.py).

Template Block Analysis _extract_template_info() (deepdoc/parser/vue_parser.py:383) analyzes the template for child component usage and slot definitions.

Symbol Normalization All extracted symbols are normalized into Symbol objects (deepdoc/parser/base.py:17) and returned as a ParsedFile (deepdoc/parser/base.py:35).

Pipeline Integration Parsed files are passed to the Pipeline & Generation Engine for evidence assembly and documentation generation.

Data Flow Diagram

The workflow is fully grounded for Vue SFCs and JS/TS files. Other language parsing is handled via parse_file() and supported_extensions (deepdoc/parser/__init__.py), but details may be inferred if not directly evidenced.

Participating Endpoints

This feature operates at the file parsing layer and does not expose direct API endpoints. However, its outputs are consumed by endpoints documented in Public API Endpoints and Runtime Services & Chatbot Engine, which serve parsed symbol data and documentation to clients.

For endpoint-level integration, see Pipeline & Generation Engine and Public API Endpoints.

Core Helpers & Business Rules

parse_vue() (deepdoc/parser/vue_parser.py:25)

  • Purpose: Parses Vue SFCs, extracts script/template blocks, delegates JS/TS parsing, and infers Vue-specific constructs.
  • Parameters: path: Path, content: str, language: str
  • Returns: ParsedFile (deepdoc/parser/base.py:35)
  • Branching Logic:
    • If no script block, returns a ParsedFile with only template/style info.
    • Determines effective language (typescript if lang is ts/tsx, else javascript).
    • If <script setup>, extracts Composition API constructs; else, extracts Options API constructs.
    • Always extracts runtime features and template info.
  • Example Usage:
    parsed = parse_vue(path, content, language)
  • Edge Cases:
    • If both <script setup> and <script> exist, <script setup> is preferred.
    • If component name is not found, falls back to filename stem.

_extract_script_block() (deepdoc/parser/vue_parser.py:86)

  • Purpose: Extracts script content, language, and setup status from Vue SFC.
  • Returns: (script_content, lang, is_setup)
  • Branching Logic:
    • Prefers <script setup> over regular <script>.
    • Determines language from lang attribute.
  • Example:
    script_content, script_lang, is_setup = _extract_script_block(content)

_extract_script_setup_constructs() (deepdoc/parser/vue_parser.py:138)

  • Purpose: Extracts defineProps, defineEmits, defineExpose, defineModel, defineSlots, and reactivity primitives from <script setup>.
  • Branching Logic:
    • If defineProps uses type parameter, extracts prop names from type.
    • If defineProps uses object parameter, extracts prop names from object keys.
    • If defineEmits uses type parameter or array, extracts event names.
    • If defineExpose is present, extracts exposed names.
    • If defineModel is present, extracts model name.
    • If defineSlots is present, extracts slot names.
    • Always extracts reactivity primitives (ref, reactive, computed, etc.).
  • Example:
    _extract_script_setup_constructs(script_content, parsed.symbols)

_extract_options_api_constructs() (deepdoc/parser/vue_parser.py:300)

  • Purpose: Extracts props, emits, and methods from Options API export default object.
  • Branching Logic:
    • If props is object, extracts prop names from keys.
    • If props is array, extracts prop names from array values.
    • If emits is array, extracts event names.
    • If methods is object, extracts method names.
  • Example:
    _extract_options_api_constructs(script_content, parsed.symbols)

_extract_template_info() (deepdoc/parser/vue_parser.py:383)

  • Purpose: Extracts child component usage and slot info from template block.
  • Branching Logic:
    • Detects PascalCase tags as child components.
    • Detects named slots and default slot.
  • Example:
    _extract_template_info(template_content, parsed.symbols)

Symbol (deepdoc/parser/base.py:17)

  • Purpose: Represents a named code symbol extracted from a file.
  • Fields: name, kind, signature, docstring, fields, props, is_exported, etc.
  • Example:
    symbol = Symbol(name="props", kind="constant", signature="defineProps()", docstring="Component props: ...")

ParsedFile (deepdoc/parser/base.py:35)

  • Purpose: Structured representation of a parsed source file.
  • Fields: path, language, symbols, imports, raw_content
  • Example:
    parsed = ParsedFile(path=path, language="vue", symbols=symbols, imports=[], raw_content=content[:8000])

parse_js_ts() (deepdoc/parser/js_ts_parser.py:28)

  • Purpose: Parses JS/TS files, infers symbols and imports, tags React constructs.
  • Branching Logic:
    • Uses Tree-sitter parser if available; else, falls back to regex.
    • Tags React components/hooks by naming convention.
  • Example:
    parsed = parse_js_ts(path, script_content, effective_lang)

All helper functions are grounded in the source. See Pipeline & Generation Engine for downstream consumption.

State Transitions

The parsing process transforms raw source files into structured symbol representations. The state transitions are:

  • RawFile: Initial state, raw source content.
  • ScriptBlockExtracted: Script block and language extracted.
  • ParsedSymbols: JS/TS symbols parsed.
  • VueConstructsExtracted: Vue-specific constructs extracted.
  • TemplateInfoExtracted: Template block analyzed for slots/components.
  • ParsedFile: Final structured representation.

Integrations Involved

No direct external API integrations are performed at the parsing stage. All integration is internal to DeepDoc's evidence pipeline.

Configuration & Environment

No environment variables or config flags directly affect the parsing logic in the evidenced files.

Language support is determined by supported_extensions (deepdoc/parser/__init__.py), which is static and not configurable via env vars.

Edge Cases & Failure Modes

  • Missing Script Block: If a Vue SFC lacks a <script> block, parse_vue() returns a ParsedFile with only template/style info.
  • Multiple Script Blocks: If both <script setup> and <script> exist, <script setup> is preferred.
  • Malformed Blocks: If script/template blocks are malformed or missing, extraction functions return empty content, resulting in reduced symbol output.
  • Unknown Component Name: If no explicit name is found, the filename stem is used as the component name.
  • JS/TS Parser Fallback: If Tree-sitter is unavailable, parse_js_ts() falls back to regex-based parsing, which may be less accurate.

Malformed or unconventional Vue SFCs may result in incomplete symbol extraction. Always validate SFC structure for optimal parsing.

Diagrams

Data Flow Diagram

See above in "Main Workflows".

State Transition Diagram

See above in "State Transitions".

Quick Reference

SymbolFile PathSignature / Key ArgsWhat It Does
parse_vuedeepdoc/parser/vue_parser.py:25parse_vue(path, content, language)Parses Vue SFC, extracts symbols and constructs
_extract_script_blockdeepdoc/parser/vue_parser.py:86_extract_script_block(content)Extracts script content, language, setup status
_extract_template_blockdeepdoc/parser/vue_parser.py:127_extract_template_block(content)Extracts template block content
_extract_script_setup_constructsdeepdoc/parser/vue_parser.py:138_extract_script_setup_constructs(script, symbols)Extracts Composition API constructs
_extract_composition_refsdeepdoc/parser/vue_parser.py:272_extract_composition_refs(script, symbols, existing_names)Extracts reactivity primitives
_extract_options_api_constructsdeepdoc/parser/vue_parser.py:300_extract_options_api_constructs(script, symbols)Extracts Options API props/emits/methods
_extract_template_infodeepdoc/parser/vue_parser.py:383_extract_template_info(template, symbols)Extracts child components and slots
_detect_component_namedeepdoc/parser/vue_parser.py:422_detect_component_name(path, content, script)Infers component name
_make_component_symboldeepdoc/parser/vue_parser.py:440_make_component_symbol(component_name)Creates component symbol object
_extract_vue_runtime_featuresdeepdoc/parser/vue_parser.py:450_extract_vue_runtime_features(script, symbols)Extracts runtime features (router, store, etc.)
Symboldeepdoc/parser/base.py:17Symbol(name, kind, signature, ...)Represents a code symbol
ParsedFiledeepdoc/parser/base.py:35ParsedFile(path, language, symbols, ...)Structured parsed file
parse_js_tsdeepdoc/parser/js_ts_parser.py:28parse_js_ts(path, content, language)Parses JS/TS files for symbols
parse_filedeepdoc/parser/registry.pyparse_file(path, content)Unified file parsing entrypoint
supported_extensionsdeepdoc/parser/registry.pysupported_extensionsSupported file extensions

Constants, Enums & Status Values

No enums or status constants directly affect runtime parsing behavior in the evidenced files. The Symbol and ParsedFile classes define type fields (kind, language) which are string values, e.g. "component", "constant", "method", "vue", "javascript", "typescript".

See Also

Ask the codebase

Open a dedicated answer page with grounded citations.

Ask from any docs page and keep reading without losing context.