@morphql/language-definitions 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -110
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Hyperwindmill/morphql/main/morphql.png" alt="MorphQL" width="200" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@morphql/language-definitions"><img src="https://img.shields.io/npm/v/@morphql/language-definitions?label=%40morphql%2Flanguage-definitions" alt="npm version" /></a>
|
|
7
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT" />
|
|
8
|
+
</p>
|
|
9
|
+
|
|
1
10
|
# @morphql/language-definitions
|
|
2
11
|
|
|
3
|
-
**
|
|
12
|
+
The **single source of truth** for MorphQL language definitions (keywords, functions, operators) across all platforms. This package ensures consistency between the engine, IDE extensions, and documentation.
|
|
4
13
|
|
|
5
14
|
## Purpose
|
|
6
15
|
|
|
7
|
-
This package centralizes
|
|
16
|
+
This shared package centralizes the MorphQL grammar for reuse in:
|
|
8
17
|
|
|
9
|
-
- VSCode
|
|
10
|
-
- Monaco Editor (
|
|
11
|
-
- Documentation
|
|
18
|
+
- **VSCode Extension**: TextMate grammar and hover providers.
|
|
19
|
+
- **Monaco Editor (Playground)**: Language configuration and Monarch tokens.
|
|
20
|
+
- **Documentation**: Automatic generation of function and keyword references.
|
|
21
|
+
- **Type Safety**: TypeScript interfaces for language features.
|
|
12
22
|
|
|
13
23
|
## Installation
|
|
14
24
|
|
|
@@ -16,130 +26,37 @@ This package centralizes all MorphQL language definitions (keywords, functions,
|
|
|
16
26
|
npm install @morphql/language-definitions
|
|
17
27
|
```
|
|
18
28
|
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
### Get Language Data
|
|
29
|
+
## Basic Usage
|
|
22
30
|
|
|
23
31
|
```typescript
|
|
24
32
|
import {
|
|
25
33
|
KEYWORDS,
|
|
26
34
|
FUNCTIONS,
|
|
27
|
-
OPERATORS,
|
|
28
35
|
getKeywordNames,
|
|
29
36
|
getFunctionNames,
|
|
30
|
-
getOperatorSymbols,
|
|
31
37
|
} from "@morphql/language-definitions";
|
|
32
38
|
|
|
33
|
-
// Get all keyword names
|
|
39
|
+
// Get all keyword names for a lexer
|
|
34
40
|
const keywords = getKeywordNames();
|
|
35
|
-
// ['from', 'to', 'transform', 'set', ...]
|
|
36
41
|
|
|
37
|
-
// Get
|
|
38
|
-
const functions = getFunctionNames();
|
|
39
|
-
// ['substring', 'split', 'replace', ...]
|
|
40
|
-
|
|
41
|
-
// Get documentation for a keyword
|
|
42
|
+
// Get documentation for hover providers
|
|
42
43
|
import { getKeywordDoc } from "@morphql/language-definitions";
|
|
43
44
|
const doc = getKeywordDoc("set");
|
|
44
|
-
// { signature:
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Generate VSCode TextMate Grammar
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { generateTextMateKeywordsPattern } from "@morphql/language-definitions";
|
|
51
|
-
|
|
52
|
-
const keywordsPattern = generateTextMateKeywordsPattern();
|
|
53
|
-
// Use in morphql.tmLanguage.json
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Generate Monaco Language Config
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { generateMonacoLanguageConfig } from "@morphql/language-definitions";
|
|
60
|
-
|
|
61
|
-
const monacoConfig = generateMonacoLanguageConfig();
|
|
62
|
-
monaco.languages.register({ id: "morphql" });
|
|
63
|
-
monaco.languages.setMonarchTokensProvider("morphql", monacoConfig);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Generate Hover Documentation
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
import { generateHoverDocs } from "@morphql/language-definitions";
|
|
70
|
-
|
|
71
|
-
const { keywordDocs, functionDocs } = generateHoverDocs();
|
|
72
|
-
// Use in VSCode HoverProvider or Monaco HoverProvider
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Adding New Language Features
|
|
76
|
-
|
|
77
|
-
### 1. Add to This Package
|
|
78
|
-
|
|
79
|
-
Edit the appropriate file:
|
|
80
|
-
|
|
81
|
-
- **Keywords**: `src/keywords.ts`
|
|
82
|
-
- **Functions**: `src/functions.ts`
|
|
83
|
-
- **Operators**: `src/operators.ts`
|
|
84
|
-
|
|
85
|
-
### 2. Update the Lexer
|
|
86
|
-
|
|
87
|
-
Update `@morphql/core/src/core/lexer.ts` with the new token.
|
|
88
|
-
|
|
89
|
-
### 3. Rebuild
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
npm run build
|
|
45
|
+
// { signature: "set <target> = <expression>", description: "..." }
|
|
93
46
|
```
|
|
94
47
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
The VSCode extension and playground will automatically use the new definitions on their next build.
|
|
48
|
+
## Maintenance
|
|
98
49
|
|
|
99
|
-
|
|
50
|
+
To add a new language feature (keyword, function, or operator), you should:
|
|
100
51
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
├── keywords.ts # Keyword definitions + docs
|
|
105
|
-
├── functions.ts # Function definitions + docs
|
|
106
|
-
├── operators.ts # Operator definitions
|
|
107
|
-
└── index.ts # Exports + generators
|
|
108
|
-
```
|
|
52
|
+
1. Update the appropriate file in `src/` (e.g., `src/functions.ts`).
|
|
53
|
+
2. Run `npm run build`.
|
|
54
|
+
3. Changes will propagate to the VS Code extension and Playground on their next build.
|
|
109
55
|
|
|
110
|
-
##
|
|
56
|
+
## Learn More
|
|
111
57
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
✅ **Auto-generated** - Configs generated from definitions
|
|
115
|
-
✅ **Consistent** - No more sync issues between platforms
|
|
116
|
-
✅ **Documented** - All definitions include documentation
|
|
117
|
-
|
|
118
|
-
## Example: Adding a New Keyword
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
// 1. Edit src/keywords.ts
|
|
122
|
-
export const KEYWORDS: KeywordDef[] = [
|
|
123
|
-
// ... existing keywords ...
|
|
124
|
-
{
|
|
125
|
-
name: "loop",
|
|
126
|
-
category: "control",
|
|
127
|
-
doc: {
|
|
128
|
-
signature: "loop <count> ( <actions> )",
|
|
129
|
-
description: "Repeats actions a specified number of times.",
|
|
130
|
-
parameters: [
|
|
131
|
-
{ name: "count", description: "Number of iterations" },
|
|
132
|
-
{ name: "actions", description: "Actions to repeat" },
|
|
133
|
-
],
|
|
134
|
-
example: "loop 5 (\n set item = value\n)",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
];
|
|
138
|
-
|
|
139
|
-
// 2. Update lexer in @morphql/core
|
|
140
|
-
// 3. Rebuild this package: npm run build
|
|
141
|
-
// 4. VSCode and Monaco will pick it up automatically!
|
|
142
|
-
```
|
|
58
|
+
- 👉 **[Official Documentation](https://hyperwindmill.github.io/morphql/)**
|
|
59
|
+
- 🏠 **[Main Repository](https://github.com/Hyperwindmill/morphql)**
|
|
143
60
|
|
|
144
61
|
## License
|
|
145
62
|
|