Skip to content

Commit 037fc23

Browse files
authored
Merge pull request #82 from linksplatform/issue-55-deaa6f4c
Add feature comparison: YAML vs XML vs JSON vs LINO
2 parents 203b7cf + de12c2c commit 037fc23

File tree

11 files changed

+412
-72
lines changed

11 files changed

+412
-72
lines changed

.codacy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
engines:
3+
markdownlint:
4+
enabled: true
5+
exclude_paths:
6+
- 'FEATURE_COMPARISON.md'
7+
8+
exclude_paths:
9+
- '.codacy.yml'

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"default": true,
3+
"MD041": false
4+
}

FEATURE_COMPARISON.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Feature Comparison
2+
3+
This document compares YAML, XML, JSON, and LINO data serialization
4+
formats, with a focus on cyclic reference support as requested in
5+
[issue #55](https://github.com/linksplatform/Protocols.Lino/issues/55).
6+
7+
## Cyclic References Support
8+
9+
### YAML
10+
11+
**Support Level**: ❌ **Limited** - Anchors and aliases only
12+
13+
YAML supports repeated nodes through anchors (&) and aliases (*), but
14+
has significant limitations:
15+
16+
- **Anchors** (&) define a value that can be referenced later
17+
- **Aliases** (*) reference previously defined anchors
18+
- **Limitation**: Anchors must be defined before they can be referenced
19+
- **No True Cycles**: Cannot create A→B→A circular references directly
20+
- **Forward References**: Not supported - aliases cannot reference
21+
anchors defined later
22+
23+
**Example**:
24+
25+
```yaml
26+
# Valid: Simple reference
27+
defaults: &defaults
28+
timeout: 30
29+
retries: 3
30+
31+
production:
32+
<<: *defaults
33+
host: prod.example.com
34+
35+
# Invalid: Cannot create true cycles
36+
# node_a: &a
37+
# ref: *b # Error: 'b' not yet defined
38+
# node_b: &b
39+
# ref: *a
40+
```
41+
42+
### XML
43+
44+
**Support Level**: ❌ **Very Limited** - Through external mechanisms only
45+
46+
XML itself has no built-in support for cyclic references:
47+
48+
- **XPointer/XPath**: Can reference other parts of documents, but
49+
primarily for addressing
50+
- **IDREF/ID**: Allows references within documents, but limited scope
51+
- **XInclude**: For including external documents, not for cycles
52+
- **No Native Cycles**: Standard XML serialization cannot represent
53+
object graphs with cycles
54+
- **External Solutions**: Some XML processors provide custom extensions
55+
56+
**Example**:
57+
58+
```xml
59+
<!-- Limited IDREF support -->
60+
<people>
61+
<person id="john" friend-ref="jane"/>
62+
<person id="jane" friend-ref="john"/>
63+
</people>
64+
65+
<!-- But cannot serialize complex object graphs with cycles -->
66+
```
67+
68+
### JSON
69+
70+
**Support Level**: ❌ **No Native Support**
71+
72+
JSON has fundamental limitations for cyclic references:
73+
74+
- **Tree Structure Only**: JSON represents hierarchical data, not graphs
75+
- **Serialization Issues**: `JSON.stringify()` throws errors on cycles
76+
- **JSON Schema**: Can define references ($ref) but for schema
77+
composition, not data cycles
78+
- **JSON Pointer**: For addressing within documents, not for cycles
79+
- **Workarounds**: External libraries provide cycle detection/replacement
80+
81+
**Example**:
82+
83+
```javascript
84+
// This fails:
85+
const obj = { name: "A" };
86+
obj.self = obj; // Creates cycle
87+
JSON.stringify(obj); // TypeError: circular structure
88+
89+
// JSON Schema $ref is for schema composition, not data cycles:
90+
{
91+
"$ref": "#/definitions/person", // References schema definition
92+
"definitions": {
93+
"person": { "type": "object" }
94+
}
95+
}
96+
```
97+
98+
### LINO (Links Notation)
99+
100+
**Support Level**: ✅ **Full Native Support**
101+
102+
LINO is specifically designed to represent linked data structures and
103+
naturally supports cyclic references:
104+
105+
- **Link-Based Structure**: Every element can reference any other link by identifier
106+
- **Bidirectional Links**: Links can reference each other freely
107+
- **Complex Graphs**: Can represent any graph structure including cycles
108+
- **Natural Syntax**: Cycles emerge naturally from the link reference system
109+
- **No Special Syntax**: No additional constructs needed for cycles
110+
111+
**Examples**:
112+
113+
```lino
114+
// Simple bidirectional relationship
115+
john (friend: jane)
116+
jane (friend: john)
117+
118+
// Complex cycle in family relationships
119+
alice (mother: bob)
120+
bob (son: alice, father: carol)
121+
carol (daughter: alice, mother: bob)
122+
123+
// Self-reference
124+
recursive_function (calls: recursive_function)
125+
126+
// Multi-level cycles in data structures
127+
node_a (next: node_b)
128+
node_b (next: node_c)
129+
node_c (next: node_a, data: "cycle complete")
130+
```
131+
132+
## Detailed Feature Comparison
133+
134+
| Feature | YAML | XML | JSON | LINO |
135+
|---------|------|-----|------|------|
136+
| **Cyclic References** | ❌ Limited | ❌ Very Limited | ❌ None | ✅ Full |
137+
| **Forward References** | ❌ No | ❌ Limited | ❌ No | ✅ Yes |
138+
| **Bidirectional Links** | ❌ No | ❌ Manual | ❌ No | ✅ Native |
139+
| **Graph Structures** | ❌ Trees | ❌ Trees | ❌ Trees | ✅ Full Graphs |
140+
| **Ref Syntax** | `&anchor *alias` | `id="x" ref="x"` | `$ref` | `identifier` |
141+
| **Self-Reference** | ❌ No | ❌ Manual | ❌ No | ✅ Yes |
142+
| **Complex Cycles** | ❌ No | ❌ No | ❌ No | ✅ Yes |
143+
| **Serialization** | ✅ Safe | ✅ Safe | ❌ Fails on cycles | ✅ Native |
144+
145+
## Use Case Analysis
146+
147+
### When Cyclic References Matter
148+
149+
1. **Object-Relational Mapping**: Database entities with bidirectional relationships
150+
2. **Graph Algorithms**: Representing networks, social graphs, dependency graphs
151+
3. **Recursive Data Structures**: Linked lists, trees with parent pointers
152+
4. **State Machines**: States that reference each other
153+
5. **Document Cross-References**: Academic papers, legal documents
154+
6. **Family Trees**: Genealogical data with marriages and relationships
155+
156+
### Format Recommendations
157+
158+
- **YAML**: Good for configuration files, simple hierarchical data
159+
- **XML**: Good for document markup, when schema validation is important
160+
- **JSON**: Good for web APIs, simple data exchange, when cycles aren't needed
161+
- **LINO**: Ideal for linked data, knowledge graphs, any data with natural relationships
162+
163+
## Technical Implementation Notes
164+
165+
### YAML Limitations in Practice
166+
167+
```yaml
168+
# This creates a parsing error in most YAML processors:
169+
# parent: &parent
170+
# children:
171+
# - child: &child
172+
# parent: *parent # Circular reference
173+
```
174+
175+
### XML Workarounds
176+
177+
```xml
178+
<!-- Requires custom processing to resolve relationships -->
179+
<graph>
180+
<nodes>
181+
<node id="1" name="A"/>
182+
<node id="2" name="B"/>
183+
</nodes>
184+
<edges>
185+
<edge from="1" to="2"/>
186+
<edge from="2" to="1"/> <!-- Creates cycle -->
187+
</edges>
188+
</graph>
189+
```
190+
191+
### JSON Alternatives
192+
193+
```javascript
194+
// Libraries like 'circular-json' provide workarounds:
195+
const CircularJSON = require('circular-json');
196+
const obj = { name: "A" };
197+
obj.self = obj;
198+
const serialized = CircularJSON.stringify(obj);
199+
```
200+
201+
### LINO Natural Cycles
202+
203+
```lino
204+
// No special handling needed - cycles are natural:
205+
parent (children: child1 child2)
206+
child1 (parent: parent, sibling: child2)
207+
child2 (parent: parent, sibling: child1)
208+
209+
// Even complex multi-level cycles work seamlessly:
210+
company (employees: john jane)
211+
john (employer: company, manager: jane, reports: jane)
212+
jane (employer: company, manager: john, reports: john)
213+
```
214+
215+
## Conclusion
216+
217+
For applications requiring cyclic references, LINO provides the most
218+
natural and complete solution. While YAML, XML, and JSON can handle
219+
simple hierarchical data effectively, they require workarounds or
220+
external libraries to handle cycles, often with significant complexity
221+
or limitations.
222+
223+
LINO's link-based design makes it uniquely suited for representing
224+
interconnected data where relationships are as important as the data
225+
itself.

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# [Protocols.Lino](https://github.com/linksplatform/Protocols.Lino) (languages: en • [ru](README.ru.md))
22

3-
43
| [![Actions Status](https://github.com/linksplatform/Protocols.Lino/workflows/js/badge.svg)](https://github.com/linksplatform/Protocols.Lino/actions?workflow=js) | [![npm Version and Downloads count](https://img.shields.io/npm/v/@linksplatform/protocols-lino?label=npm&style=flat)](https://www.npmjs.com/package/@linksplatform/protocols-lino) | **[JavaScript](js/README.md)** |
54
|:-|-:|:-|
65
| [![Actions Status](https://github.com/linksplatform/Protocols.Lino/workflows/rust/badge.svg)](https://github.com/linksplatform/Protocols.Lino/actions?workflow=rust) | [![Crates.io Version and Downloads count](https://img.shields.io/crates/v/platform-lino?label=crates.io&style=flat)](https://crates.io/crates/platform-lino) | **[Rust](rust/README.md)** |
@@ -16,37 +15,45 @@ LinksPlatform's Platform.Protocols.Lino Class Library.
1615

1716
![introduction](https://github.com/linksplatform/Documentation/raw/master/doc/Examples/json_xml_lino_comparison/b%26w.png "json, xml and lino comparison")
1817

19-
This library gives you an ability to convert any string that contains links notation into a list of links and back to the string after modifications are made.
18+
This library gives you an ability to convert any string that contains
19+
links notation into a list of links and back to the string after
20+
modifications are made.
2021

21-
Links notation is based on two concepts references and links. Each reference references other link. The notation supports links with any number of references to other links.
22+
Links notation is based on two concepts references and links. Each
23+
reference references other link. The notation supports links with any
24+
number of references to other links.
2225

2326
## Quick Start
2427

25-
### C#
28+
### C&#35;
29+
2630
```csharp
2731
var parser = new Platform.Protocols.Lino.Parser();
2832
var links = parser.Parse("papa (lovesMama: loves mama)");
2933
```
3034

3135
### JavaScript
36+
3237
```javascript
3338
import { Parser } from '@linksplatform/protocols-lino';
3439
const parser = new Parser();
3540
const links = parser.parse("papa (lovesMama: loves mama)");
3641
```
3742

3843
### Rust
44+
3945
```rust
4046
use lino::parse_lino;
4147
let links = parse_lino("papa (lovesMama: loves mama)").unwrap();
4248
```
4349

4450
## Examples
51+
4552
### Links notation (lino)
4653

4754
#### Doublets (2-tuple)
4855

49-
```
56+
```lino
5057
papa (lovesMama: loves mama)
5158
son lovesMama
5259
daughter lovesMama
@@ -55,15 +62,15 @@ all (love mama)
5562

5663
#### Triplets (3-tuple)
5764

58-
```
65+
```lino
5966
papa has car
6067
mama has house
6168
(papa and mama) are happy
6269
```
6370

6471
#### Sequences (N-tuple)
6572

66-
```
73+
```lino
6774
I'm a friendly AI.
6875
(I'm a friendly AI too.)
6976
(linksNotation: links notation)
@@ -73,30 +80,41 @@ I'm a friendly AI.
7380
parentheses may be ommitted if the whole line is a single link
7481
```
7582

76-
So that means that *this* text is also links notation. So most of the text in the world already may be parsed as links notation. That makes links notation the most easy an natural/intuitive/native one.
83+
So that means that *this* text is also links notation. So most of the
84+
text in the world already may be parsed as links notation. That makes
85+
links notation the most easy an natural/intuitive/native one.
7786

7887
## What is Links Notation?
7988

80-
Links Notation (Lino) is a simple, intuitive format for representing structured data as links between entities. It's designed to be:
89+
Links Notation (Lino) is a simple, intuitive format for representing
90+
structured data as links between entities. It's designed to be:
8191

8292
- **Natural**: Most text can already be parsed as links notation
8393
- **Flexible**: Supports any number of references in each link
8494
- **Universal**: Can represent doublets, triplets, and N-tuples
8595
- **Hierarchical**: Supports nested structures with indentation
8696

8797
The notation uses two core concepts:
98+
8899
- **References**: Points to other links (like variables or identifiers)
89100
- **Links**: Connect references together with optional identifiers
90101

91102
## Documentation
92103

93-
For detailed implementation guides and API references, see the language-specific documentation:
104+
For detailed implementation guides and API references, see the
105+
language-specific documentation:
94106

95-
- **[C# Documentation](https://linksplatform.github.io/Protocols.Lino/csharp/api/Platform.Protocols.Lino.html)** - Complete API reference
107+
- **[C# Documentation](https://linksplatform.github.io/Protocols.Lino/csharp/api/Platform.Protocols.Lino.html)**
108+
\- Complete API reference
96109
- **[C# README](csharp/README.md)** - Installation and usage guide
97-
- **[JavaScript README](js/README.md)** - Modern web development guide
110+
- **[JavaScript README](js/README.md)** - Modern web development guide
98111
- **[Rust README](rust/README.md)** - High-performance parsing guide
99112

100113
Additional resources:
101-
- [PDF Documentation](https://linksplatform.github.io/Protocols.Lino/csharp/Platform.Protocols.Lino.pdf) - Complete reference for offline reading
102-
- [Links Theory 0.0.2](https://habr.com/en/articles/895896) - Theoretical foundation that Links Notation fully supports
114+
115+
- [Feature Comparison](FEATURE_COMPARISON.md) - LINO vs YAML/XML/JSON
116+
feature analysis
117+
- [PDF Documentation](https://linksplatform.github.io/Protocols.Lino/csharp/Platform.Protocols.Lino.pdf)
118+
\- Complete reference for offline reading
119+
- [Links Theory 0.0.2](https://habr.com/en/articles/895896) - Theoretical
120+
foundation that Links Notation fully supports

0 commit comments

Comments
 (0)