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 Path | Role | Key Symbols | Responsibility |
|---|---|---|---|
deepdoc/parser/vue_parser.py | Handler | parse_vue, _extract_script_block, _extract_options_api_constructs, _extract_script_setup_constructs | Parses Vue SFCs, extracts script/template blocks, infers component structure and runtime features |
deepdoc/parser/__init__.py | Service | parse_file, supported_extensions, ParsedFile, Symbol | Entry point for parsing, exposes unified API and supported file types |
deepdoc/parser/base.py | Model | Symbol, ParsedFile | Data models for parsed files and symbols |
deepdoc/parser/js_ts_parser.py | Handler | parse_js_ts | Parses 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
ParsedFilewith only template/style info. - Determines effective language (
typescriptiflangists/tsx, elsejavascript). - If
<script setup>, extracts Composition API constructs; else, extracts Options API constructs. - Always extracts runtime features and template info.
- If no script block, returns a
- 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.
- If both
_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
langattribute.
- Prefers
- 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
definePropsuses type parameter, extracts prop names from type. - If
definePropsuses object parameter, extracts prop names from object keys. - If
defineEmitsuses type parameter or array, extracts event names. - If
defineExposeis present, extracts exposed names. - If
defineModelis present, extracts model name. - If
defineSlotsis present, extracts slot names. - Always extracts reactivity primitives (
ref,reactive,computed, etc.).
- If
- 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
propsis object, extracts prop names from keys. - If
propsis array, extracts prop names from array values. - If
emitsis array, extracts event names. - If
methodsis object, extracts method names.
- If
- 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
- Pipeline & Generation Engine: Consumes
ParsedFileobjects for evidence assembly and documentation generation. See Pipeline & Generation Engine. - Frontend Site Builder: Uses parsed symbols for UI scaffolding and documentation rendering. See Site Generation & Frontend Integration Overview.
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 aParsedFilewith 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
| Symbol | File Path | Signature / Key Args | What It Does |
|---|---|---|---|
parse_vue | deepdoc/parser/vue_parser.py:25 | parse_vue(path, content, language) | Parses Vue SFC, extracts symbols and constructs |
_extract_script_block | deepdoc/parser/vue_parser.py:86 | _extract_script_block(content) | Extracts script content, language, setup status |
_extract_template_block | deepdoc/parser/vue_parser.py:127 | _extract_template_block(content) | Extracts template block content |
_extract_script_setup_constructs | deepdoc/parser/vue_parser.py:138 | _extract_script_setup_constructs(script, symbols) | Extracts Composition API constructs |
_extract_composition_refs | deepdoc/parser/vue_parser.py:272 | _extract_composition_refs(script, symbols, existing_names) | Extracts reactivity primitives |
_extract_options_api_constructs | deepdoc/parser/vue_parser.py:300 | _extract_options_api_constructs(script, symbols) | Extracts Options API props/emits/methods |
_extract_template_info | deepdoc/parser/vue_parser.py:383 | _extract_template_info(template, symbols) | Extracts child components and slots |
_detect_component_name | deepdoc/parser/vue_parser.py:422 | _detect_component_name(path, content, script) | Infers component name |
_make_component_symbol | deepdoc/parser/vue_parser.py:440 | _make_component_symbol(component_name) | Creates component symbol object |
_extract_vue_runtime_features | deepdoc/parser/vue_parser.py:450 | _extract_vue_runtime_features(script, symbols) | Extracts runtime features (router, store, etc.) |
Symbol | deepdoc/parser/base.py:17 | Symbol(name, kind, signature, ...) | Represents a code symbol |
ParsedFile | deepdoc/parser/base.py:35 | ParsedFile(path, language, symbols, ...) | Structured parsed file |
parse_js_ts | deepdoc/parser/js_ts_parser.py:28 | parse_js_ts(path, content, language) | Parses JS/TS files for symbols |
parse_file | deepdoc/parser/registry.py | parse_file(path, content) | Unified file parsing entrypoint |
supported_extensions | deepdoc/parser/registry.py | supported_extensions | Supported 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".