links-notation 0.8.0

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 ADDED
@@ -0,0 +1,219 @@
1
+ # Lino Protocol Parser for JavaScript
2
+
3
+ JavaScript implementation of the Lino protocol parser using Bun and
4
+ Peggy.js parser generator.
5
+
6
+ ## Installation
7
+
8
+ ### Installing from npm
9
+
10
+ Install the package using your preferred package manager:
11
+
12
+ #### Using npm (Node.js)
13
+
14
+ ```bash
15
+ npm install links-notation
16
+ ```
17
+
18
+ #### Using Bun
19
+
20
+ ```bash
21
+ bun add links-notation
22
+ ```
23
+
24
+ #### Using Deno
25
+
26
+ ```typescript
27
+ import { Parser, Link } from "npm:links-notation@^0.6.0";
28
+ ```
29
+
30
+ ### Local Development Setup
31
+
32
+ For contributors working on the source code:
33
+
34
+ #### Using Bun (recommended)
35
+
36
+ ```bash
37
+ cd js
38
+ bun install
39
+ ```
40
+
41
+ #### Using npm
42
+
43
+ ```bash
44
+ cd js
45
+ npm install
46
+ ```
47
+
48
+ ## Build
49
+
50
+ Compile the Peggy.js grammar:
51
+
52
+ ```bash
53
+ bun run build:grammar
54
+ ```
55
+
56
+ Build the project:
57
+
58
+ ```bash
59
+ bun run build
60
+ ```
61
+
62
+ ## Test
63
+
64
+ Run tests:
65
+
66
+ ```bash
67
+ bun test
68
+ ```
69
+
70
+ Watch mode:
71
+
72
+ ```bash
73
+ bun test --watch
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ ### Basic Parsing
79
+
80
+ ```javascript
81
+ import { Parser, Link } from 'links-notation';
82
+
83
+ // Create parser
84
+ const parser = new Parser();
85
+
86
+ // Parse Lino format string
87
+ const input = `papa (lovesMama: loves mama)
88
+ son lovesMama
89
+ daughter lovesMama
90
+ all (love mama)`;
91
+
92
+ const result = parser.parse(input);
93
+ console.log(result);
94
+
95
+ // Access parsed structure
96
+ result.forEach(link => {
97
+ console.log(link.toString());
98
+ });
99
+ ```
100
+
101
+ ### Working with Links
102
+
103
+ ```javascript
104
+ import { Link } from 'links-notation';
105
+
106
+ // Create links programmatically
107
+ const link = new Link('parent', [
108
+ new Link('child1'),
109
+ new Link('child2')
110
+ ]);
111
+
112
+ console.log(link.toString()); // (parent: child1 child2)
113
+
114
+ // Access link properties
115
+ console.log('ID:', link.id);
116
+ console.log('Values:', link.values);
117
+ ```
118
+
119
+ ### Advanced Usage
120
+
121
+ ```javascript
122
+ // Handle nested structures
123
+ const input = `parent
124
+ child1
125
+ child2
126
+ grandchild1
127
+ grandchild2`;
128
+
129
+ const parsed = await parser.parse(input);
130
+
131
+ // Work with groups
132
+ import { LinksGroup } from 'links-notation';
133
+ const group = new LinksGroup(parsed);
134
+ console.log(group.format());
135
+ ```
136
+
137
+ ## Syntax Examples
138
+
139
+ ### Doublets (2-tuple)
140
+
141
+ ```lino
142
+ papa (lovesMama: loves mama)
143
+ son lovesMama
144
+ daughter lovesMama
145
+ all (love mama)
146
+ ```
147
+
148
+ ### Triplets (3-tuple)
149
+
150
+ ```lino
151
+ papa has car
152
+ mama has house
153
+ (papa and mama) are happy
154
+ ```
155
+
156
+ ### N-tuples with References
157
+
158
+ ```lino
159
+ (linksNotation: links notation)
160
+ (This is a linksNotation as well)
161
+ (linksNotation supports (unlimited number (of references) in each link))
162
+ ```
163
+
164
+ ### Indented Structure
165
+
166
+ ```lino
167
+ parent
168
+ child1
169
+ child2
170
+ grandchild1
171
+ grandchild2
172
+ ```
173
+
174
+ ## API Reference
175
+
176
+ ### Classes
177
+
178
+ #### `Parser`
179
+
180
+ Main parser class for converting strings to links.
181
+
182
+ - `initialize()` - Initialize the parser (async)
183
+ - `parse(input)` - Parse a Lino string and return links
184
+
185
+ #### `Link`
186
+
187
+ Represents a single link with ID and values.
188
+
189
+ - `constructor(id, values = [])` - Create a new link
190
+ - `toString()` - Convert link to string format
191
+ - `id` - Link identifier
192
+ - `values` - Array of child values/links
193
+
194
+ #### `LinksGroup`
195
+
196
+ Container for grouping related links.
197
+
198
+ - `constructor(links)` - Create a new group
199
+ - `format()` - Format the group as a string
200
+
201
+ ## Project Structure
202
+
203
+ - `src/grammar.pegjs` - Peggy.js grammar definition
204
+ - `src/Link.js` - Link data structure
205
+ - `src/LinksGroup.js` - Links group container
206
+ - `src/Parser.js` - Parser wrapper
207
+ - `src/index.js` - Main entry point
208
+ - `tests/` - Test files
209
+
210
+ ## Dependencies
211
+
212
+ - Peggy.js (5.0.6) - Parser generator
213
+ - Bun runtime (development)
214
+
215
+ ## Package Information
216
+
217
+ - Package: `links-notation`
218
+ - Version: 0.1.0
219
+ - License: MIT
package/README.ru.md ADDED
@@ -0,0 +1,193 @@
1
+ # Парсер протокола Lino для JavaScript
2
+
3
+ Реализация парсера протокола Lino для JavaScript с использованием Bun и
4
+ генератора парсеров Peggy.js.
5
+
6
+ ## Установка
7
+
8
+ ### Использование Bun (рекомендуется)
9
+
10
+ ```bash
11
+ cd js
12
+ bun install
13
+ ```
14
+
15
+ ### Использование npm
16
+
17
+ ```bash
18
+ cd js
19
+ npm install
20
+ ```
21
+
22
+ ## Сборка
23
+
24
+ Компиляция грамматики Peggy.js:
25
+
26
+ ```bash
27
+ bun run build:grammar
28
+ ```
29
+
30
+ Сборка проекта:
31
+
32
+ ```bash
33
+ bun run build
34
+ ```
35
+
36
+ ## Тестирование
37
+
38
+ Запуск тестов:
39
+
40
+ ```bash
41
+ bun test
42
+ ```
43
+
44
+ Режим наблюдения:
45
+
46
+ ```bash
47
+ bun test --watch
48
+ ```
49
+
50
+ ## Использование
51
+
52
+ ### Базовый парсинг
53
+
54
+ ```javascript
55
+ import { Parser, Link } from 'links-notation';
56
+
57
+ // Создание парсера
58
+ const parser = new Parser();
59
+
60
+ // Парсинг строки в формате Lino
61
+ const input = `папа (любитМаму: любит маму)
62
+ сын любитМаму
63
+ дочь любитМаму
64
+ все (любят маму)`;
65
+
66
+ const result = parser.parse(input);
67
+ console.log(result);
68
+
69
+ // Обращение к распарсенной структуре
70
+ result.forEach(link => {
71
+ console.log(link.toString());
72
+ });
73
+ ```
74
+
75
+ ### Работа со связями
76
+
77
+ ```javascript
78
+ import { Link } from 'links-notation';
79
+
80
+ // Создание связей программно
81
+ const link = new Link('родитель', [
82
+ new Link('ребенок1'),
83
+ new Link('ребенок2')
84
+ ]);
85
+
86
+ console.log(link.toString()); // (родитель: ребенок1 ребенок2)
87
+
88
+ // Доступ к свойствам связи
89
+ console.log('ID:', link.id);
90
+ console.log('Значения:', link.values);
91
+ ```
92
+
93
+ ### Расширенное использование
94
+
95
+ ```javascript
96
+ // Обработка вложенных структур
97
+ const input = `родитель
98
+ ребенок1
99
+ ребенок2
100
+ внук1
101
+ внук2`;
102
+
103
+ const parsed = await parser.parse(input);
104
+
105
+ // Работа с группами
106
+ import { LinksGroup } from 'links-notation';
107
+ const group = new LinksGroup(parsed);
108
+ console.log(group.format());
109
+ ```
110
+
111
+ ## Примеры синтаксиса
112
+
113
+ ### Дуплеты (2-кортежи)
114
+
115
+ ```lino
116
+ папа (любитМаму: любит маму)
117
+ сын любитМаму
118
+ дочь любитМаму
119
+ все (любят маму)
120
+ ```
121
+
122
+ ### Триплеты (3-кортежи)
123
+
124
+ ```lino
125
+ папа имеет машину
126
+ мама имеет дом
127
+ (папа и мама) счастливы
128
+ ```
129
+
130
+ ### N-кортежи со ссылками
131
+
132
+ ```lino
133
+ (нотацияСвязей: нотация связей)
134
+ (Это тоже нотацияСвязей)
135
+ (нотацияСвязей поддерживает (неограниченное количество (ссылок) в каждой связи))
136
+ ```
137
+
138
+ ### Структура с отступами
139
+
140
+ ```lino
141
+ родитель
142
+ ребенок1
143
+ ребенок2
144
+ внук1
145
+ внук2
146
+ ```
147
+
148
+ ## Справочник API
149
+
150
+ ### Классы
151
+
152
+ #### `Parser`
153
+
154
+ Основной класс парсера для преобразования строк в связи.
155
+
156
+ - `initialize()` - Инициализация парсера (асинхронно)
157
+ - `parse(input)` - Парсинг строки Lino и возвращение связей
158
+
159
+ #### `Link`
160
+
161
+ Представляет одну связь с ID и значениями.
162
+
163
+ - `constructor(id, values = [])` - Создание новой связи
164
+ - `toString()` - Преобразование связи в строковый формат
165
+ - `id` - Идентификатор связи
166
+ - `values` - Массив дочерних значений/связей
167
+
168
+ #### `LinksGroup`
169
+
170
+ Контейнер для группировки связанных связей.
171
+
172
+ - `constructor(links)` - Создание новой группы
173
+ - `format()` - Форматирование группы в строку
174
+
175
+ ## Структура проекта
176
+
177
+ - `src/grammar.pegjs` - Определение грамматики Peggy.js
178
+ - `src/Link.js` - Структура данных связи
179
+ - `src/LinksGroup.js` - Контейнер групп связей
180
+ - `src/Parser.js` - Обертка парсера
181
+ - `src/index.js` - Главная точка входа
182
+ - `tests/` - Файлы тестов
183
+
184
+ ## Зависимости
185
+
186
+ - Peggy.js (5.0.6) - Генератор парсеров
187
+ - Среда выполнения Bun (разработка)
188
+
189
+ ## Информация о пакете
190
+
191
+ - Пакет: `links-notation`
192
+ - Версия: 0.1.0
193
+ - Лицензия: MIT
package/bun.lock ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "workspaces": {
4
+ "": {
5
+ "name": "@linksplatform/protocols-lino",
6
+ "devDependencies": {
7
+ "bun-types": "^1.2.19",
8
+ "peggy": "^5.0.6",
9
+ },
10
+ },
11
+ },
12
+ "packages": {
13
+ "@peggyjs/from-mem": ["@peggyjs/from-mem@3.1.1", "", { "dependencies": { "semver": "7.7.2" } }, "sha512-m5OEjgJaePWpyNtQCvRZkpLoV+z44eh6QIO9yEwQuOThdUdkECO3wcKLT3tFA3H8WM5bxU/K/dpmo7r/X16UEw=="],
14
+
15
+ "@types/node": ["@types/node@24.2.1", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-DRh5K+ka5eJic8CjH7td8QpYEV6Zo10gfRkjHCO3weqZHWDtAaSTFtl4+VMqOJ4N5jcuhZ9/l+yy8rVgw7BQeQ=="],
16
+
17
+ "@types/react": ["@types/react@19.1.9", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-WmdoynAX8Stew/36uTSVMcLJJ1KRh6L3IZRx1PZ7qJtBqT3dYTgyDTx8H1qoRghErydW7xw9mSJ3wS//tCRpFA=="],
18
+
19
+ "bun-types": ["bun-types@1.2.19", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-uAOTaZSPuYsWIXRpj7o56Let0g/wjihKCkeRqUBhlLVM/Bt+Fj9xTo+LhC1OV1XDaGkz4hNC80et5xgy+9KTHQ=="],
20
+
21
+ "commander": ["commander@14.0.0", "", {}, "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA=="],
22
+
23
+ "csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
24
+
25
+ "peggy": ["peggy@5.0.6", "", { "dependencies": { "@peggyjs/from-mem": "3.1.1", "commander": "^14.0.0", "source-map-generator": "2.0.2" }, "bin": { "peggy": "bin/peggy.js" } }, "sha512-Sud8Zus0JAgE+U4zwkJv29OOaXhviFI7J90/6cGfy3OoqR8dpnieeF9a46dj0bTtqiFnrFatldA6ltQyOJvNmg=="],
26
+
27
+ "semver": ["semver@7.7.2", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA=="],
28
+
29
+ "source-map-generator": ["source-map-generator@2.0.2", "", {}, "sha512-unCl5BQhF/us51DiT7SvlSY3QUPhyfAdHJxd8l7FXdwzqxli0UDMV2dEuei2SeGp3Z4rB/AJ9zKi1mGOp2K2ww=="],
30
+
31
+ "undici-types": ["undici-types@7.10.0", "", {}, "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag=="],
32
+ }
33
+ }