Skip to main content
RFC Status: This document is part of the OpenDocs RFC and subject to change based on community feedback.

Language Extractors

Language extractors are the core components that parse source code and convert it into OpenDocs DocItems. This guide shows you how to build extractors for different programming languages.

Introduction

A language extractor:
  1. Parses source code using language-specific AST parsers
  2. Extracts documentation comments and metadata
  3. Converts language constructs to DocItems
  4. Maintains relationships between items (containers, references)

TypeScript Extractor Example

Here’s a complete implementation of a TypeScript extractor using the TypeScript Compiler API:

Rust Extractor Example

Here’s a complete implementation of a Rust extractor using the Syn library:

Best Practices for Building Extractors

1. Start Simple

Begin with basic extraction of classes, functions, and interfaces before adding complex features like generics, decorators, or annotations.
Focus on:
  • Name and ID extraction
  • Basic documentation comments
  • Simple metadata (visibility, modifiers)
  • Container relationships

2. Leverage Language-Specific Tools

Use established AST parsers and tooling:
  • TypeScript: TypeScript Compiler API
  • Rust: Syn + Quote
  • Go: go/ast + go/parser
  • Python: ast module
  • Java: JavaParser or Eclipse JDT

3. Handle Documentation Comments Properly

Different languages have different documentation comment formats:

4. Generate Unique, Stable IDs

IDs should be:
  • Unique: No collisions within a project
  • Stable: Unchanged across rebuilds
  • Qualified: Include namespace/module path
  • Language-prefixed: Indicate language for cross-language projects
Example ID patterns:

5. Extract Rich Metadata

Include language-specific metadata that helps documentation tools:

Common Pitfalls

1. Incomplete AST Traversal

Problem: Missing items due to incomplete tree walking. Solution: Use recursive traversal and handle all relevant node types:

2. Ignoring Nested Structures

Problem: Only extracting top-level items. Solution: Track nesting context and extract nested classes, enums, etc.

3. Poor Error Handling

Problem: Extraction crashes on malformed code. Solution: Gracefully handle parse errors and continue extraction:

4. Memory Leaks on Large Codebases

Problem: Loading entire AST into memory. Solution: Process files in batches and use streaming:

See Also


This guide is part of the OpenDocs Specification RFC. Help us improve it by sharing your extractor implementations and feedback.