oaknut-basic 10.0.1__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.
- oaknut_basic-10.0.1/LICENSE +21 -0
- oaknut_basic-10.0.1/PKG-INFO +29 -0
- oaknut_basic-10.0.1/README.md +9 -0
- oaknut_basic-10.0.1/pyproject.toml +43 -0
- oaknut_basic-10.0.1/setup.cfg +4 -0
- oaknut_basic-10.0.1/src/oaknut/basic/__init__.py +60 -0
- oaknut_basic-10.0.1/src/oaknut_basic.egg-info/PKG-INFO +29 -0
- oaknut_basic-10.0.1/src/oaknut_basic.egg-info/SOURCES.txt +9 -0
- oaknut_basic-10.0.1/src/oaknut_basic.egg-info/dependency_links.txt +1 -0
- oaknut_basic-10.0.1/src/oaknut_basic.egg-info/top_level.txt +1 -0
- oaknut_basic-10.0.1/tests/test_basic.py +62 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Smallshire
|
|
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,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oaknut-basic
|
|
3
|
+
Version: 10.0.1
|
|
4
|
+
Summary: BBC BASIC tokeniser and detokeniser for Acorn 8-bit and 32-bit BASIC source files
|
|
5
|
+
Author-email: Robert Smallshire <robert@smallshire.org.uk>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rob-smallshire/oaknut
|
|
8
|
+
Project-URL: Repository, https://github.com/rob-smallshire/oaknut
|
|
9
|
+
Project-URL: Issues, https://github.com/rob-smallshire/oaknut/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# oaknut-basic
|
|
22
|
+
|
|
23
|
+
BBC BASIC tokeniser and detokeniser for Acorn 8-bit BASIC (BBC
|
|
24
|
+
Micro, Acorn Electron) and 32-bit BASIC V/VI (Archimedes, RISC OS)
|
|
25
|
+
source files. Self-contained, no runtime dependencies on other
|
|
26
|
+
`oaknut-*` packages.
|
|
27
|
+
|
|
28
|
+
Part of the [oaknut](https://github.com/rob-smallshire/oaknut)
|
|
29
|
+
monorepo.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# oaknut-basic
|
|
2
|
+
|
|
3
|
+
BBC BASIC tokeniser and detokeniser for Acorn 8-bit BASIC (BBC
|
|
4
|
+
Micro, Acorn Electron) and 32-bit BASIC V/VI (Archimedes, RISC OS)
|
|
5
|
+
source files. Self-contained, no runtime dependencies on other
|
|
6
|
+
`oaknut-*` packages.
|
|
7
|
+
|
|
8
|
+
Part of the [oaknut](https://github.com/rob-smallshire/oaknut)
|
|
9
|
+
monorepo.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "oaknut-basic"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
authors = [{ name = "Robert Smallshire", email = "robert@smallshire.org.uk" }]
|
|
9
|
+
description = "BBC BASIC tokeniser and detokeniser for Acorn 8-bit and 32-bit BASIC source files"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
]
|
|
22
|
+
dependencies = []
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/rob-smallshire/oaknut"
|
|
26
|
+
Repository = "https://github.com/rob-smallshire/oaknut"
|
|
27
|
+
Issues = "https://github.com/rob-smallshire/oaknut/issues"
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
test = [
|
|
31
|
+
"pytest>=8.0",
|
|
32
|
+
]
|
|
33
|
+
dev = [
|
|
34
|
+
"bump-my-version>=0.28.0",
|
|
35
|
+
"pre-commit>=3.0",
|
|
36
|
+
{include-group = "test"},
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.dynamic]
|
|
40
|
+
version = { attr = "oaknut.basic.__version__" }
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""BBC BASIC tokenisation and detokenisation.
|
|
2
|
+
|
|
3
|
+
Tokenised BBC BASIC is a compact on-disc representation in which
|
|
4
|
+
keywords like ``PRINT`` and ``GOTO`` are replaced with single bytes,
|
|
5
|
+
line numbers are packed at the start of each line, and string
|
|
6
|
+
literals and ``REM`` comments are stored in the Acorn character
|
|
7
|
+
encoding. This module converts between source text and that byte
|
|
8
|
+
representation.
|
|
9
|
+
|
|
10
|
+
BBC BASIC is a language, not a text encoding — tokenised programs
|
|
11
|
+
are bytecode, not text. The two functions here therefore work in
|
|
12
|
+
``str`` ↔ ``bytes`` pairs and must never be composed with
|
|
13
|
+
``DFSPath.read_text`` / ``write_text`` (which would silently mangle
|
|
14
|
+
the bytecode). The canonical way to move a BASIC program through a
|
|
15
|
+
disc image is ``DFSPath.read_basic`` / ``write_basic``, which wrap
|
|
16
|
+
these functions with the correct load-address default.
|
|
17
|
+
|
|
18
|
+
This module is deliberately self-contained and has no runtime
|
|
19
|
+
dependencies on any other oaknut package.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
__version__ = "10.0.1"
|
|
25
|
+
|
|
26
|
+
# Canonical load addresses for BBC BASIC programs on each host.
|
|
27
|
+
# Programs saved by *SAVE on a real machine use these by default.
|
|
28
|
+
BBC_BASIC_LOAD_ADDRESS = 0x1900
|
|
29
|
+
ELECTRON_BASIC_LOAD_ADDRESS = 0x0E00
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def tokenise(source: str) -> bytes:
|
|
33
|
+
"""Tokenise BBC BASIC source text into its on-disc byte form.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
source: BBC BASIC source as a Unicode string.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Tokenised BASIC program bytes, ready to be written to a disc
|
|
40
|
+
image via ``DFSPath.write_bytes`` or ``ADFSPath.write_bytes``.
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
NotImplementedError: The tokeniser has not yet been implemented.
|
|
44
|
+
"""
|
|
45
|
+
raise NotImplementedError("BBC BASIC tokenisation is not yet implemented")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def detokenise(data: bytes) -> str:
|
|
49
|
+
"""Detokenise a BBC BASIC program into source text.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
data: Tokenised BASIC program bytes, as read from a disc image.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
BBC BASIC source as a Unicode string.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
NotImplementedError: The detokeniser has not yet been implemented.
|
|
59
|
+
"""
|
|
60
|
+
raise NotImplementedError("BBC BASIC detokenisation is not yet implemented")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oaknut-basic
|
|
3
|
+
Version: 10.0.1
|
|
4
|
+
Summary: BBC BASIC tokeniser and detokeniser for Acorn 8-bit and 32-bit BASIC source files
|
|
5
|
+
Author-email: Robert Smallshire <robert@smallshire.org.uk>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rob-smallshire/oaknut
|
|
8
|
+
Project-URL: Repository, https://github.com/rob-smallshire/oaknut
|
|
9
|
+
Project-URL: Issues, https://github.com/rob-smallshire/oaknut/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# oaknut-basic
|
|
22
|
+
|
|
23
|
+
BBC BASIC tokeniser and detokeniser for Acorn 8-bit BASIC (BBC
|
|
24
|
+
Micro, Acorn Electron) and 32-bit BASIC V/VI (Archimedes, RISC OS)
|
|
25
|
+
source files. Self-contained, no runtime dependencies on other
|
|
26
|
+
`oaknut-*` packages.
|
|
27
|
+
|
|
28
|
+
Part of the [oaknut](https://github.com/rob-smallshire/oaknut)
|
|
29
|
+
monorepo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
oaknut
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Tests for the oaknut.dfs.basic module.
|
|
2
|
+
|
|
3
|
+
The tokeniser and detokeniser are stubs that raise NotImplementedError
|
|
4
|
+
until the real implementation lands. These tests lock in the module's
|
|
5
|
+
public API shape so the stubs can be replaced with working code
|
|
6
|
+
without disturbing callers.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import oaknut.basic as basic
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestConstants:
|
|
14
|
+
def test_bbc_basic_load_address(self):
|
|
15
|
+
assert basic.BBC_BASIC_LOAD_ADDRESS == 0x1900
|
|
16
|
+
|
|
17
|
+
def test_electron_basic_load_address(self):
|
|
18
|
+
assert basic.ELECTRON_BASIC_LOAD_ADDRESS == 0x0E00
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TestTokeniseStub:
|
|
22
|
+
def test_tokenise_raises_not_implemented(self):
|
|
23
|
+
with pytest.raises(NotImplementedError):
|
|
24
|
+
basic.tokenise('10 PRINT "Hello"')
|
|
25
|
+
|
|
26
|
+
def test_tokenise_raises_on_empty_input(self):
|
|
27
|
+
with pytest.raises(NotImplementedError):
|
|
28
|
+
basic.tokenise("")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TestDetokeniseStub:
|
|
32
|
+
def test_detokenise_raises_not_implemented(self):
|
|
33
|
+
with pytest.raises(NotImplementedError):
|
|
34
|
+
basic.detokenise(b"\x0d\xff")
|
|
35
|
+
|
|
36
|
+
def test_detokenise_raises_on_empty_input(self):
|
|
37
|
+
with pytest.raises(NotImplementedError):
|
|
38
|
+
basic.detokenise(b"")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TestModuleIsolation:
|
|
42
|
+
"""The basic module is destined for a standalone oaknut-basic
|
|
43
|
+
package, so it must not import anything from the rest of
|
|
44
|
+
oaknut.dfs. Guard against regressions."""
|
|
45
|
+
|
|
46
|
+
def test_no_oaknut_dfs_imports_in_basic(self):
|
|
47
|
+
import ast
|
|
48
|
+
from pathlib import Path
|
|
49
|
+
|
|
50
|
+
source = Path(basic.__file__).read_text()
|
|
51
|
+
tree = ast.parse(source)
|
|
52
|
+
|
|
53
|
+
for node in ast.walk(tree):
|
|
54
|
+
if isinstance(node, ast.ImportFrom):
|
|
55
|
+
assert node.module is None or not node.module.startswith("oaknut.dfs"), (
|
|
56
|
+
f"basic.py must not import from oaknut.dfs: {ast.dump(node)}"
|
|
57
|
+
)
|
|
58
|
+
elif isinstance(node, ast.Import):
|
|
59
|
+
for alias in node.names:
|
|
60
|
+
assert not alias.name.startswith("oaknut.dfs"), (
|
|
61
|
+
f"basic.py must not import from oaknut.dfs: {alias.name}"
|
|
62
|
+
)
|