logic-asts 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- logic_asts-1.1.0/.envrc.recommended +11 -0
- logic_asts-1.1.0/.github/workflows/pypi.yml +74 -0
- logic_asts-1.1.0/.gitignore +176 -0
- logic_asts-1.1.0/.python-version +1 -0
- logic_asts-1.1.0/Makefile +33 -0
- logic_asts-1.1.0/PKG-INFO +34 -0
- logic_asts-1.1.0/README.md +23 -0
- logic_asts-1.1.0/pyproject.toml +47 -0
- logic_asts-1.1.0/src/logic_asts/__init__.py +28 -0
- logic_asts-1.1.0/src/logic_asts/base.py +400 -0
- logic_asts-1.1.0/src/logic_asts/grammars/__init__.py +276 -0
- logic_asts-1.1.0/src/logic_asts/grammars/base.lark +34 -0
- logic_asts-1.1.0/src/logic_asts/grammars/ltl.lark +23 -0
- logic_asts-1.1.0/src/logic_asts/grammars/stl_go.lark +39 -0
- logic_asts-1.1.0/src/logic_asts/grammars/strel.lark +32 -0
- logic_asts-1.1.0/src/logic_asts/ltl.py +252 -0
- logic_asts-1.1.0/src/logic_asts/py.typed +0 -0
- logic_asts-1.1.0/src/logic_asts/stl_go.py +251 -0
- logic_asts-1.1.0/src/logic_asts/strel.py +182 -0
- logic_asts-1.1.0/src/logic_asts/utils.py +32 -0
- logic_asts-1.1.0/tests/test_base_logic.py +47 -0
- logic_asts-1.1.0/tests/test_ltl.py +57 -0
- logic_asts-1.1.0/tests/test_stl_go.py +442 -0
- logic_asts-1.1.0/tests/test_strel.py +38 -0
- logic_asts-1.1.0/uv.lock +518 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
name: "Test, build, and deploy Python package"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main]
|
|
6
|
+
push:
|
|
7
|
+
branches: [main]
|
|
8
|
+
tags:
|
|
9
|
+
- v*
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
name: Test package
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
strategy:
|
|
18
|
+
fail-fast: false
|
|
19
|
+
matrix:
|
|
20
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
# checkout@v4.2.2
|
|
24
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
|
25
|
+
# setup-uv@v6.0.1
|
|
26
|
+
- uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca
|
|
27
|
+
with:
|
|
28
|
+
version: "latest"
|
|
29
|
+
python-version: ${{ matrix.python-version }}
|
|
30
|
+
- name: lint
|
|
31
|
+
run: uv run --frozen --dev ruff check .
|
|
32
|
+
- name: format
|
|
33
|
+
run: uv run --frozen --dev ruff format --check .
|
|
34
|
+
- name: Test with Python ${{ matrix.python-version }}
|
|
35
|
+
run: uv run --frozen --dev pytest
|
|
36
|
+
- name: Run type checker with Python
|
|
37
|
+
run: uv run --frozen --dev mypy src tests
|
|
38
|
+
|
|
39
|
+
release-build:
|
|
40
|
+
name: Build and release package
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
needs:
|
|
43
|
+
- test
|
|
44
|
+
permissions:
|
|
45
|
+
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
46
|
+
id-token: write
|
|
47
|
+
|
|
48
|
+
# Dedicated environments with protections for publishing are strongly recommended.
|
|
49
|
+
environment:
|
|
50
|
+
name: pypi
|
|
51
|
+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
|
|
52
|
+
url: https://pypi.org/p/logic-asts
|
|
53
|
+
|
|
54
|
+
if: "startsWith(github.ref, 'refs/tags/')"
|
|
55
|
+
|
|
56
|
+
steps:
|
|
57
|
+
# checkout@v4.2.2
|
|
58
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
|
59
|
+
# setup-uv@v6.0.1
|
|
60
|
+
- uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca
|
|
61
|
+
with:
|
|
62
|
+
version: "latest"
|
|
63
|
+
- name: Install dependencies
|
|
64
|
+
run: uv sync
|
|
65
|
+
- name: Build wheels and sdist
|
|
66
|
+
run: uv build
|
|
67
|
+
- name: Upload wheels and sdist
|
|
68
|
+
# upload-artifact@v4.6.2
|
|
69
|
+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
|
|
70
|
+
with:
|
|
71
|
+
name: release-dists
|
|
72
|
+
path: dist/
|
|
73
|
+
- name: Publish release distributions to PyPI
|
|
74
|
+
run: uv publish
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Created by https://www.toptal.com/developers/gitignore/api/python
|
|
2
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
|
3
|
+
|
|
4
|
+
### Python ###
|
|
5
|
+
# Byte-compiled / optimized / DLL files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
|
|
10
|
+
# C extensions
|
|
11
|
+
*.so
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
.Python
|
|
15
|
+
build/
|
|
16
|
+
develop-eggs/
|
|
17
|
+
dist/
|
|
18
|
+
downloads/
|
|
19
|
+
eggs/
|
|
20
|
+
.eggs/
|
|
21
|
+
lib/
|
|
22
|
+
lib64/
|
|
23
|
+
parts/
|
|
24
|
+
sdist/
|
|
25
|
+
var/
|
|
26
|
+
wheels/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py,cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
cover/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# Sphinx documentation
|
|
76
|
+
docs/_build/
|
|
77
|
+
|
|
78
|
+
# PyBuilder
|
|
79
|
+
.pybuilder/
|
|
80
|
+
target/
|
|
81
|
+
|
|
82
|
+
# Jupyter Notebook
|
|
83
|
+
.ipynb_checkpoints
|
|
84
|
+
|
|
85
|
+
# IPython
|
|
86
|
+
profile_default/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
|
|
89
|
+
# pyenv
|
|
90
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
91
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
92
|
+
# .python-version
|
|
93
|
+
|
|
94
|
+
# pipenv
|
|
95
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
96
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
97
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
98
|
+
# install all needed dependencies.
|
|
99
|
+
#Pipfile.lock
|
|
100
|
+
|
|
101
|
+
# poetry
|
|
102
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
103
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
104
|
+
# commonly ignored for libraries.
|
|
105
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
106
|
+
#poetry.lock
|
|
107
|
+
|
|
108
|
+
# pdm
|
|
109
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
110
|
+
#pdm.lock
|
|
111
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
112
|
+
# in version control.
|
|
113
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
114
|
+
.pdm.toml
|
|
115
|
+
|
|
116
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
117
|
+
__pypackages__/
|
|
118
|
+
|
|
119
|
+
# Celery stuff
|
|
120
|
+
celerybeat-schedule
|
|
121
|
+
celerybeat.pid
|
|
122
|
+
|
|
123
|
+
# SageMath parsed files
|
|
124
|
+
*.sage.py
|
|
125
|
+
|
|
126
|
+
# Environments
|
|
127
|
+
.env
|
|
128
|
+
.venv
|
|
129
|
+
env/
|
|
130
|
+
venv/
|
|
131
|
+
ENV/
|
|
132
|
+
env.bak/
|
|
133
|
+
venv.bak/
|
|
134
|
+
|
|
135
|
+
# Spyder project settings
|
|
136
|
+
.spyderproject
|
|
137
|
+
.spyproject
|
|
138
|
+
|
|
139
|
+
# Rope project settings
|
|
140
|
+
.ropeproject
|
|
141
|
+
|
|
142
|
+
# mkdocs documentation
|
|
143
|
+
/site
|
|
144
|
+
|
|
145
|
+
# mypy
|
|
146
|
+
.mypy_cache/
|
|
147
|
+
.dmypy.json
|
|
148
|
+
dmypy.json
|
|
149
|
+
|
|
150
|
+
# Pyre type checker
|
|
151
|
+
.pyre/
|
|
152
|
+
|
|
153
|
+
# pytype static type analyzer
|
|
154
|
+
.pytype/
|
|
155
|
+
|
|
156
|
+
# Cython debug symbols
|
|
157
|
+
cython_debug/
|
|
158
|
+
|
|
159
|
+
# PyCharm
|
|
160
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
161
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
162
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
163
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
164
|
+
#.idea/
|
|
165
|
+
|
|
166
|
+
### Python Patch ###
|
|
167
|
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
|
168
|
+
poetry.toml
|
|
169
|
+
|
|
170
|
+
# ruff
|
|
171
|
+
.ruff_cache/
|
|
172
|
+
|
|
173
|
+
# LSP config files
|
|
174
|
+
pyrightconfig.json
|
|
175
|
+
|
|
176
|
+
# End of https://www.toptal.com/developers/gitignore/api/python
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
SHELL := bash
|
|
2
|
+
.ONESHELL:
|
|
3
|
+
.SHELLFLAGS := -eu -o pipefail -c
|
|
4
|
+
.DELETE_ON_ERROR:
|
|
5
|
+
MAKEFLAGS += --warn-undefined-variables
|
|
6
|
+
MAKEFLAGS += --no-builtin-rules
|
|
7
|
+
|
|
8
|
+
# Default: create the dev environment
|
|
9
|
+
dev: uv.lock | .venv
|
|
10
|
+
.PHONY: dev
|
|
11
|
+
|
|
12
|
+
fmt:
|
|
13
|
+
uv run --frozen ruff format
|
|
14
|
+
uv run --frozen ruff check --fix .
|
|
15
|
+
.PHONY: fmt
|
|
16
|
+
|
|
17
|
+
typing:
|
|
18
|
+
uv run --frozen mypy src
|
|
19
|
+
.PHONY: typing
|
|
20
|
+
|
|
21
|
+
lint: fmt typing
|
|
22
|
+
.PHONY: lint
|
|
23
|
+
|
|
24
|
+
test:
|
|
25
|
+
uv run --dev --frozen pytest
|
|
26
|
+
.PHONY: test
|
|
27
|
+
|
|
28
|
+
uv.lock .venv &: pyproject.toml
|
|
29
|
+
uv sync --frozen --dev
|
|
30
|
+
|
|
31
|
+
# Automatic make target for scripts with locking
|
|
32
|
+
%.py.lock: %.py
|
|
33
|
+
uv lock --script $<
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: logic-asts
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Grammars and parsers for various logic
|
|
5
|
+
Author-email: Anand Balakrishnan <anandbala1597@gmail.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: attrs>=25.3.0
|
|
8
|
+
Requires-Dist: lark>=1.2.2
|
|
9
|
+
Requires-Dist: typing-extensions>=4.13.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Abstract syntax trees for logical expressions
|
|
13
|
+
|
|
14
|
+
A collection of grammars, parsers, and abstract syntax trees in Python for various
|
|
15
|
+
logics. The goal of this package is to serve as a common utility for
|
|
16
|
+
academics/developers to build their tools on, without having to create a new parser each
|
|
17
|
+
time they make a library.
|
|
18
|
+
|
|
19
|
+
Currently supported logics are:
|
|
20
|
+
|
|
21
|
+
- `base`: the basic Boolean propositional logic.
|
|
22
|
+
- `ltl`: Linear temporal logic
|
|
23
|
+
- `strel`: Spatio-temporal reach escape logic
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Simply install the library, either as a git dependency or (once it is available) through
|
|
28
|
+
PyPI. Then, the library can be used as:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import logic_asts
|
|
32
|
+
|
|
33
|
+
expr = logic_asts.parse_expr(expr_string, syntax="base"|"ltl"|"strel") # remember to pick the syntax
|
|
34
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Abstract syntax trees for logical expressions
|
|
2
|
+
|
|
3
|
+
A collection of grammars, parsers, and abstract syntax trees in Python for various
|
|
4
|
+
logics. The goal of this package is to serve as a common utility for
|
|
5
|
+
academics/developers to build their tools on, without having to create a new parser each
|
|
6
|
+
time they make a library.
|
|
7
|
+
|
|
8
|
+
Currently supported logics are:
|
|
9
|
+
|
|
10
|
+
- `base`: the basic Boolean propositional logic.
|
|
11
|
+
- `ltl`: Linear temporal logic
|
|
12
|
+
- `strel`: Spatio-temporal reach escape logic
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Simply install the library, either as a git dependency or (once it is available) through
|
|
17
|
+
PyPI. Then, the library can be used as:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import logic_asts
|
|
21
|
+
|
|
22
|
+
expr = logic_asts.parse_expr(expr_string, syntax="base"|"ltl"|"strel") # remember to pick the syntax
|
|
23
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "logic-asts"
|
|
3
|
+
version = "1.1.0"
|
|
4
|
+
description = "Grammars and parsers for various logic"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "Anand Balakrishnan", email = "anandbala1597@gmail.com" }]
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
dependencies = ["attrs>=25.3.0", "lark>=1.2.2", "typing-extensions>=4.13.0"]
|
|
9
|
+
|
|
10
|
+
[dependency-groups]
|
|
11
|
+
dev = ["ipython", "mypy", "pytest", "rich", "ruff", "zuban"]
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["hatchling"]
|
|
15
|
+
build-backend = "hatchling.build"
|
|
16
|
+
|
|
17
|
+
[tool.pytest.ini_options]
|
|
18
|
+
addopts = "--import-mode=importlib"
|
|
19
|
+
testpaths = ["tests"]
|
|
20
|
+
|
|
21
|
+
[tool.mypy]
|
|
22
|
+
strict = true
|
|
23
|
+
packages = ["logic_asts"]
|
|
24
|
+
files = ["tests/*.py", "tests/**/*.py"]
|
|
25
|
+
exclude = ["^build/"] # add mypyc build directory
|
|
26
|
+
show_error_codes = true
|
|
27
|
+
namespace_packages = false
|
|
28
|
+
|
|
29
|
+
[tool.ruff]
|
|
30
|
+
line-length = 127
|
|
31
|
+
|
|
32
|
+
[tool.ruff.lint]
|
|
33
|
+
extend-select = ["E", "F", "W", "N", "B", "ANN", "PYI", "I"]
|
|
34
|
+
extend-ignore = ["F722", "PYI041"]
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint.extend-per-file-ignores]
|
|
37
|
+
"*.py" = ["B905", "E203", "E501", "W291", "W293"]
|
|
38
|
+
"*.pyi" = ["B", "E501", "E701"]
|
|
39
|
+
|
|
40
|
+
[tool.pyright]
|
|
41
|
+
pythonVersion = "3.10"
|
|
42
|
+
pythonPlatform = "All"
|
|
43
|
+
reportUnknownMemberType = false
|
|
44
|
+
reportUnknownParameterType = false
|
|
45
|
+
reportUnknownVariableType = false
|
|
46
|
+
reportUnknownArgumentType = false
|
|
47
|
+
reportAny = false
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# mypy: allow_untyped_calls
|
|
2
|
+
import typing
|
|
3
|
+
|
|
4
|
+
from lark import Lark, Transformer
|
|
5
|
+
|
|
6
|
+
from logic_asts.base import Expr
|
|
7
|
+
from logic_asts.grammars import SupportedGrammars
|
|
8
|
+
|
|
9
|
+
SupportedGrammarsStr: typing.TypeAlias = typing.Literal["base", "ltl", "strel", "stl_go"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_expr(
|
|
13
|
+
expr: str,
|
|
14
|
+
*,
|
|
15
|
+
syntax: SupportedGrammars | SupportedGrammarsStr = SupportedGrammars.BASE,
|
|
16
|
+
) -> Expr:
|
|
17
|
+
syntax = SupportedGrammars(syntax)
|
|
18
|
+
|
|
19
|
+
grammar = Lark.open_from_package(
|
|
20
|
+
__name__,
|
|
21
|
+
f"{str(syntax.value)}.lark",
|
|
22
|
+
["grammars"],
|
|
23
|
+
)
|
|
24
|
+
transformer = syntax.get_transformer()
|
|
25
|
+
assert isinstance(transformer, Transformer), f"{transformer=}"
|
|
26
|
+
|
|
27
|
+
parse_tree = grammar.parse(expr)
|
|
28
|
+
return transformer.transform(tree=parse_tree)
|