Python implementation of the Links Notation parser.
pip install links-notationfrom links_notation import Parser
parser = Parser()
links = parser.parse("papa (lovesMama: loves mama)")
# Access parsed links
for link in links:
print(link)from links_notation 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)from links_notation 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)parser = Parser()
# Parse indented notation
text = """3:
papa
loves
mama"""
links = parser.parse(text)
# Produces: (3: papa loves mama)The main parser class for Links Notation.
parse(input_text: str) -> List[Link]: Parse Links Notation text into Link objects
Represents a link in Links 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 a list of links into Links Notation.
format_links(links: List[Link], less_parentheses: bool = False) -> str
parser = Parser()
text = """
papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
"""
links = parser.parse(text)text = """
papa has car
mama has house
(papa and mama) are happy
"""
links = parser.parse(text)# References with special characters need quotes
text = '("has space": "value with: colon")'
links = parser.parse(text)# Install development dependencies
pip install pytest
# Run tests
pytestpip install build
python -m buildThis project uses Black for code formatting, isort for import sorting, and flake8 for linting.
Install linting tools:
pip install ".[lint]"
# Or install all dev dependencies
pip install ".[dev]"black .
isort .black --check --diff .
isort --check-only --diff .
flake8 --max-line-length=120These checks are enforced in CI. Pull requests with unformatted code will fail the lint check.
This project uses pre-commit hooks that automatically run Black, isort, and flake8 before commits. To set up pre-commit hooks locally:
# From repository root
pip install pre-commit
pre-commit installThis project is released into the public domain under the Unlicense.