sattline-parser 2026.8__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.
- sattline_parser-2026.8/LICENSE +21 -0
- sattline_parser-2026.8/PKG-INFO +175 -0
- sattline_parser-2026.8/README.md +131 -0
- sattline_parser-2026.8/pyproject.toml +147 -0
- sattline_parser-2026.8/setup.cfg +4 -0
- sattline_parser-2026.8/src/sattline_parser/__init__.py +116 -0
- sattline_parser-2026.8/src/sattline_parser/__version__.py +3 -0
- sattline_parser-2026.8/src/sattline_parser/api.py +305 -0
- sattline_parser-2026.8/src/sattline_parser/decode_fuzzer.py +17 -0
- sattline_parser-2026.8/src/sattline_parser/errors.py +101 -0
- sattline_parser-2026.8/src/sattline_parser/formatting/__init__.py +12 -0
- sattline_parser-2026.8/src/sattline_parser/formatting/formatter.py +391 -0
- sattline_parser-2026.8/src/sattline_parser/fuzz_harness.py +276 -0
- sattline_parser-2026.8/src/sattline_parser/grammar/__init__.py +5 -0
- sattline_parser-2026.8/src/sattline_parser/grammar/constants.py +234 -0
- sattline_parser-2026.8/src/sattline_parser/grammar/sattline.lark +447 -0
- sattline_parser-2026.8/src/sattline_parser/grammar/sattline_lexer.py +106 -0
- sattline_parser-2026.8/src/sattline_parser/models/__init__.py +1 -0
- sattline_parser-2026.8/src/sattline_parser/models/_ast_model_support.py +188 -0
- sattline_parser-2026.8/src/sattline_parser/models/ast_model.py +582 -0
- sattline_parser-2026.8/src/sattline_parser/models/expressions.py +195 -0
- sattline_parser-2026.8/src/sattline_parser/parser_fuzzer.py +21 -0
- sattline_parser-2026.8/src/sattline_parser/preprocessing/__init__.py +17 -0
- sattline_parser-2026.8/src/sattline_parser/preprocessing/compressed.py +276 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/__init__.py +5 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_comments_mixin.py +77 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_expressions_mixin.py +247 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_graphics_interact_mixin.py +433 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_module_assembly_mixin.py +587 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_module_header_mixin.py +188 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_module_layout_mixin.py +196 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_module_shared.py +106 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_modules_mixin.py +27 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_sfc_mixin.py +315 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/_tokens_mixin.py +149 -0
- sattline_parser-2026.8/src/sattline_parser/transformer/sl_transformer.py +240 -0
- sattline_parser-2026.8/src/sattline_parser.egg-info/PKG-INFO +175 -0
- sattline_parser-2026.8/src/sattline_parser.egg-info/SOURCES.txt +39 -0
- sattline_parser-2026.8/src/sattline_parser.egg-info/dependency_links.txt +1 -0
- sattline_parser-2026.8/src/sattline_parser.egg-info/requires.txt +24 -0
- sattline_parser-2026.8/src/sattline_parser.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Søren H. Johansen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sattline-parser
|
|
3
|
+
Version: 2026.8
|
|
4
|
+
Summary: Standalone parser, AST, and transformer for the SattLine PLC language
|
|
5
|
+
Author: Søren H. Johansen
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/SorenHJohansen/sattline-parser
|
|
8
|
+
Project-URL: Repository, https://github.com/SorenHJohansen/sattline-parser
|
|
9
|
+
Project-URL: Issues, https://github.com/SorenHJohansen/sattline-parser/issues
|
|
10
|
+
Keywords: sattline,parser,transformer,ast,plc
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
18
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: lark[interegular]<2,>=1.3.1
|
|
23
|
+
Requires-Dist: regex>=2024.0.0
|
|
24
|
+
Provides-Extra: fuzz
|
|
25
|
+
Requires-Dist: atheris>=2.3.0; extra == "fuzz"
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
|
|
29
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-timeout>=2.3.1; extra == "test"
|
|
31
|
+
Requires-Dist: pytest-xdist>=3.0.0; extra == "test"
|
|
32
|
+
Requires-Dist: pytest-benchmark>=4.0.0; extra == "test"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: sattline-parser[fuzz,test]; extra == "dev"
|
|
35
|
+
Requires-Dist: ruff==0.15.20; extra == "dev"
|
|
36
|
+
Requires-Dist: pyright>=1.1.380; extra == "dev"
|
|
37
|
+
Requires-Dist: build>=1.2.2; extra == "dev"
|
|
38
|
+
Requires-Dist: bandit>=1.8.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pip-audit>=2.8.0; extra == "dev"
|
|
40
|
+
Requires-Dist: twine>=5.1.1; extra == "dev"
|
|
41
|
+
Requires-Dist: vulture>=2.11; extra == "dev"
|
|
42
|
+
Requires-Dist: pre-commit>=4.0; extra == "dev"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
# sattline-parser
|
|
46
|
+
|
|
47
|
+
Standalone parser, AST, and transformer for ABB SattLine.
|
|
48
|
+
|
|
49
|
+
This package owns the Lark grammar, the strict single-file syntax behavior, the AST models, and the `SLTransformer`, all in one self-contained, installable package.
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- Lark LALR parser for SattLine sources (grammar in `grammar/sattline.lark`)
|
|
54
|
+
- Parses plain text and files (`.s`, `.g`, `.l`, `.x`, `.y`, `.z` and any other extension; the parser is content-based, not extension-based)
|
|
55
|
+
- Strict, no-silent-fallback parsing
|
|
56
|
+
- Structural comments (`(* ... *)`, nested) preserved as role-tagged AST nodes
|
|
57
|
+
- Automatic compressed-source decoding (`preprocess_sl_text`, `is_compressed`)
|
|
58
|
+
- Error reporting with line/column locations in the original source (`describe_parse_error`)
|
|
59
|
+
- AST models in `sattline_parser.models`
|
|
60
|
+
- `SLTransformer` tree transformer in `sattline_parser.transformer`
|
|
61
|
+
- Standalone fuzz harness with timeout protection and corpus regression
|
|
62
|
+
- Zero runtime dependencies beyond `lark` and `regex`
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install sattline-parser
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Requires Python 3.13+.
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
### Parse a source file
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from pathlib import Path
|
|
78
|
+
from sattline_parser import parse_source_file
|
|
79
|
+
|
|
80
|
+
basepicture = parse_source_file(Path("program.s"))
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Parse source text
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from sattline_parser import parse_source_text
|
|
87
|
+
|
|
88
|
+
source = open("program.x", encoding="utf-8").read()
|
|
89
|
+
basepicture = parse_source_text(source)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`parse_source_file` and `parse_source_text` both return a `BasePicture` (the module-level model) with the full AST attached.
|
|
93
|
+
|
|
94
|
+
### Choosing an entry point
|
|
95
|
+
|
|
96
|
+
`parse_source_file` is for when you have a path on disk. It handles the file I/O for you: it reads the file with an encoding fallback (`utf-8`, then `cp1252`, then `latin-1`) and passes the path along so error messages can name the source file.
|
|
97
|
+
|
|
98
|
+
`parse_source_text` is for when you already hold the source as a string: a snippet, an editor buffer, a response from an API, or content read by your own code. The two are interchangeable in behavior; `parse_source_file(path)` is equivalent to `parse_source_text(path.read_text(...))` plus the encoding fallback and path-aware error reporting. Start with `parse_source_file` when you have a path, `parse_source_text` otherwise.
|
|
99
|
+
|
|
100
|
+
Both entry points handle cleanup automatically, so you do not need to pre-process the source:
|
|
101
|
+
|
|
102
|
+
- **Comments are parsed structurally** (`(* ... *)`, including nested ones) and preserved on the AST as `CodeComment` nodes.
|
|
103
|
+
- **Compressed sources are detected and decoded** automatically.
|
|
104
|
+
|
|
105
|
+
The exposed helpers below exist for the rare case where you are building tooling that needs the intermediate stages (for example, to tokenize, diff, or re-emit sources). For ordinary parsing you can ignore them.
|
|
106
|
+
|
|
107
|
+
### For power users: handle compressed sources
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from sattline_parser import is_compressed, preprocess_sl_text
|
|
111
|
+
|
|
112
|
+
if is_compressed(source):
|
|
113
|
+
decoded, mapping = preprocess_sl_text(source)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`is_compressed` answers whether the text uses the compressed encoding, and `preprocess_sl_text` decodes it, returning the decoded text plus a mapping back to the original. Since both parse entry points already detect and decode compressed sources, these are only needed by tooling that must decode without parsing (for example, saving a plain-text copy) or by the fuzz harness that drives `preprocess_sl_text` with adversarial inputs.
|
|
117
|
+
|
|
118
|
+
### Report errors with source locations
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from sattline_parser import create_parser, describe_parse_error, parse_source_text
|
|
122
|
+
|
|
123
|
+
parser = create_parser()
|
|
124
|
+
try:
|
|
125
|
+
parse_source_text(source, parser=parser)
|
|
126
|
+
except Exception as exc:
|
|
127
|
+
details = describe_parse_error(exc, source)
|
|
128
|
+
print(f"{details.line}:{details.column} {details.message}")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### What is the AST good for?
|
|
132
|
+
|
|
133
|
+
`parse_source_file` and `parse_source_text` return a `BasePicture`, a tree of Python objects that mirrors the structure of the program. Once you have it, you can inspect and walk the program *as data* instead of as text.
|
|
134
|
+
|
|
135
|
+
For readers new to ASTs (abstract syntax trees): the parser does not give you the flat file back; it gives you structured objects. `basepicture.program_name` is the program name, `basepicture.moduletype_defs` is the list of type definitions, `basepicture.submodules` is the tree of nested modules, and so on. You can read fields, iterate lists, and check conditions directly in Python. For a small program this prints:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from pathlib import Path
|
|
139
|
+
from sattline_parser import parse_source_file
|
|
140
|
+
|
|
141
|
+
basepicture = parse_source_file(Path("program.s"))
|
|
142
|
+
print(basepicture.program_name)
|
|
143
|
+
print([submodule.header.name for submodule in basepicture.submodules])
|
|
144
|
+
print(len(basepicture.submodules), "submodules")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```text
|
|
148
|
+
program
|
|
149
|
+
['Controller1', 'Controller2']
|
|
150
|
+
2 submodules
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Think of the AST as a structured, machine-readable view of the program, that tools (a linter, a refactorer, an editor, a report generator) can walk without re-parsing the text. Since an AST is just nested objects, answering questions about the program becomes ordinary Python.
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
python -m venv .venv && source .venv/bin/activate
|
|
159
|
+
pip install -e ".[dev]"
|
|
160
|
+
pytest tests/parser -q
|
|
161
|
+
ruff check src tests
|
|
162
|
+
pyright src tests
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Project layout
|
|
166
|
+
|
|
167
|
+
- `src/sattline_parser/grammar/` : Lark grammar and constants
|
|
168
|
+
- `src/sattline_parser/models/` : AST models
|
|
169
|
+
- `src/sattline_parser/transformer/` : transformer mixins and `SLTransformer`
|
|
170
|
+
- `src/sattline_parser/api.py` : public entry points
|
|
171
|
+
- `src/sattline_parser/fuzz_harness.py` : standalone fuzzing
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT. Copyright (c) 2025 Søren H. Johansen.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# sattline-parser
|
|
2
|
+
|
|
3
|
+
Standalone parser, AST, and transformer for ABB SattLine.
|
|
4
|
+
|
|
5
|
+
This package owns the Lark grammar, the strict single-file syntax behavior, the AST models, and the `SLTransformer`, all in one self-contained, installable package.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Lark LALR parser for SattLine sources (grammar in `grammar/sattline.lark`)
|
|
10
|
+
- Parses plain text and files (`.s`, `.g`, `.l`, `.x`, `.y`, `.z` and any other extension; the parser is content-based, not extension-based)
|
|
11
|
+
- Strict, no-silent-fallback parsing
|
|
12
|
+
- Structural comments (`(* ... *)`, nested) preserved as role-tagged AST nodes
|
|
13
|
+
- Automatic compressed-source decoding (`preprocess_sl_text`, `is_compressed`)
|
|
14
|
+
- Error reporting with line/column locations in the original source (`describe_parse_error`)
|
|
15
|
+
- AST models in `sattline_parser.models`
|
|
16
|
+
- `SLTransformer` tree transformer in `sattline_parser.transformer`
|
|
17
|
+
- Standalone fuzz harness with timeout protection and corpus regression
|
|
18
|
+
- Zero runtime dependencies beyond `lark` and `regex`
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install sattline-parser
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requires Python 3.13+.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Parse a source file
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
from sattline_parser import parse_source_file
|
|
35
|
+
|
|
36
|
+
basepicture = parse_source_file(Path("program.s"))
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Parse source text
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from sattline_parser import parse_source_text
|
|
43
|
+
|
|
44
|
+
source = open("program.x", encoding="utf-8").read()
|
|
45
|
+
basepicture = parse_source_text(source)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`parse_source_file` and `parse_source_text` both return a `BasePicture` (the module-level model) with the full AST attached.
|
|
49
|
+
|
|
50
|
+
### Choosing an entry point
|
|
51
|
+
|
|
52
|
+
`parse_source_file` is for when you have a path on disk. It handles the file I/O for you: it reads the file with an encoding fallback (`utf-8`, then `cp1252`, then `latin-1`) and passes the path along so error messages can name the source file.
|
|
53
|
+
|
|
54
|
+
`parse_source_text` is for when you already hold the source as a string: a snippet, an editor buffer, a response from an API, or content read by your own code. The two are interchangeable in behavior; `parse_source_file(path)` is equivalent to `parse_source_text(path.read_text(...))` plus the encoding fallback and path-aware error reporting. Start with `parse_source_file` when you have a path, `parse_source_text` otherwise.
|
|
55
|
+
|
|
56
|
+
Both entry points handle cleanup automatically, so you do not need to pre-process the source:
|
|
57
|
+
|
|
58
|
+
- **Comments are parsed structurally** (`(* ... *)`, including nested ones) and preserved on the AST as `CodeComment` nodes.
|
|
59
|
+
- **Compressed sources are detected and decoded** automatically.
|
|
60
|
+
|
|
61
|
+
The exposed helpers below exist for the rare case where you are building tooling that needs the intermediate stages (for example, to tokenize, diff, or re-emit sources). For ordinary parsing you can ignore them.
|
|
62
|
+
|
|
63
|
+
### For power users: handle compressed sources
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from sattline_parser import is_compressed, preprocess_sl_text
|
|
67
|
+
|
|
68
|
+
if is_compressed(source):
|
|
69
|
+
decoded, mapping = preprocess_sl_text(source)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`is_compressed` answers whether the text uses the compressed encoding, and `preprocess_sl_text` decodes it, returning the decoded text plus a mapping back to the original. Since both parse entry points already detect and decode compressed sources, these are only needed by tooling that must decode without parsing (for example, saving a plain-text copy) or by the fuzz harness that drives `preprocess_sl_text` with adversarial inputs.
|
|
73
|
+
|
|
74
|
+
### Report errors with source locations
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from sattline_parser import create_parser, describe_parse_error, parse_source_text
|
|
78
|
+
|
|
79
|
+
parser = create_parser()
|
|
80
|
+
try:
|
|
81
|
+
parse_source_text(source, parser=parser)
|
|
82
|
+
except Exception as exc:
|
|
83
|
+
details = describe_parse_error(exc, source)
|
|
84
|
+
print(f"{details.line}:{details.column} {details.message}")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### What is the AST good for?
|
|
88
|
+
|
|
89
|
+
`parse_source_file` and `parse_source_text` return a `BasePicture`, a tree of Python objects that mirrors the structure of the program. Once you have it, you can inspect and walk the program *as data* instead of as text.
|
|
90
|
+
|
|
91
|
+
For readers new to ASTs (abstract syntax trees): the parser does not give you the flat file back; it gives you structured objects. `basepicture.program_name` is the program name, `basepicture.moduletype_defs` is the list of type definitions, `basepicture.submodules` is the tree of nested modules, and so on. You can read fields, iterate lists, and check conditions directly in Python. For a small program this prints:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from pathlib import Path
|
|
95
|
+
from sattline_parser import parse_source_file
|
|
96
|
+
|
|
97
|
+
basepicture = parse_source_file(Path("program.s"))
|
|
98
|
+
print(basepicture.program_name)
|
|
99
|
+
print([submodule.header.name for submodule in basepicture.submodules])
|
|
100
|
+
print(len(basepicture.submodules), "submodules")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
program
|
|
105
|
+
['Controller1', 'Controller2']
|
|
106
|
+
2 submodules
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Think of the AST as a structured, machine-readable view of the program, that tools (a linter, a refactorer, an editor, a report generator) can walk without re-parsing the text. Since an AST is just nested objects, answering questions about the program becomes ordinary Python.
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
python -m venv .venv && source .venv/bin/activate
|
|
115
|
+
pip install -e ".[dev]"
|
|
116
|
+
pytest tests/parser -q
|
|
117
|
+
ruff check src tests
|
|
118
|
+
pyright src tests
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Project layout
|
|
122
|
+
|
|
123
|
+
- `src/sattline_parser/grammar/` : Lark grammar and constants
|
|
124
|
+
- `src/sattline_parser/models/` : AST models
|
|
125
|
+
- `src/sattline_parser/transformer/` : transformer mixins and `SLTransformer`
|
|
126
|
+
- `src/sattline_parser/api.py` : public entry points
|
|
127
|
+
- `src/sattline_parser/fuzz_harness.py` : standalone fuzzing
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT. Copyright (c) 2025 Søren H. Johansen.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=82.0.1", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sattline-parser"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Standalone parser, AST, and transformer for the SattLine PLC language"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [{ name = "S\u00f8ren H. Johansen" }]
|
|
12
|
+
requires-python = ">=3.13"
|
|
13
|
+
keywords = ["sattline", "parser", "transformer", "ast", "plc"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Topic :: Software Development :: Compilers",
|
|
22
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"lark[interegular]>=1.3.1,<2",
|
|
26
|
+
"regex>=2024.0.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/SorenHJohansen/sattline-parser"
|
|
31
|
+
Repository = "https://github.com/SorenHJohansen/sattline-parser"
|
|
32
|
+
Issues = "https://github.com/SorenHJohansen/sattline-parser/issues"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
fuzz = [
|
|
36
|
+
"atheris>=2.3.0",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
test = [
|
|
40
|
+
"pytest>=7.0.0",
|
|
41
|
+
"pytest-cov>=4.0.0",
|
|
42
|
+
"pytest-mock>=3.10.0",
|
|
43
|
+
"pytest-timeout>=2.3.1",
|
|
44
|
+
"pytest-xdist>=3.0.0",
|
|
45
|
+
"pytest-benchmark>=4.0.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
dev = [
|
|
49
|
+
"sattline-parser[test,fuzz]",
|
|
50
|
+
"ruff==0.15.20",
|
|
51
|
+
"pyright>=1.1.380",
|
|
52
|
+
"build>=1.2.2",
|
|
53
|
+
"bandit>=1.8.0",
|
|
54
|
+
"pip-audit>=2.8.0",
|
|
55
|
+
"twine>=5.1.1",
|
|
56
|
+
"vulture>=2.11",
|
|
57
|
+
"pre-commit>=4.0",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
minversion = "7.0"
|
|
62
|
+
testpaths = ["tests"]
|
|
63
|
+
python_files = ["test_*.py", "*_test.py"]
|
|
64
|
+
python_classes = ["Test*"]
|
|
65
|
+
python_functions = ["test_*"]
|
|
66
|
+
timeout = 60
|
|
67
|
+
timeout_method = "thread"
|
|
68
|
+
addopts = [
|
|
69
|
+
"--strict-markers",
|
|
70
|
+
"--strict-config",
|
|
71
|
+
"--cov=src",
|
|
72
|
+
"--cov-report=term-missing",
|
|
73
|
+
"--cov-report=xml:coverage.xml",
|
|
74
|
+
"--cov-report=html:htmlcov",
|
|
75
|
+
]
|
|
76
|
+
markers = [
|
|
77
|
+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
|
|
78
|
+
"parser: marks tests related to parser functionality",
|
|
79
|
+
"quarantine: marks flaky tests that should be skipped in CI",
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
[tool.coverage.report]
|
|
83
|
+
precision = 2
|
|
84
|
+
exclude_lines = [
|
|
85
|
+
"if TYPE_CHECKING:",
|
|
86
|
+
"if not fitting_tokens:",
|
|
87
|
+
'encoding="latin-1"',
|
|
88
|
+
]
|
|
89
|
+
fail_under = 100
|
|
90
|
+
|
|
91
|
+
[tool.ruff]
|
|
92
|
+
line-length = 120
|
|
93
|
+
target-version = "py313"
|
|
94
|
+
|
|
95
|
+
[tool.ruff.lint]
|
|
96
|
+
select = [
|
|
97
|
+
"E", # pycodestyle errors
|
|
98
|
+
"F", # pyflakes
|
|
99
|
+
"W", # pycodestyle warnings
|
|
100
|
+
"I", # isort
|
|
101
|
+
"N", # pep8-naming
|
|
102
|
+
"UP", # pyupgrade
|
|
103
|
+
"B", # flake8-bugbear
|
|
104
|
+
"BLE", # blind except Exception handlers
|
|
105
|
+
"C4", # flake8-comprehensions
|
|
106
|
+
"PLC0415", # imports outside top-level
|
|
107
|
+
"PLR0915", # too many statements
|
|
108
|
+
"S101", # disallow assert-based error handling
|
|
109
|
+
"SIM", # flake8-simplify
|
|
110
|
+
"RUF", # ruff-specific rules
|
|
111
|
+
]
|
|
112
|
+
ignore = [
|
|
113
|
+
"E501",
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
[tool.ruff.lint.per-file-ignores]
|
|
117
|
+
"src/sattline_parser/models/ast_model.py" = ["N801"]
|
|
118
|
+
"src/sattline_parser/transformer/sl_transformer.py" = ["N802"]
|
|
119
|
+
"src/sattline_parser/transformer/_modules_mixin.py" = ["N802"]
|
|
120
|
+
"src/sattline_parser/transformer/_tokens_mixin.py" = ["N802"]
|
|
121
|
+
"tests/*.py" = ["S101"]
|
|
122
|
+
"tests/**/*.py" = ["S101"]
|
|
123
|
+
|
|
124
|
+
[tool.ruff.lint.pylint]
|
|
125
|
+
max-statements = 50
|
|
126
|
+
|
|
127
|
+
[tool.pyright]
|
|
128
|
+
include = ["src", "tests"]
|
|
129
|
+
typeCheckingMode = "strict"
|
|
130
|
+
pythonVersion = "3.13"
|
|
131
|
+
venvPath = "."
|
|
132
|
+
venv = ".venv"
|
|
133
|
+
extraPaths = ["src"]
|
|
134
|
+
reportMissingTypeStubs = false
|
|
135
|
+
|
|
136
|
+
[tool.bandit]
|
|
137
|
+
exclude_dirs = ["tests"]
|
|
138
|
+
skips = ["B404", "B603"]
|
|
139
|
+
|
|
140
|
+
[tool.setuptools.packages.find]
|
|
141
|
+
where = ["src"]
|
|
142
|
+
|
|
143
|
+
[tool.setuptools.dynamic]
|
|
144
|
+
version = { attr = "sattline_parser.__version__.__version__" }
|
|
145
|
+
|
|
146
|
+
[tool.setuptools.package-data]
|
|
147
|
+
sattline_parser = ["grammar/*.lark"]
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""Reusable SattLine parser-core package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib import import_module
|
|
6
|
+
from types import ModuleType
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
from sattline_parser.models.ast_model import BasePicture, SourceSpan
|
|
10
|
+
from sattline_parser.models.expressions import (
|
|
11
|
+
Assignment,
|
|
12
|
+
BinOp,
|
|
13
|
+
BoolOp,
|
|
14
|
+
Compare,
|
|
15
|
+
FuncCall,
|
|
16
|
+
FuncCallStmt,
|
|
17
|
+
IfStmt,
|
|
18
|
+
NotOp,
|
|
19
|
+
SLExpression,
|
|
20
|
+
SLStmt,
|
|
21
|
+
TernaryOp,
|
|
22
|
+
UnaryOp,
|
|
23
|
+
VarRef,
|
|
24
|
+
)
|
|
25
|
+
from sattline_parser.preprocessing import is_compressed, preprocess_sl_text
|
|
26
|
+
from sattline_parser.transformer.sl_transformer import SLTransformer
|
|
27
|
+
|
|
28
|
+
from .__version__ import __version__
|
|
29
|
+
from .api import create_parser, create_sl_parser, describe_parse_error, parse_source_file, parse_source_text
|
|
30
|
+
from .grammar import constants
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from . import fuzz_harness as fuzz_harness
|
|
34
|
+
from .fuzz_harness import (
|
|
35
|
+
FuzzResult,
|
|
36
|
+
assert_no_crashes,
|
|
37
|
+
assert_no_timeouts,
|
|
38
|
+
collect_corpus_inputs,
|
|
39
|
+
fuzz_parse_text,
|
|
40
|
+
generate_random_text,
|
|
41
|
+
run_corpus_regression,
|
|
42
|
+
run_random_fuzz,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
_FUZZ_EXPORTS = (
|
|
46
|
+
"FuzzResult",
|
|
47
|
+
"assert_no_crashes",
|
|
48
|
+
"assert_no_timeouts",
|
|
49
|
+
"collect_corpus_inputs",
|
|
50
|
+
"fuzz_harness",
|
|
51
|
+
"fuzz_parse_text",
|
|
52
|
+
"generate_random_text",
|
|
53
|
+
"run_corpus_regression",
|
|
54
|
+
"run_random_fuzz",
|
|
55
|
+
)
|
|
56
|
+
_FUZZ_EXPORT_SET = frozenset(_FUZZ_EXPORTS)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _load_fuzz_harness() -> ModuleType:
|
|
60
|
+
module = import_module(".fuzz_harness", __name__)
|
|
61
|
+
globals()["fuzz_harness"] = module
|
|
62
|
+
for export_name in _FUZZ_EXPORTS:
|
|
63
|
+
if export_name == "fuzz_harness":
|
|
64
|
+
continue
|
|
65
|
+
globals()[export_name] = getattr(module, export_name)
|
|
66
|
+
return module
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def __getattr__(name: str) -> Any:
|
|
70
|
+
if name not in _FUZZ_EXPORT_SET:
|
|
71
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
72
|
+
module = _load_fuzz_harness()
|
|
73
|
+
if name == "fuzz_harness":
|
|
74
|
+
return module
|
|
75
|
+
return getattr(module, name)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def __dir__() -> list[str]:
|
|
79
|
+
return sorted(set(globals()) | _FUZZ_EXPORT_SET)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
__all__ = [
|
|
83
|
+
"Assignment",
|
|
84
|
+
"BasePicture",
|
|
85
|
+
"BinOp",
|
|
86
|
+
"BoolOp",
|
|
87
|
+
"Compare",
|
|
88
|
+
"FuncCall",
|
|
89
|
+
"FuncCallStmt",
|
|
90
|
+
"FuzzResult",
|
|
91
|
+
"IfStmt",
|
|
92
|
+
"NotOp",
|
|
93
|
+
"SLExpression",
|
|
94
|
+
"SLStmt",
|
|
95
|
+
"SLTransformer",
|
|
96
|
+
"SourceSpan",
|
|
97
|
+
"TernaryOp",
|
|
98
|
+
"UnaryOp",
|
|
99
|
+
"VarRef",
|
|
100
|
+
"__version__",
|
|
101
|
+
"assert_no_crashes",
|
|
102
|
+
"assert_no_timeouts",
|
|
103
|
+
"collect_corpus_inputs",
|
|
104
|
+
"constants",
|
|
105
|
+
"create_parser",
|
|
106
|
+
"create_sl_parser",
|
|
107
|
+
"describe_parse_error",
|
|
108
|
+
"fuzz_parse_text",
|
|
109
|
+
"generate_random_text",
|
|
110
|
+
"is_compressed",
|
|
111
|
+
"parse_source_file",
|
|
112
|
+
"parse_source_text",
|
|
113
|
+
"preprocess_sl_text",
|
|
114
|
+
"run_corpus_regression",
|
|
115
|
+
"run_random_fuzz",
|
|
116
|
+
]
|