Python implementation of the Lino protocol parser
Project description
Platform.Protocols.Lino - Python
Python implementation of the Lino (Links Notation) protocol parser.
Installation
pip install platform-lino
Quick Start
from platform_lino import Parser
parser = Parser()
links = parser.parse("papa (lovesMama: loves mama)")
# Access parsed links
for link in links:
print(link)
Usage
Basic Parsing
from platform_lino import Parser, format_links
parser = Parser()
# Parse simple links
links = parser.parse("(papa: loves mama)")
print(links[0].id) # 'papa'
print(len(links[0].values)) # 2
# Format links back to string
output = format_links(links)
print(output) # (papa: loves mama)
Working with Link Objects
from platform_lino import Link
# Create links programmatically
link = Link('parent', [Link('child1'), Link('child2')])
print(str(link)) # (parent: child1 child2)
# Access link properties
print(link.id) # 'parent'
print(link.values[0].id) # 'child1'
# Combine links
combined = link.combine(Link('another'))
print(str(combined)) # ((parent: child1 child2) another)
Indented Syntax
parser = Parser()
# Parse indented notation
text = """3:
papa
loves
mama"""
links = parser.parse(text)
# Produces: (3: papa loves mama)
API Reference
Parser
The main parser class for Lino notation.
parse(input_text: str) -> List[Link]: Parse Lino text into Link objects
Link
Represents a link in Lino notation.
__init__(id: Optional[str] = None, values: Optional[List[Link]] = None)format(less_parentheses: bool = False) -> str: Format as stringsimplify() -> Link: Simplify link structurecombine(other: Link) -> Link: Combine with another link
format_links
Format a list of links into Lino notation.
format_links(links: List[Link], less_parentheses: bool = False) -> str
Examples
Doublets (2-tuple)
parser = Parser()
text = """
papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
"""
links = parser.parse(text)
Triplets (3-tuple)
text = """
papa has car
mama has house
(papa and mama) are happy
"""
links = parser.parse(text)
Quoted References
# References with special characters need quotes
text = '("has space": "value with: colon")'
links = parser.parse(text)
Development
Running Tests
# Install development dependencies
pip install pytest
# Run tests
pytest
Building
pip install build
python -m build
License
This project is released into the public domain under the Unlicense.
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file links_notation-0.9.0.tar.gz.
File metadata
- Download URL: links_notation-0.9.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d0e3a7971733a43fb0e9e6d5bc5666b23146d0ea442dc5b22742b4d4941cdf7
|
|
| MD5 |
81313869014e3d90850fa979a27d26a9
|
|
| BLAKE2b-256 |
0549a3caf51cad936970379166ce35448c64ed0eaaa88db95674d1f11d8e49ce
|
File details
Details for the file links_notation-0.9.0-py3-none-any.whl.
File metadata
- Download URL: links_notation-0.9.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eee308f45f4d4884e4e501a5dfe217e2cc97baa72b6eec5b2aa10b25f7cd6b2b
|
|
| MD5 |
d9b51360b50dccf03907b882f83e6e12
|
|
| BLAKE2b-256 |
93339037aeff8ac8a5cc009b3f50cf10c399772a3a5422d8901cf75ee8da757d
|