Skip to main content

EBNF grammar and parser for the Winding Markdown extension

Project description

Winding Markdown Extension

Winding is a grammar, AST and parser for the Winding Markdown extension. This extension enhances Markdown, allowing to specify scenes, layout and agentic behaviours.

Features

  • Defines a clear and concise EBNF grammar for the Winding Markdown extension.
  • Defines a pure Python parser, based on the Lark standalone parser.
  • Defines AST and WindingTransformer, to facilitate the parsing.
  • No external dependencies required.

Installation

You can install the Winding module from PyPI using pip:

pip install winding

Usage

You can find runnable examples in the samples/ directory.

Here is a simple example of printing the grammar:

>>> from winding import grammar
>>> print(grammar)

start: (winding | markdown)+

winding: meta_winding | space_winding | inline_winding
meta_winding: "---\n" IDENTIFIER ":" attributes header_winding* "\n---\n" content? 
space_winding: "--\n" IDENTIFIER ":" attributes header_winding* "\n--\n" content?
header_winding: "\n" IDENTIFIER ":" attributes
inline_winding: "@" IDENTIFIER ":" attributes "\n" content?

content: (winding | markdown)+

markdown: (image | TEXT)+

attributes: (IDENTIFIER ("," IDENTIFIER)*)?

image: "![" CAPTION? "]" "(" URI? ")"

IDENTIFIER: /!?[A-Za-z][A-Za-z0-9_.-]*/
URI: /[^\)\n]+/
TEXT: /(?:(?!@\w+:|--|!\[).)*\n+/ 
CAPTION: /[^\]]+/
    
%ignore /[ \t]+/
%ignore "\r" 

Example of parsing a Winding Markdown file

See samples/dragon.py for a complete example.

from winding.parser import Lark_StandAlone
from winding.transformer import WindingTransformer
from winding.ast import Winding
from pprint import pprint

parser = Lark_StandAlone()
sample = """---
dragons: portrait-oriented
---
A book about dragons

--
front-cover: portrait-oriented
--
Dragons

@center: large, landscape-oriented
![Flying Wind Dragon](dragon.png)
"""

tree = parser.parse(sample)
ast = WindingTransformer().transform(tree)
pprint(ast, indent=2)

This will output the following AST:

Winding(at='this',
    attributes=[],
    content=[ 
        Winding(at='dragons',
            attributes=['portrait-oriented'],
            content=[ 
                Markdown(content='A book about dragons\n\n'),
                Winding(at='front-cover', attributes=['portrait-oriented'],
                    content=[ 
                        Markdown(content='Dragons\n\n'),
                        Winding(at='center', attributes=['large', 'landscape-oriented'],
                            content=[Markdown(content=Image(caption='Flying Wind Dragon',
                                               url='dragon.png')),
                                     Markdown(content='\n')]
                                )])])])

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

winding-0.2.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

winding-0.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file winding-0.2.0.tar.gz.

File metadata

  • Download URL: winding-0.2.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for winding-0.2.0.tar.gz
Algorithm Hash digest
SHA256 305d63ec10b8d00d5e92f94f2f897faeb8689fc0474ca0b4d17c2ee76bdca2fb
MD5 b52617d82ae42eadec1fbd1ea4bd85db
BLAKE2b-256 70c040bb6a43d9395b481e903b3f941bab5fa5167dbc1d5b30e005ca1e8287a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for winding-0.2.0.tar.gz:

Publisher: workflow.yaml on Wind-WindKids/winding

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file winding-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: winding-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for winding-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb85f3c52d4c1b9e297beac6e7c8f037148f6c0c4257ab9125bb22511b8f0b3f
MD5 6584796c47e04fb71c705afcbf600498
BLAKE2b-256 ee66997076f91b9549a8e913f4b22f0811dd72c42382e1fef15c470c4e29db3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for winding-0.2.0-py3-none-any.whl:

Publisher: workflow.yaml on Wind-WindKids/winding

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page