Update manuals and other additions
This commit is contained in:
@@ -42,7 +42,7 @@ def _sanitize_namespace(name: str) -> str:
|
||||
|
||||
|
||||
class CppTranspiler(CTranspiler):
|
||||
def __init__(self, *, classical: bool = False, source_name: str = "input.protel"):
|
||||
def __init__(self, *, classical: bool = False, source_name: str = "input.P"):
|
||||
super().__init__(classical=classical, source_name=source_name)
|
||||
self._cpp = True
|
||||
self._current_namespace: str | None = None
|
||||
@@ -724,7 +724,7 @@ def transpile_to_cpp(
|
||||
compilation_unit,
|
||||
*,
|
||||
classical: bool = False,
|
||||
source_name: str = "input.protel",
|
||||
source_name: str = "input.P",
|
||||
source_path: Path | None = None,
|
||||
) -> str:
|
||||
from .module_resolver import resolve_compilation_unit
|
||||
@@ -747,7 +747,7 @@ def transpile_file_cpp(
|
||||
source: str,
|
||||
*,
|
||||
classical: bool = False,
|
||||
source_name: str = "input.protel",
|
||||
source_name: str = "input.P",
|
||||
) -> str:
|
||||
from .parser import parse_protel
|
||||
|
||||
|
||||
+18
-5
@@ -5,14 +5,21 @@ from __future__ import annotations
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# Modern / distribution suffixes (case-insensitive except where noted).
|
||||
_FIXED_SUFFIXES = frozenset({".protel", ".pt", ".ptl", ".p"})
|
||||
# Default distribution suffix (historical Nortel/BNR). The compiler does not
|
||||
# require any particular extension; these are conventions for tooling and Emacs.
|
||||
DEFAULT_SUFFIX = ".P"
|
||||
|
||||
# Recognized suffixes (case-insensitive except where noted).
|
||||
_FIXED_SUFFIXES = frozenset({".p", ".protel", ".pt", ".ptl"})
|
||||
|
||||
# PLS edition suffix: .AA01 .. .ZZ99 (two letters + two digits).
|
||||
_PLS_SUFFIX_RE = re.compile(r"\.[A-Za-z]{2}\d{2}$")
|
||||
|
||||
PLS_SUFFIX_DESCRIPTION = ".AA01 through .ZZ99 (two letters + two digits)"
|
||||
|
||||
# USES module lookup order when the section index has no entry.
|
||||
_USES_SUFFIXES = (DEFAULT_SUFFIX, ".protel", ".pt", ".ptl")
|
||||
|
||||
|
||||
def is_pls_suffix(suffix: str) -> bool:
|
||||
"""True when suffix matches legacy PLS edition form (e.g. .AA01, .aa01)."""
|
||||
@@ -32,6 +39,12 @@ def is_protel_source(path: str | Path) -> bool:
|
||||
|
||||
|
||||
def format_suffix_list() -> str:
|
||||
"""Human-readable suffix list for CLI messages."""
|
||||
fixed = ", ".join(sorted(_FIXED_SUFFIXES))
|
||||
return f"{fixed}, {PLS_SUFFIX_DESCRIPTION}"
|
||||
"""Human-readable suffix list for CLI messages (.P listed first as default)."""
|
||||
others = sorted(s for s in _FIXED_SUFFIXES if s.lower() != DEFAULT_SUFFIX.lower())
|
||||
fixed = f"{DEFAULT_SUFFIX} (default), " + ", ".join(others)
|
||||
return f"{fixed}, {PLS_SUFFIX_DESCRIPTION}"
|
||||
|
||||
|
||||
def uses_module_candidates(module_name: str) -> list[Path]:
|
||||
"""Candidate filenames for USES module resolution (stem only; caller adds directory)."""
|
||||
return [Path(f"{module_name}{suffix}") for suffix in _USES_SUFFIXES]
|
||||
@@ -6,7 +6,7 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
from . import ast_nodes as ast
|
||||
from .extensions import is_protel_source
|
||||
from .extensions import is_protel_source, uses_module_candidates
|
||||
from .parser import parse_protel
|
||||
from .transpiler import TranspileError
|
||||
|
||||
@@ -59,9 +59,10 @@ def _find_module_path(
|
||||
if module_name in index:
|
||||
return index[module_name]
|
||||
for base in _search_dirs(source_path):
|
||||
candidate = base / f"{module_name}.protel"
|
||||
if candidate.is_file():
|
||||
return candidate.resolve()
|
||||
for candidate in uses_module_candidates(module_name):
|
||||
path = base / candidate
|
||||
if path.is_file():
|
||||
return path.resolve()
|
||||
return None
|
||||
|
||||
|
||||
@@ -133,7 +134,7 @@ def resolve_compilation_unit(
|
||||
path = _find_module_path(module_name, source_path=source_path, index=index)
|
||||
if path is None:
|
||||
print(
|
||||
f"protel: warning: USES module {module_name!r} not found; "
|
||||
f"Pc: warning: USES module {module_name!r} not found; "
|
||||
f"skipping embed",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
+5
-5
@@ -36,7 +36,7 @@ class TypeContext:
|
||||
|
||||
|
||||
class CTranspiler:
|
||||
def __init__(self, *, classical: bool = False, source_name: str = "input.protel"):
|
||||
def __init__(self, *, classical: bool = False, source_name: str = "input.P"):
|
||||
self.classical = classical
|
||||
self.source_name = source_name
|
||||
self.types = TypeContext()
|
||||
@@ -747,13 +747,13 @@ class CTranspiler:
|
||||
|
||||
if protel_str is not None:
|
||||
msg = (
|
||||
f"protel: warning: call to {proc_name} uses a PROTEL string without "
|
||||
f"Pc: warning: call to {proc_name} uses a PROTEL string without "
|
||||
f"an explicit NUL (0) suffix; append ', 0' in a char tuple for C "
|
||||
f"interoperability"
|
||||
)
|
||||
else:
|
||||
msg = (
|
||||
f"protel: warning: call to {proc_name} uses a char tuple without "
|
||||
f"Pc: warning: call to {proc_name} uses a char tuple without "
|
||||
f"a trailing 0 byte for C interoperability"
|
||||
)
|
||||
print(msg, file=sys.stderr)
|
||||
@@ -796,7 +796,7 @@ def transpile_to_c(
|
||||
compilation_unit,
|
||||
*,
|
||||
classical: bool = False,
|
||||
source_name: str = "input.protel",
|
||||
source_name: str = "input.P",
|
||||
source_path: "Path | None" = None,
|
||||
) -> str:
|
||||
from pathlib import Path
|
||||
@@ -815,7 +815,7 @@ def transpile_to_c(
|
||||
return CTranspiler(classical=classical, source_name=source_name).transpile(compilation_unit)
|
||||
|
||||
|
||||
def transpile_file(source: str, *, classical: bool = False, source_name: str = "input.protel") -> str:
|
||||
def transpile_file(source: str, *, classical: bool = False, source_name: str = "input.P") -> str:
|
||||
from .parser import parse_protel
|
||||
|
||||
tree = parse_protel(source, classical=classical)
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ class TypeInfo:
|
||||
|
||||
|
||||
class TypeChecker:
|
||||
def __init__(self, *, source_name: str = "input.protel"):
|
||||
def __init__(self, *, source_name: str = "input.P"):
|
||||
self.source_name = source_name
|
||||
self.types = TypeContext()
|
||||
self._scopes: list[dict[str, TypeInfo]] = [{}]
|
||||
@@ -333,6 +333,6 @@ class TypeChecker:
|
||||
def check_types(
|
||||
compilation_unit: list[ast.Section],
|
||||
*,
|
||||
source_name: str = "input.protel",
|
||||
source_name: str = "input.P",
|
||||
) -> None:
|
||||
TypeChecker(source_name=source_name).check(compilation_unit)
|
||||
Reference in New Issue
Block a user