Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KOLANICH committed Oct 13, 2023
0 parents commit 48c0606
Show file tree
Hide file tree
Showing 27 changed files with 1,701 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
end_of_line = lf

[*.{yml,yaml}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .github/.templateMarker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KOLANICH/python_project_boilerplate.py
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "all"
15 changes: 15 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: typical python workflow
uses: KOLANICH-GHActions/typical-python-workflow@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__pycache__
*.pyc
*.pyo
/*.egg-info
/build
/dist
/.eggs
/monkeytype.sqlite3
/*.srctrldb
/*.srctrlbm
/*.srctrlprj
1 change: 1 addition & 0 deletions Code_Of_Conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No codes of conduct!
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include UNLICENSE
include *.md
exclude tests
include .editorconfig
global-include *.json
global-include *.pglr
global-include *.pgt
global-include *.parsimonious
global-include *.ebnf
33 changes: 33 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pyMetakitDefinitionString [![Unlicensed work](https://raw.githubusercontent.com/unlicense/unlicense.org/master/static/favicon.png)](https://unlicense.org/)
=========================
~~[wheel (GHA via `nightly.link`)](https://nightly.link/prebuilder/pyMetakitDefinitionString/workflows/CI/master/pyMetakitDefinitionString-0.CI-py3-none-any.whl)~~
~~[![GitHub Actions](https://github.com/prebuilder/pyMetakitDefinitionString/workflows/CI/badge.svg)](https://github.com/prebuilder/pyMetakitDefinitionString/actions/)~~
[![Libraries.io Status](https://img.shields.io/librariesio/github/prebuilder/pyMetakitDefinitionString.svg)](https://libraries.io/github/prebuilder/pyMetakitDefinitionString)
[![Code style: antiflash](https://img.shields.io/badge/code%20style-antiflash-FFF.svg)](https://codeberg.org/KOLANICH-tools/antiflash.py)

Parses metakit definition string.

Usage
-----

```python
import pyMetakitDefinitionString

d = pyMetakitDefinitionString.parse("people[first:S,last:S,shoesize:I],text[line:S]")
print(d)
```

```
[
view<name='people', bodyF=[scalar<name='first', typeF='S'>, scalar<name='last', typeF='S'>, scalar<name='shoesize', typeF='I'>]>,
view<name='text', bodyF=[scalar<name='line', typeF='S'>]>
]
```

Interpretation of `typeF` is up to you since adding a enum will not spare you from having a look-up table. [See the docs.](https://codeberg.org/prebuilder/metakit/blob/master/doc/format.html#L155-L161)


Requirements
------------
* [UniGrammarRuntime](https://codeberg.org/UniGrammar/UniGrammarRuntime.py)
* Any of the backends for which parsers have been generated. [`parsimonious`](https://github.com/erikrose/parsimonious) is recommended, as it was benchmarked as the fastest one.
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org/>
1 change: 1 addition & 0 deletions parserBundle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./pyMetakitDefinitionString/parserBundle/
17 changes: 17 additions & 0 deletions pyMetakitDefinitionString/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
__all__ = ("parse",)

from pathlib import Path

from UniGrammarRuntime.ParserBundle import ParserBundle

thisFile = Path(__file__).absolute()
thisDir = thisFile.parent
bundleDir = thisDir / "parserBundle"

bundle = ParserBundle(bundleDir)

grammar = bundle.grammars["metakit4_definition_string"]
wrapper = grammar.getWrapper() # put backend name, by default it selects the fastest one


parse = wrapper
9 changes: 9 additions & 0 deletions pyMetakitDefinitionString/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys

if __name__ == "__main__":
from pprint import pprint

from . import parse

for el in sys.argv[1:]:
pprint(parse(el))
Loading

0 comments on commit 48c0606

Please sign in to comment.