Parser and abstract syntax tree for TLA+, the temporal logic of actions.
Project description
About
A parser for the Temporal Logic of Actions (TLA+). The parser is based on
combinators.
The lexer is generated with ply
using lex
. Classes for a TLA+ abstract tree are included and used for
representing the result of parsing.
To install:
pip install tla
To parse a string:
from tla import parser
module_text = r'''
---- MODULE Foo ----
foo == TRUE
====================
'''
tree = parser.parse(module_text)
To parse the string module_text
from above and print a formatted version:
from tla import parser
from tla.to_str import Nodes
# The abstract syntax tree classes can be changed using
# the optional argument `nodes` of the function `parser.parse`.
tree = parser.parse(module_text, nodes=Nodes)
text = tree.to_str(width=80)
print(text)
More examples can be found in the directory examples/
To implement a new translator of TLA+ to an intended output format, either:
- use the visitor pattern with the module
ast.visit
, or - subclass the class
tla.ast.Nodes
, and override AST node classes and their methods as needed. An example of this approach is the moduletla.to_str
, which can be copied as a starting point for implementing a translator.
This parser is a translation to Python from OCaml of the parser in
tlapm
, the TLA+ proof manager.
The Python source code includes in comments the corresponding OCaml source code.
Comments in each module mention the OCaml files on which that module is based.
This parser is slower than the OCaml implementation.
The module tla._combinators
can be used to write other parsers.
Documentation
Tests
Require nose
. Run with:
cd tests/
nosetests .
See also the file tests/README.md
.
License
BSD-3, see LICENSE
file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tla-0.0.1.tar.gz
.
File metadata
- Download URL: tla-0.0.1.tar.gz
- Upload date:
- Size: 78.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56f9103d2b8dd0c619456312d83efe0fd2f9db24596ae741f831d678c3e2713a |
|
MD5 | dd4a861b8c57e9c8f43a740a21552e9b |
|
BLAKE2b-256 | a0f8dd808ceb440a695acce638e57c2b25dd7a5fbd53ac24cddcbd907c2b2233 |