Update manuals and other additions

This commit is contained in:
2026-06-09 12:45:33 -05:00
parent 051b12f28d
commit 78fb8d6d7c
101 changed files with 1629 additions and 401 deletions
+75 -75
View File
@@ -10,100 +10,100 @@ REF = EXAMPLES / "ref"
# Every numbered Reference Manual section maps to at least one example or test corpus file.
REFERENCE_MANUAL_SECTIONS: dict[str, list[str]] = {
"1.0": ["ref/ref_1_0_introduction.protel"],
"2.0": ["ref/ref_9_1_expressions.protel"],
"3.0": ["ref/ref_3_0_lexical.protel"],
"3.1": ["ref/ref_3_0_lexical.protel"],
"3.2": ["ref/ref_3_0_lexical.protel"],
"3.3": ["ref/ref_3_0_lexical.protel"],
"3.4": ["ref/ref_3_0_lexical.protel"],
"4.0": ["ref/ref_4_0_data_elements.protel"],
"4.1": ["ref/ref_4_0_data_elements.protel"],
"4.2": ["ref/ref_4_0_data_elements.protel"],
"4.3": ["ref/ref_4_0_data_elements.protel"],
"4.4": ["ref/ref_4_0_data_elements.protel"],
"4.5": ["ref/ref_4_0_data_elements.protel"],
"1.0": ["ref/ref_1_0_introduction.P"],
"2.0": ["ref/ref_9_1_expressions.P"],
"3.0": ["ref/ref_3_0_lexical.P"],
"3.1": ["ref/ref_3_0_lexical.P"],
"3.2": ["ref/ref_3_0_lexical.P"],
"3.3": ["ref/ref_3_0_lexical.P"],
"3.4": ["ref/ref_3_0_lexical.P"],
"4.0": ["ref/ref_4_0_data_elements.P"],
"4.1": ["ref/ref_4_0_data_elements.P"],
"4.2": ["ref/ref_4_0_data_elements.P"],
"4.3": ["ref/ref_4_0_data_elements.P"],
"4.4": ["ref/ref_4_0_data_elements.P"],
"4.5": ["ref/ref_4_0_data_elements.P"],
"5.0": [
"ref/ref_5_0_compilation_unit.protel",
"ref/ref_5_0_compilation_unit.P",
"ref/ref_5_0_directives.aa01",
"Hello.aa01",
],
"6.0": ["ref/ref_6_0_module_types.protel"],
"7.0": ["ref/ref_7_0_declarations.protel"],
"7.1": ["ref/ref_7_1_1_simple_types.protel", "ref/ref_7_1_2_aggregates.protel"],
"7.1.1": ["ref/ref_7_1_1_simple_types.protel"],
"7.1.1.1": ["ref/ref_7_1_1_simple_types.protel"],
"7.1.1.2": ["intro_2_1_types.protel"],
"7.1.1.3": ["ref/ref_7_1_1_simple_types.protel", "intro_2_1_types.protel"],
"7.1.1.4": ["ref/ref_7_1_1_simple_types.protel"],
"7.1.1.5": ["ref/ref_7_1_1_simple_types.protel"],
"7.1.2": ["ref/ref_7_1_2_aggregates.protel"],
"7.1.2.1": ["ref/ref_7_1_2_aggregates.protel"],
"7.1.2.2": ["ref/ref_7_1_2_aggregates.protel", "ref_8_1_task_block_struct.protel"],
"7.1.2.3": ["intro_2_1_types.protel", "intro_3_2_6_sum_table.protel"],
"7.1.2.4": ["intro_2_1_types.protel"],
"7.1.2.5": ["ref/ref_7_1_2_aggregates.protel"],
"7.1.3": ["ref/ref_7_1_3_procedures.protel"],
"7.1.3.1": ["ref/ref_7_1_3_procedures.protel"],
"7.1.3.2": ["ref/ref_7_1_3_procedures.protel"],
"7.2": ["ref/ref_7_2_data_declarations.protel"],
"7.2.1": ["ref/ref_7_2_data_declarations.protel"],
"7.2.2": ["intro_2_2_calculate_average.protel"],
"7.2.3": ["ref/ref_7_2_data_declarations.protel"],
"7.3": ["ref/ref_7_3_overlays.protel"],
"8.0": ["ref/ref_8_0_scope.protel"],
"8.1": ["ref/ref_8_0_scope.protel"],
"8.2": ["ref/ref_8_0_scope.protel"],
"9.0": ["ref/ref_9_0_statements.protel"],
"9.1": ["ref/ref_9_1_expressions.protel"],
"9.1.1": ["ref/ref_9_1_expressions.protel"],
"9.1.1.1": ["ref/ref_4_0_data_elements.protel"],
"9.1.1.2": ["ref/ref_9_1_expressions.protel"],
"9.1.1.3": ["ref/ref_7_1_3_procedures.protel"],
"9.1.2": ["ref/ref_9_1_expressions.protel"],
"9.2": ["ref/ref_9_2_return.protel", "intro_5_5_2_args_exit.protel"],
"9.3": ["ref/ref_9_3_if.protel"],
"9.4": ["ref/ref_9_4_case.protel", "intro_3_2_4_case.protel"],
"9.5": ["ref/ref_9_5_select.protel"],
"9.6": ["ref/ref_9_6_exit.protel"],
"6.0": ["ref/ref_6_0_module_types.P"],
"7.0": ["ref/ref_7_0_declarations.P"],
"7.1": ["ref/ref_7_1_1_simple_types.P", "ref/ref_7_1_2_aggregates.P"],
"7.1.1": ["ref/ref_7_1_1_simple_types.P"],
"7.1.1.1": ["ref/ref_7_1_1_simple_types.P"],
"7.1.1.2": ["intro_2_1_types.P"],
"7.1.1.3": ["ref/ref_7_1_1_simple_types.P", "intro_2_1_types.P"],
"7.1.1.4": ["ref/ref_7_1_1_simple_types.P"],
"7.1.1.5": ["ref/ref_7_1_1_simple_types.P"],
"7.1.2": ["ref/ref_7_1_2_aggregates.P"],
"7.1.2.1": ["ref/ref_7_1_2_aggregates.P"],
"7.1.2.2": ["ref/ref_7_1_2_aggregates.P", "ref_8_1_task_block_struct.P"],
"7.1.2.3": ["intro_2_1_types.P", "intro_3_2_6_sum_table.P"],
"7.1.2.4": ["intro_2_1_types.P"],
"7.1.2.5": ["ref/ref_7_1_2_aggregates.P"],
"7.1.3": ["ref/ref_7_1_3_procedures.P"],
"7.1.3.1": ["ref/ref_7_1_3_procedures.P"],
"7.1.3.2": ["ref/ref_7_1_3_procedures.P"],
"7.2": ["ref/ref_7_2_data_declarations.P"],
"7.2.1": ["ref/ref_7_2_data_declarations.P"],
"7.2.2": ["intro_2_2_calculate_average.P"],
"7.2.3": ["ref/ref_7_2_data_declarations.P"],
"7.3": ["ref/ref_7_3_overlays.P"],
"8.0": ["ref/ref_8_0_scope.P"],
"8.1": ["ref/ref_8_0_scope.P"],
"8.2": ["ref/ref_8_0_scope.P"],
"9.0": ["ref/ref_9_0_statements.P"],
"9.1": ["ref/ref_9_1_expressions.P"],
"9.1.1": ["ref/ref_9_1_expressions.P"],
"9.1.1.1": ["ref/ref_4_0_data_elements.P"],
"9.1.1.2": ["ref/ref_9_1_expressions.P"],
"9.1.1.3": ["ref/ref_7_1_3_procedures.P"],
"9.1.2": ["ref/ref_9_1_expressions.P"],
"9.2": ["ref/ref_9_2_return.P", "intro_5_5_2_args_exit.P"],
"9.3": ["ref/ref_9_3_if.P"],
"9.4": ["ref/ref_9_4_case.P", "intro_3_2_4_case.P"],
"9.5": ["ref/ref_9_5_select.P"],
"9.6": ["ref/ref_9_6_exit.P"],
"9.7": [
"ref/ref_9_7_iterative.protel",
"intro_1_3_factorial.protel",
"intro_1_3_factorial_cli.protel",
"intro_3_2_6_sum_table.protel",
"ref/ref_9_7_iterative.P",
"intro_1_3_factorial.P",
"intro_1_3_factorial_cli.P",
"intro_3_2_6_sum_table.P",
],
"10.0": ["ref/ref_10_0_bind_with.protel"],
"11.0": ["ref/ref_11_0_type_compat.protel"],
"11.1": ["ref/ref_11_0_type_compat.protel"],
"11.2": ["ref/ref_11_0_type_compat.protel"],
"11.3": ["ref/ref_11_0_type_compat.protel"],
"12.0": ["ref/ref_12_0_intrinsic.protel"],
"10.0": ["ref/ref_10_0_bind_with.P"],
"11.0": ["ref/ref_11_0_type_compat.P"],
"11.1": ["ref/ref_11_0_type_compat.P"],
"11.2": ["ref/ref_11_0_type_compat.P"],
"11.3": ["ref/ref_11_0_type_compat.P"],
"12.0": ["ref/ref_12_0_intrinsic.P"],
"13.0": [
"ref/ref_13_0_descriptors.protel",
"interop/protel_for_python.protel",
"interop/protel_calls_python.protel",
"Hello.protel",
"ref/ref_13_0_descriptors.P",
"interop/protel_for_python.P",
"interop/protel_calls_python.P",
"Hello.P",
],
"14.0": ["ref/ref_14_0_keyword_exercise.protel"],
"14.0": ["ref/ref_14_0_keyword_exercise.P"],
"15.0": ["tests/test_parser.py"],
"16.0": ["tests/ref_manual_manifest.py"],
"OO": ["ref/ref_oo_classes.protel", "ref_oo_class_with_var.protel", "ref_oo_class_method_invoke.protel"],
"OO": ["ref/ref_oo_classes.P", "ref_oo_class_with_var.P", "ref_oo_class_method_invoke.P"],
}
# Keywords exercised outside .protel examples (preprocessor / tooling).
# Keywords exercised outside .P examples (preprocessor / tooling).
KEYWORD_EXTERNAL_SOURCES: dict[str, list[str]] = {
"$EJECT": ["ref/ref_5_0_directives.aa01", "tests/test_pb.py"],
"$LI": ["ref/ref_5_0_directives.aa01", "vdi.aa01", "tests/test_pb.py"],
"$OBJECT": ["ref/ref_oo_classes.protel", "ref_oo_class_with_var.protel"],
"$REFDESC": ["ref/ref_9_1_expressions.protel"],
"$TYPEDESC": ["ref/ref_9_1_expressions.protel"],
"$UNIVERSAL_PTR": ["ref/ref_9_1_expressions.protel"],
"$VARDESC": ["ref/ref_9_1_expressions.protel"],
"$OBJECT": ["ref/ref_oo_classes.P", "ref_oo_class_with_var.P"],
"$REFDESC": ["ref/ref_9_1_expressions.P"],
"$TYPEDESC": ["ref/ref_9_1_expressions.P"],
"$UNIVERSAL_PTR": ["ref/ref_9_1_expressions.P"],
"$VARDESC": ["ref/ref_9_1_expressions.P"],
}
# All ref_* and intro_* example files that must parse.
REF_EXAMPLE_SOURCES: list[str] = sorted(
p.relative_to(EXAMPLES).as_posix()
for p in EXAMPLES.rglob("*.protel")
for p in EXAMPLES.rglob("*.P")
if p.is_file() and not p.name.endswith("~")
)
+2 -2
View File
@@ -10,8 +10,8 @@ from src.parser import parse_protel
from src.transpiler import TranspileError
ROOT = Path(__file__).resolve().parent.parent
EXAMPLE = ROOT / "examples" / "intro_5_5_2_args_exit.protel"
PROTEL = ROOT / "protel"
EXAMPLE = ROOT / "examples" / "intro_5_5_2_args_exit.P"
PROTEL = ROOT / "Pc"
PYTHON = ROOT / ".venv" / "bin" / "python"
+14 -14
View File
@@ -10,26 +10,26 @@ from src.cpp_transpiler import transpile_to_cpp
ROOT = Path(__file__).resolve().parent.parent
EXAMPLES = ROOT / "examples"
PROTEL = ROOT / "protel"
PROTEL = ROOT / "Pc"
def _transpile_hello() -> str:
source = (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
source = (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
tree = parse_protel(source)
return transpile_to_cpp(tree, source_name="Hello.protel")
return transpile_to_cpp(tree, source_name="Hello.P")
def test_cpp_hello_emits_namespace_and_main():
cpp = _transpile_hello()
assert "namespace protel_generated" in cpp
assert "namespace Hello" in cpp
assert "IS ENTRY" in (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
assert "IS ENTRY" in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "void Start()" in cpp
assert 'extern "C"' in cpp
assert "void writeln(const char* msg)" in cpp
assert "<iostream>" not in cpp
assert "IS INTRINSIC" not in (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
assert "EXTERNAL" in (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
assert "IS INTRINSIC" not in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "EXTERNAL" in (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "int main()" in cpp
assert "protel_generated::Hello::Start()" in cpp
assert "(const char[]){" in cpp
@@ -38,8 +38,8 @@ def test_cpp_hello_emits_namespace_and_main():
def test_cpp_hello_class_uses_this():
source = (EXAMPLES / "ref_oo_class_with_var.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="ref_oo_class_with_var.protel")
source = (EXAMPLES / "ref_oo_class_with_var.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="ref_oo_class_with_var.P")
assert "class class_with_var" in cpp
assert "static int16_t class_var" in cpp
assert "class_with_var::class_method" in cpp
@@ -53,7 +53,7 @@ def test_hello_compiles_and_runs():
[
str(ROOT / ".venv/bin/python"),
str(PROTEL),
str(EXAMPLES / "Hello.protel"),
str(EXAMPLES / "Hello.P"),
"-o",
str(ROOT / "build" / "Hello"),
"--run",
@@ -67,8 +67,8 @@ def test_hello_compiles_and_runs():
def test_hello_shebang_direct_execution():
hello = EXAMPLES / "Hello.protel"
assert hello.read_text(encoding="utf-8").startswith("#!/usr/bin/env protel-run")
hello = EXAMPLES / "Hello.P"
assert hello.read_text(encoding="utf-8").startswith("#!/usr/bin/env Pc!")
mode = hello.stat().st_mode
hello.chmod(mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
env = dict(os.environ)
@@ -86,7 +86,7 @@ def test_hello_shebang_direct_execution():
def test_hello_compiles_and_runs_a_out():
result = subprocess.run(
[str(ROOT / ".venv/bin/python"), str(PROTEL), "examples/Hello.protel", "--run"],
[str(ROOT / ".venv/bin/python"), str(PROTEL), "examples/Hello.P", "--run"],
capture_output=True,
text=True,
cwd=ROOT,
@@ -99,11 +99,11 @@ def test_hello_compiles_and_runs_a_out():
def test_cpp_oo_examples_compile():
from src.compile import check_cpp_syntax
for name in ("ref_oo_class_with_var.protel", "ref_oo_class_method_invoke.protel"):
for name in ("ref_oo_class_with_var.P", "ref_oo_class_method_invoke.P"):
source = EXAMPLES / name
tree = parse_protel(source.read_text(encoding="utf-8"))
cpp = transpile_to_cpp(tree, source_name=name)
cpp_path = ROOT / "build" / f"{name.replace('.protel', '.cpp')}"
cpp_path = ROOT / "build" / f"{name.replace('.P', '.cpp')}"
cpp_path.parent.mkdir(parents=True, exist_ok=True)
cpp_path.write_text(cpp, encoding="utf-8")
check_cpp_syntax(cpp_path)
+5 -2
View File
@@ -13,14 +13,14 @@ from src.parser import parse_protel
ROOT = Path(__file__).resolve().parent.parent
EXAMPLES = ROOT / "examples"
MODE_EL = ROOT / "emacs" / "protel-mode.el"
PROTEL = ROOT / "protel"
PROTEL = ROOT / "Pc"
@pytest.mark.parametrize(
"name,expected",
[
("Hello.protel", True),
("Hello.P", True),
("Hello.protel", True),
("Hello.p", True),
("Hello.pt", True),
("Hello.ptl", True),
@@ -42,11 +42,14 @@ def test_is_protel_source_recognizes_fixed_and_pls_suffixes(name, expected):
def test_is_pls_suffix_matches_letter_digit_pattern():
assert is_pls_suffix(".aa01")
assert is_pls_suffix(".AB99")
assert not is_pls_suffix(".P")
assert not is_pls_suffix(".protel")
def test_format_suffix_list_mentions_pls_range():
text = format_suffix_list()
assert ".P" in text
assert "default" in text
assert ".AA01" in text
assert ".ZZ99" in text
+2 -2
View File
@@ -21,7 +21,7 @@ SECTION Hello;
DCL Start PROC() IS ENTRY;
DCL Start PROC() IS BLOCK ENDBLOCK;
"""
cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.protel")
cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.P")
assert "/* ENTRY Start */" in cpp
assert "void Start()" in cpp
assert "int main()" in cpp
@@ -34,7 +34,7 @@ def test_procedure_named_main_without_entry_has_no_c_main():
SECTION demo;
DCL main PROC() IS BLOCK ENDBLOCK;
"""
cpp = transpile_to_cpp(parse_protel(source), source_name="demo.protel")
cpp = transpile_to_cpp(parse_protel(source), source_name="demo.P")
assert "void main()" in cpp
assert "int main()" not in cpp
+3 -3
View File
@@ -7,9 +7,9 @@ from src.cpp_transpiler import transpile_to_cpp
from src.parser import parse_protel
ROOT = Path(__file__).resolve().parent.parent
EXAMPLE = ROOT / "examples" / "intro_1_3_factorial_cli.protel"
FACTORIAL = ROOT / "examples" / "intro_1_3_factorial.protel"
PROTEL = ROOT / "protel"
EXAMPLE = ROOT / "examples" / "intro_1_3_factorial_cli.P"
FACTORIAL = ROOT / "examples" / "intro_1_3_factorial.P"
PROTEL = ROOT / "Pc"
PYTHON = ROOT / ".venv" / "bin" / "python"
+68
View File
@@ -0,0 +1,68 @@
"""System-wide install Makefile targets (staged under DESTDIR)."""
import os
import shutil
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
def _make(*targets: str, env: dict | None = None) -> subprocess.CompletedProcess:
run_env = os.environ.copy()
if env:
run_env.update(env)
return subprocess.run(
["make", *targets],
cwd=ROOT,
capture_output=True,
text=True,
env=run_env,
)
def test_install_system_staged_layout():
stage = ROOT / "build" / "install-stage"
if stage.exists():
shutil.rmtree(stage)
prefix = "/usr/local/protel"
result = _make(
"install-system",
env={
"DESTDIR": str(stage),
"SYSPREFIX": prefix,
"SYSBINDIR": "/usr/local/bin",
"SYSMANPREFIX": "/usr/local/share/man",
},
)
assert result.returncode == 0, result.stderr + result.stdout
toolkit = stage / prefix.lstrip("/")
bindir = stage / "usr/local/bin"
mandir = stage / "usr/local/share/man/man1"
for name in ("Pc", "Pb", "Pc!"):
tool = toolkit / name
assert tool.is_file(), f"missing {tool}"
assert os.access(tool, os.X_OK)
link = bindir / name
assert link.is_symlink(), f"missing symlink {link}"
assert os.readlink(link) == f"{prefix}/{name}"
assert (toolkit / "src" / "parser.py").is_file()
assert (toolkit / "examples" / "Hello.P").is_file()
assert (toolkit / "emacs" / "protel-mode.el").is_file()
assert (toolkit / ".venv" / "bin" / "python3").is_file()
assert (mandir / "Pc.1").is_file()
assert (mandir / "Pb.1").is_file()
shutil.rmtree(stage)
def test_makefile_declares_install_system_target():
makefile = (ROOT / "Makefile").read_text(encoding="utf-8")
assert "install-system:" in makefile
assert "install-man-system:" in makefile
assert "uninstall-system:" in makefile
assert "SYSPREFIX ?=" in makefile
assert "/usr/local/protel" in makefile
+4 -4
View File
@@ -24,8 +24,8 @@ def _java_runtime_available() -> bool:
def test_protel_calls_java_emits_external_java_greet():
source = (INTEROP / "protel_calls_java.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_java.protel")
source = (INTEROP / "protel_calls_java.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_java.P")
assert 'extern "C"' in cpp
assert "void java_greet(const char* name, int16_t value)" in cpp
assert "java_greet(" in cpp
@@ -33,8 +33,8 @@ def test_protel_calls_java_emits_external_java_greet():
def test_protel_for_java_exports_c_linkage():
source = (INTEROP / "protel_for_java.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_java.protel")
source = (INTEROP / "protel_for_java.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_java.P")
assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp
+55
View File
@@ -0,0 +1,55 @@
"""Manual page presence and basic content checks."""
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
MAN = ROOT / "man"
def test_pc_man_page_exists_with_required_sections():
text = (MAN / "Pc.1").read_text(encoding="utf-8")
assert '.TH Pc 1' in text
for section in (
"SYNOPSIS",
"DESCRIPTION",
"OPTIONS",
"SHEBANG RUNNER",
"EXIT STATUS",
"EXAMPLES",
"SEE ALSO",
):
assert f".SH {section}" in text or section in text
assert "Pc!" in text
for option in (
"\\-\\-run",
"\\-\\-classical",
"\\-\\-emit\\-c",
"\\-\\-parse\\-only",
"\\-\\-compile",
"\\-\\-keep",
):
assert option in text
def test_pb_man_page_exists_with_required_sections():
text = (MAN / "Pb.1").read_text(encoding="utf-8")
assert '.TH Pb 1' in text
for section in (
"SYNOPSIS",
"DESCRIPTION",
"OPTIONS",
"BEHAVIOR",
"EXIT STATUS",
"EXAMPLES",
"SEE ALSO",
):
assert f".SH {section}" in text or f'.SH "{section}"' in text
assert "\\-\\-bold" in text
assert "shebang" in text.lower()
def test_install_man_layout_after_make():
man1 = MAN / "man1"
# install-man may not have been run; source pages must remain in man/
assert (MAN / "Pc.1").is_file()
assert (MAN / "Pb.1").is_file()
+10 -10
View File
@@ -24,7 +24,7 @@ def test_parse_section_uses_and_of():
def test_parse_factorial_example():
tree = parse_protel(_read("intro_1_3_factorial.protel"))
tree = parse_protel(_read("intro_1_3_factorial.P"))
assert len(tree) == 1
section = tree[0]
assert isinstance(section, ast.Section)
@@ -38,7 +38,7 @@ def test_parse_factorial_example():
def test_parse_types_example():
tree = parse_protel(_read("intro_2_1_types.protel"))
tree = parse_protel(_read("intro_2_1_types.P"))
section = tree[0]
type_names = {d.names[0] for d in section.declarations if isinstance(d, ast.TypeDecl)}
assert "integer" in type_names
@@ -47,7 +47,7 @@ def test_parse_types_example():
def test_parse_calculate_average():
tree = parse_protel(_read("intro_2_2_calculate_average.protel"))
tree = parse_protel(_read("intro_2_2_calculate_average.P"))
proc = next(
d for d in tree[0].declarations if isinstance(d, ast.ProcDecl)
)
@@ -69,7 +69,7 @@ def test_classical_keyword_casing():
def test_parse_case_statement():
tree = parse_protel(_read("intro_3_2_4_case.protel"))
tree = parse_protel(_read("intro_3_2_4_case.P"))
proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl))
case_stmt = proc.body.statements[0]
assert isinstance(case_stmt, ast.CaseStmt)
@@ -78,7 +78,7 @@ def test_parse_case_statement():
def test_parse_for_loop_with_upb():
tree = parse_protel(_read("intro_3_2_6_sum_table.protel"))
tree = parse_protel(_read("intro_3_2_6_sum_table.P"))
proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl))
for_stmt = next(s for s in proc.body.statements if isinstance(s, ast.ForStmt))
assert for_stmt.var == "i"
@@ -87,7 +87,7 @@ def test_parse_for_loop_with_upb():
def test_parse_struct_type():
tree = parse_protel(_read("ref_8_1_task_block_struct.protel"))
tree = parse_protel(_read("ref_8_1_task_block_struct.P"))
task_block = next(
d for d in tree[0].declarations
if isinstance(d, ast.TypeDecl) and d.names == ["task_block"]
@@ -97,13 +97,13 @@ def test_parse_struct_type():
def test_var_init_not_wrapped_in_tree():
tree = parse_protel(_read("intro_2_1_types.protel"))
tree = parse_protel(_read("intro_2_1_types.P"))
primes = next(d for d in tree[0].declarations if isinstance(d, ast.VarDecl) and "primes" in d.names)
assert isinstance(primes.init, ast.TupleLit)
def test_parse_class_type_with_operations():
tree = parse_protel(_read("ref_oo_class_with_var.protel"))
tree = parse_protel(_read("ref_oo_class_with_var.P"))
section = tree[0]
assert section.section_kind == "INTERFACE"
class_decl = next(
@@ -124,7 +124,7 @@ def test_parse_class_type_with_operations():
def test_parse_class_method_invocation():
tree = parse_protel(_read("ref_oo_class_method_invoke.protel"))
tree = parse_protel(_read("ref_oo_class_method_invoke.P"))
proc = next(d for d in tree[0].declarations if isinstance(d, ast.ProcDecl))
assert isinstance(proc.body.statements[0], ast.MethodCall)
assert proc.body.statements[0].name == "class_method"
@@ -132,7 +132,7 @@ def test_parse_class_method_invocation():
def test_parse_self_member_assignment():
tree = parse_protel(_read("ref_oo_class_with_var.protel"))
tree = parse_protel(_read("ref_oo_class_with_var.P"))
impl = tree[0].class_impls[0]
stmt = impl.declarations[0].body.statements[0]
assert isinstance(stmt, ast.AssignExpr)
+2 -2
View File
@@ -34,9 +34,9 @@ def test_dollar_li_line_with_leading_whitespace():
def test_pb_preserves_shebang_first_line():
pb = _load_pb()
source = "#!/usr/bin/env protel-run\nsection s;\nDCL x BOOL;\n"
source = "#!/usr/bin/env Pc!\nsection s;\nDCL x BOOL;\n"
result = pb.beautify_protel(source)
assert result.startswith("#!/usr/bin/env protel-run\n")
assert result.startswith("#!/usr/bin/env Pc!\n")
assert "SECTION" in result
assert "DCL" in result
+3 -3
View File
@@ -6,11 +6,11 @@ from src.parser import parse_protel
from src.preprocess import normalize_keywords, strip_shebang
ROOT = Path(__file__).resolve().parent.parent
HELLO = ROOT / "examples" / "Hello.protel"
HELLO = ROOT / "examples" / "Hello.P"
def test_strip_shebang_removes_first_line():
source = "#!/usr/bin/env -S protel --run --\nSECTION s;\n"
source = "#!/usr/bin/env -S Pc --run --\nSECTION s;\n"
assert strip_shebang(source) == "SECTION s;\n"
@@ -20,7 +20,7 @@ def test_strip_shebang_passthrough_without_hash_bang():
def test_normalize_keywords_strips_shebang_before_parse():
source = "#!/usr/bin/env protel --run\n% hi\nSECTION s;\n"
source = "#!/usr/bin/env Pc --run\n% hi\nSECTION s;\n"
norm = normalize_keywords(source)
assert "#!" not in norm
assert "SECTION" in norm
+4 -4
View File
@@ -15,8 +15,8 @@ INTEROP = ROOT / "examples" / "interop"
def test_protel_calls_python_emits_external_python_greet():
source = (INTEROP / "protel_calls_python.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_python.protel")
source = (INTEROP / "protel_calls_python.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_python.P")
assert 'extern "C"' in cpp
assert "void python_greet(const char* name, int16_t value)" in cpp
assert "python_greet(" in cpp
@@ -24,8 +24,8 @@ def test_protel_calls_python_emits_external_python_greet():
def test_protel_for_python_exports_c_linkage():
source = (INTEROP / "protel_for_python.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_python.protel")
source = (INTEROP / "protel_for_python.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_python.P")
assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp
+1 -1
View File
@@ -28,7 +28,7 @@ _KEYWORD_BOUNDARY = re.compile(
def _corpus_files() -> list[Path]:
patterns = (
"examples/**/*.protel",
"examples/**/*.P",
"examples/**/*.aa01",
"examples/**/*.P",
"vdi.aa01",
+4 -4
View File
@@ -14,8 +14,8 @@ INTEROP = ROOT / "examples" / "interop"
def test_protel_calls_rust_emits_external_rust_greet():
source = (INTEROP / "protel_calls_rust.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_rust.protel")
source = (INTEROP / "protel_calls_rust.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_rust.P")
assert 'extern "C"' in cpp
assert "void rust_greet(const char* name, int16_t value)" in cpp
assert "rust_greet(" in cpp
@@ -23,8 +23,8 @@ def test_protel_calls_rust_emits_external_rust_greet():
def test_protel_for_rust_exports_c_linkage():
source = (INTEROP / "protel_for_rust.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_rust.protel")
source = (INTEROP / "protel_for_rust.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_rust.P")
assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp
+2 -2
View File
@@ -33,9 +33,9 @@ def test_string_without_nul_emits_no_trailing_zero():
def test_hello_uses_explicit_nul_suffix():
source = (EXAMPLES / "Hello.protel").read_text(encoding="utf-8")
source = (EXAMPLES / "Hello.P").read_text(encoding="utf-8")
assert "{'Hello, World!', 0}" in source
cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.protel")
cpp = transpile_to_cpp(parse_protel(source), source_name="Hello.P")
assert "(const char[]){" in cpp
assert "'!'" in cpp
assert ", 0 }" in cpp
+4 -4
View File
@@ -14,8 +14,8 @@ INTEROP = ROOT / "examples" / "interop"
def test_protel_calls_swift_emits_external_swift_greet():
source = (INTEROP / "protel_calls_swift.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_swift.protel")
source = (INTEROP / "protel_calls_swift.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_calls_swift.P")
assert 'extern "C"' in cpp
assert "void swift_greet(const char* name, int16_t value)" in cpp
assert "swift_greet(" in cpp
@@ -23,8 +23,8 @@ def test_protel_calls_swift_emits_external_swift_greet():
def test_protel_for_swift_exports_c_linkage():
source = (INTEROP / "protel_for_swift.protel").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_swift.protel")
source = (INTEROP / "protel_for_swift.P").read_text(encoding="utf-8")
cpp = transpile_to_cpp(parse_protel(source), source_name="protel_for_swift.P")
assert "/* EXPORT protel_add" in cpp
assert "int16_t protel_add(int16_t a, int16_t b)" in cpp
assert "return (a + b)" in cpp
+9 -9
View File
@@ -15,40 +15,40 @@ def _transpile_example(name: str) -> str:
def test_transpile_factorial_contains_procedure():
c = _transpile_example("intro_1_3_factorial.protel")
c = _transpile_example("intro_1_3_factorial.P")
assert "int16_t factorial(" in c
assert "while (" in c
assert "return result;" in c
def test_transpile_types_emits_typedefs():
c = _transpile_example("intro_2_1_types.protel")
c = _transpile_example("intro_2_1_types.P")
assert "typedef int16_t integer;" in c
assert "typedef int16_t digit_register[16];" in c
assert "seconds_per_hour" in c
def test_transpile_assignment_maps_arrow_to_equals():
c = _transpile_example("intro_2_2_calculate_average.protel")
c = _transpile_example("intro_2_2_calculate_average.P")
assert "average =" in c
assert "return average;" in c
def test_transpile_case_emits_switch():
c = _transpile_example("intro_3_2_4_case.protel")
c = _transpile_example("intro_3_2_4_case.P")
assert "switch (n)" in c
assert "case 0:" in c
assert "default:" not in c
def test_transpile_for_emits_c_for_loop():
c = _transpile_example("intro_3_2_6_sum_table.protel")
c = _transpile_example("intro_3_2_6_sum_table.P")
assert "for (int32_t i = 0;" in c
assert "return sum;" in c
def test_transpile_struct_emits_fields():
c = _transpile_example("ref_8_1_task_block_struct.protel")
c = _transpile_example("ref_8_1_task_block_struct.P")
assert "typedef struct {" in c
assert "uint8_t priority;" in c
assert "uint8_t completed;" in c
@@ -56,7 +56,7 @@ def test_transpile_struct_emits_fields():
def test_transpile_class_type_emits_static_class_var():
c = _transpile_example("ref_oo_class_with_var.protel")
c = _transpile_example("ref_oo_class_with_var.P")
assert "typedef struct class_with_var_t" in c
assert "static int16_t class_with_var_class_var" in c
assert "void class_with_var_class_method(int16_t parameter)" in c
@@ -64,12 +64,12 @@ def test_transpile_class_type_emits_static_class_var():
def test_transpile_class_method_invocation():
c = _transpile_example("ref_oo_class_method_invoke.protel")
c = _transpile_example("ref_oo_class_method_invoke.P")
assert "class_with_class_method_class_method(5)" in c
assert "class_with_class_method_class_method(6)" in c
def test_transpile_emits_header():
c = _transpile_example("intro_1_3_factorial.protel")
c = _transpile_example("intro_1_3_factorial.P")
assert "Generated by PROTEL 2026 transpiler" in c
assert "#include <stdint.h>" in c
+13 -13
View File
@@ -19,15 +19,15 @@ def _read(name: str) -> str:
@pytest.mark.parametrize(
"filename,message_fragment",
[
("err_assign_integer_to_char.protel", "cannot assign integer to char"),
("err_assign_integer_to_char.P", "cannot assign integer to char"),
(
"err_assign_integer_to_packed_byte.protel",
"err_assign_integer_to_packed_byte.P",
"packed byte-sized type",
),
("err_assign_integer_to_bool.protel", "cannot assign"),
("err_constant_out_of_range.protel", "out of range"),
("err_assign_incompatible_pointer.protel", "cannot assign"),
("err_return_type_mismatch.protel", "RETURN type"),
("err_assign_integer_to_bool.P", "cannot assign"),
("err_constant_out_of_range.P", "out of range"),
("err_assign_incompatible_pointer.P", "cannot assign"),
("err_return_type_mismatch.P", "RETURN type"),
],
)
def test_error_examples_fail_type_check(filename: str, message_fragment: str):
@@ -38,9 +38,9 @@ def test_error_examples_fail_type_check(filename: str, message_fragment: str):
def test_ok_char_literal_transpiles():
source = _read("ok_assign_char_literal.protel")
source = _read("ok_assign_char_literal.P")
tree = parse_protel(source)
cpp = transpile_to_cpp(tree, source_name="ok_assign_char_literal.protel")
cpp = transpile_to_cpp(tree, source_name="ok_assign_char_literal.P")
assert "Generated by PROTEL" in cpp
@@ -50,8 +50,8 @@ def test_protel_driver_reports_type_error():
result = subprocess.run(
[
str(ROOT / ".venv" / "bin" / "python"),
str(ROOT / "protel"),
str(ERRORS / "err_assign_integer_to_char.protel"),
str(ROOT / "Pc"),
str(ERRORS / "err_assign_integer_to_char.P"),
"--parse-only",
],
capture_output=True,
@@ -63,13 +63,13 @@ def test_protel_driver_reports_type_error():
result = subprocess.run(
[
str(ROOT / ".venv" / "bin" / "python"),
str(ROOT / "protel"),
str(ERRORS / "err_assign_integer_to_char.protel"),
str(ROOT / "Pc"),
str(ERRORS / "err_assign_integer_to_char.P"),
],
capture_output=True,
text=True,
cwd=ROOT,
)
assert result.returncode == 1
assert "protel: type error" in result.stderr
assert "Pc: type error" in result.stderr
assert "cannot assign integer to char" in result.stderr
+1 -1
View File
@@ -9,7 +9,7 @@ from src.preprocess import normalize_keywords
ROOT = Path(__file__).resolve().parent.parent
VDI = ROOT / "vdi.aa01"
PROTEL = ROOT / "protel"
PROTEL = ROOT / "Pc"
def test_preprocess_strips_dollar_li_directive():