Skip to content

Commit 6a06c2d

Browse files
committed
Re-implement _symbol_ident
1 parent 92fa2bb commit 6a06c2d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pyk/src/pyk/k2lean4/k2lean4.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
from __future__ import annotations
22

3+
import re
34
from dataclasses import dataclass
45
from typing import TYPE_CHECKING
56

7+
from ..konvert import unmunge
68
from ..kore.internal import CollectionKind
79
from ..kore.syntax import SortApp
810
from ..utils import check_type
911
from .model import Abbrev, Ctor, ExplBinder, Inductive, Module, Signature, Term
1012

1113
if TYPE_CHECKING:
14+
from typing import Final
15+
1216
from ..kore.internal import KoreDefn
1317
from .model import Command
1418

1519

20+
_VALID_LEAN_IDENT: Final = re.compile(
21+
"_[a-zA-Z_?!']+|[a-zA-Z][a-zA-Z_?!']*"
22+
) # Simplified to characters permitted in KORE in the first place
23+
24+
1625
@dataclass(frozen=True)
1726
class K2Lean4:
1827
defn: KoreDefn
@@ -52,7 +61,12 @@ def _symbol_ctor(self, sort: str, symbol: str) -> Ctor:
5261

5362
@staticmethod
5463
def _symbol_ident(symbol: str) -> str:
55-
return symbol.replace('-', '_')
64+
if symbol.startswith('Lbl'):
65+
symbol = symbol[3:]
66+
symbol = unmunge(symbol)
67+
if not _VALID_LEAN_IDENT.match(symbol):
68+
symbol = f'«{symbol}»'
69+
return symbol
5670

5771
def _collections(self) -> list[Command]:
5872
return [self._collection(sort) for sort in sorted(self.defn.collections)]

0 commit comments

Comments
 (0)