Skip to content

Commit f8c934d

Browse files
committed
docs: add CLAUDE.md file
1 parent 2e46b8f commit f8c934d

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build Commands
6+
7+
```bash
8+
npm install # Install dependencies
9+
npm run build # Full build (grammar + ES + CJS + UMD browser bundles)
10+
npm run grammar:compile # Compile ABNF grammar to parser (src/grammar.bnf → src/grammar.js)
11+
npm test # Run all tests with Mocha
12+
npm test -- --grep "pattern" # Run specific tests matching pattern
13+
npm test -- test/parse/index.js # Run a single test file
14+
```
15+
16+
## Architecture
17+
18+
This is an RFC 6901 JSON Pointer implementation providing parsing, validation, evaluation, compilation, and representation.
19+
20+
### Core Pipeline
21+
22+
1. **Grammar** (`src/grammar.bnf`) - ABNF grammar defining JSON Pointer syntax, compiled via apg-js to `src/grammar.js`
23+
2. **Parsing** (`src/parse/`) - Uses apg-lite parser generator with pluggable translators (AST, CST, XML)
24+
3. **Evaluation** (`src/evaluate/`) - Traverses data structures using reference tokens with pluggable evaluation realms
25+
4. **Compilation** (`src/compile.js`) - Converts unescaped reference tokens back to JSON Pointer string
26+
27+
### Evaluation Realms
28+
29+
The realm system (`src/evaluate/realms/`) enables polymorphic evaluation across different data structures:
30+
31+
- `json/` - Default realm for plain JS objects/arrays
32+
- `map-set/` - Supports Map and Set instances
33+
- `minim/` - For minim element structures (API description tools)
34+
- `apidom/` - For ApiDOM structures (OpenAPI/AsyncAPI processing)
35+
- `immutable/` - For Immutable.js structures
36+
- `compose.js` - Composes multiple realms (order matters: specific before generic)
37+
38+
Custom realms extend `EvaluationRealm` base class implementing: `isArray`, `isObject`, `sizeOf`, `has`, `evaluate`.
39+
40+
### Parse Translators
41+
42+
Located in `src/parse/translators/`:
43+
- `ASTTranslator` (default) - Returns array of unescaped reference tokens
44+
- `CSTTranslator` - Returns concrete syntax tree with node positions
45+
- `XMLTranslator` - Returns XML string representation
46+
47+
### Error Hierarchy
48+
49+
All errors extend `JSONPointerError`:
50+
- `JSONPointerParseError` - Invalid pointer syntax
51+
- `JSONPointerCompileError` - Invalid reference tokens during compilation
52+
- `JSONPointerEvaluateError` - Base for evaluation errors
53+
- `JSONPointerTypeError` - Evaluating against non-object/non-array
54+
- `JSONPointerKeyError` - Object key not found
55+
- `JSONPointerIndexError` - Array index issues (out of bounds, invalid format, "-" token)
56+
57+
### Module Formats
58+
59+
The build produces three formats:
60+
- `es/` - ES modules (.mjs)
61+
- `cjs/` - CommonJS (.cjs)
62+
- `dist/` - UMD browser bundles (json-pointer.browser.js, json-pointer.browser.min.js)
63+
64+
TypeScript types are in `types/index.d.ts`.

0 commit comments

Comments
 (0)