Skip to content

Commit 82d087c

Browse files
committed
outlining docs
1 parent 5ec0687 commit 82d087c

20 files changed

Lines changed: 569 additions & 585 deletions

docs/Specifications.md

Lines changed: 80 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ The Compiler class provides static methods for converting Abstract Syntax Tree (
66
import { Compiler } from '@stackpress/idea-parser';
77
```
88

9-
## Static Methods
9+
## 1. Static Methods
1010

1111
The following methods can be accessed directly from the Compiler class.
1212

13-
### Converting Array Tokens
13+
### 1.1. Converting Array Tokens
1414

1515
The following example shows how to compile array tokens into actual arrays.
1616

@@ -42,7 +42,7 @@ console.log(result); // ['value1', 'value2', 'value3']
4242

4343
An array containing the compiled elements.
4444

45-
### Converting Data Tokens
45+
### 1.2. Converting Data Tokens
4646

4747
The following example shows how to compile various data tokens into their actual values.
4848

@@ -76,7 +76,7 @@ console.log(objectResult); // { name: 'John' }
7676

7777
The compiled data value based on the token type.
7878

79-
### Converting Enum Declarations
79+
### 1.3. Converting Enum Declarations
8080

8181
The following example shows how to compile enum declarations into JSON configurations.
8282

@@ -112,7 +112,7 @@ console.log(config); // { ACTIVE: 'Active', INACTIVE: 'Inactive' }
112112

113113
A tuple containing the enum name and its configuration object.
114114

115-
### Converting Schema to Final JSON
115+
### 1.4. Converting Schema to Final JSON
116116

117117
The following example shows how to compile a schema token into a final JSON configuration.
118118

@@ -135,7 +135,7 @@ console.log(finalSchema);
135135

136136
A `FinalSchemaConfig` object with references resolved and removed.
137137

138-
### Converting Identifier Tokens
138+
### 1.5. Converting Identifier Tokens
139139

140140
The following example shows how to resolve identifier tokens to their actual values.
141141

@@ -170,7 +170,7 @@ try {
170170

171171
The resolved value from references, a template string, or throws an error.
172172

173-
### Converting Literal Tokens
173+
### 1.6. Converting Literal Tokens
174174

175175
The following example shows how to extract values from literal tokens.
176176

@@ -197,7 +197,7 @@ console.log(booleanLiteral); // true
197197

198198
The literal value (string, number, boolean, etc.).
199199

200-
### Converting Model Declarations
200+
### 1.7. Converting Model Declarations
201201

202202
The following example shows how to compile model declarations into JSON configurations.
203203

@@ -252,7 +252,7 @@ console.log(config.columns); // Array of column configurations
252252

253253
A tuple containing the model name and its configuration object.
254254

255-
### Converting Object Tokens
255+
### 1.8. Converting Object Tokens
256256

257257
The following example shows how to compile object tokens into actual objects.
258258

@@ -283,7 +283,7 @@ console.log(result); // { name: 'John', age: 30 }
283283

284284
An object with compiled key-value pairs.
285285

286-
### Converting Plugin Declarations
286+
### 1.9. Converting Plugin Declarations
287287

288288
The following example shows how to compile plugin declarations into JSON configurations.
289289

@@ -318,7 +318,7 @@ console.log(config); // { provider: 'postgresql' }
318318

319319
A tuple containing the plugin name and its configuration object.
320320

321-
### Converting Prop Declarations
321+
### 1.10. Converting Prop Declarations
322322

323323
The following example shows how to compile prop declarations into JSON configurations.
324324

@@ -355,7 +355,7 @@ console.log(config); // { type: 'text', format: 'lowercase' }
355355

356356
A tuple containing the prop name and its configuration object.
357357

358-
### Converting Schema Declarations
358+
### 1.11. Converting Schema Declarations
359359

360360
The following example shows how to compile complete schema tokens into JSON configurations.
361361

@@ -384,7 +384,7 @@ console.log(finalizedConfig);
384384

385385
A `SchemaConfig` object containing all compiled declarations.
386386

387-
### Converting Type Declarations
387+
### 1.12. Converting Type Declarations
388388

389389
The following example shows how to compile type declarations into JSON configurations.
390390

@@ -438,7 +438,7 @@ console.log(config.columns); // Array of column configurations
438438

439439
A tuple containing the type name and its configuration object.
440440

441-
### Converting Use Declarations
441+
### 1.13. Converting Use Declarations
442442

443443
The following example shows how to compile use (import) declarations.
444444

@@ -465,11 +465,11 @@ console.log(importPath); // './another.idea'
465465

466466
The import path as a string.
467467

468-
## Error Handling
468+
## 2. Error Handling
469469

470470
The Compiler class throws `Exception` errors for various invalid conditions:
471471

472-
### Invalid Token Types
472+
### 2.1. Invalid Token Types
473473

474474
```typescript
475475
// Throws: "Invalid data token type"
@@ -494,7 +494,7 @@ Compiler.type({ kind: 'notAType' });
494494
Compiler.use({ type: 'NotAnImportDeclaration' });
495495
```
496496

497-
### Missing Required Properties
497+
### 2.2. Missing Required Properties
498498

499499
```typescript
500500
// Throws: "Expecting a columns property"
@@ -507,31 +507,31 @@ Compiler.model({
507507
});
508508
```
509509

510-
### Unknown References
510+
### 2.3. Unknown References
511511

512512
```typescript
513513
// Throws: "Unknown reference MyProp"
514514
Compiler.identifier({ name: 'MyProp' }, {});
515515
```
516516

517-
### Duplicate Declarations
517+
### 2.4. Duplicate Declarations
518518

519519
```typescript
520520
// Throws: "Duplicate MyEnum" when compiling schema with duplicate names
521521
Compiler.schema(schemaWithDuplicates);
522522
```
523523

524-
## Type Processing
524+
## 3. Type Processing
525525

526526
The Compiler automatically processes type information for models and types:
527527

528-
### Type Modifiers
528+
### 3.1. Type Modifiers
529529

530530
- **Optional types**: `String?``{ type: 'String', required: false }`
531531
- **Array types**: `String[]``{ type: 'String', multiple: true }`
532532
- **Combined**: `String[]?``{ type: 'String', required: false, multiple: true }`
533533

534-
### Column Configuration
534+
### 3.2. Column Configuration
535535

536536
Models and types are converted from object format to array format to preserve column order:
537537

@@ -553,7 +553,7 @@ Models and types are converted from object format to array format to preserve co
553553
}
554554
```
555555

556-
## Usage with AST
556+
## 3.3. Usage with AST
557557

558558
The Compiler is typically used in conjunction with AST classes:
559559

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ The Exception class extends the Exception class from `@stackpress/lib` to provid
66
import { Exception } from '@stackpress/idea-parser';
77
```
88

9-
## Overview
9+
## 1. Overview
1010

1111
Exception is a specialized error class that extends the base Exception class with additional functionality for parser-specific error handling. It automatically includes position information when parsing fails, making it easier to identify and fix syntax errors in schema files.
1212

13-
## Usage Examples
13+
## 2. Usage Examples
1414

15-
### Basic Error Handling
15+
### 2.1. Basic Error Handling
1616

1717
```typescript
1818
import { parse, Exception } from '@stackpress/idea-parser';
@@ -28,7 +28,7 @@ try {
2828
}
2929
```
3030

31-
### Position Information
31+
### 2.2. Position Information
3232

3333
Exception includes position information to help locate errors in the source code:
3434

@@ -50,9 +50,9 @@ try {
5050
}
5151
```
5252

53-
### Common Error Scenarios
53+
### 2.3. Common Error Scenarios
5454

55-
#### Syntax Errors
55+
#### 2.3.1. Syntax Errors
5656

5757
```typescript
5858
try {
@@ -62,7 +62,7 @@ try {
6262
}
6363
```
6464

65-
#### Invalid Token Types
65+
#### 2.3.2. Invalid Token Types
6666

6767
```typescript
6868
try {
@@ -72,7 +72,7 @@ try {
7272
}
7373
```
7474

75-
#### Unknown References
75+
#### 2.3.3. Unknown References
7676

7777
```typescript
7878
try {
@@ -82,7 +82,7 @@ try {
8282
}
8383
```
8484

85-
#### Duplicate Declarations
85+
#### 2.3.4. Duplicate Declarations
8686

8787
```typescript
8888
try {
@@ -95,7 +95,7 @@ try {
9595
}
9696
```
9797

98-
## Integration with AST
98+
## 3. Integration with AST
9999

100100
All AST classes throw Exception when parsing fails:
101101

@@ -118,7 +118,7 @@ try {
118118
}
119119
```
120120

121-
## Error Recovery
121+
## 4. Error Recovery
122122

123123
While Exception indicates parsing failure, you can implement error recovery strategies:
124124

@@ -138,7 +138,7 @@ function parseWithFallback(code: string, fallbackCode?: string) {
138138
}
139139
```
140140

141-
## Language Server Integration
141+
## 5. Language Server Integration
142142

143143
Exception's position information makes it ideal for language server implementations:
144144

@@ -168,7 +168,7 @@ function validateSchema(code: string) {
168168
}
169169
```
170170

171-
## Inherited Features
171+
## 6. Inherited Features
172172

173173
Since Exception extends the base Exception class from `@stackpress/lib`, it inherits all the enhanced error handling features:
174174

@@ -180,9 +180,9 @@ Since Exception extends the base Exception class from `@stackpress/lib`, it inhe
180180

181181
For more details on the base Exception functionality, refer to the [@stackpress/lib Exception documentation](https://github.com/stackpress/lib#exception).
182182

183-
## Best Practices
183+
## 7. Best Practices
184184

185-
### Always Check Error Type
185+
### 7.1. Always Check Error Type
186186

187187
```typescript
188188
try {
@@ -198,7 +198,7 @@ try {
198198
}
199199
```
200200

201-
### Use Position Information
201+
### 7.2. Use Position Information
202202

203203
```typescript
204204
function highlightError(code: string, error: Exception) {
@@ -222,7 +222,7 @@ function highlightError(code: string, error: Exception) {
222222
}
223223
```
224224

225-
### Provide Helpful Error Messages
225+
### 7.3. Provide Helpful Error Messages
226226

227227
```typescript
228228
function parseWithContext(code: string, filename?: string) {

0 commit comments

Comments
 (0)