from abc import ABC from collections.abc import Mapping from dataclasses import dataclass, field from enum import Enum from typing import ClassVar from lsprotocol.types import SymbolKind class SkillDataType(Enum): array = "a" """array""" ddUserType = "b" """Boolean""" opfcontext = "C" """OPF Context""" dbobject = "d" """Cadence database object (CDBA)""" envobj = "e" """environment""" flonum = "f" """floating-point number""" opffile = "F" """OPF file ID""" general = "g" """any data type""" nil = "g" """""" dgbSpecIlUserType = "G" """gdm spec""" hdbobject = "h" """hierarchical database configuration object""" list = "l" """linked list""" nmpIlUserType = "m" """nmpll user type""" cdsEvalObject = "M" """Cadence evaluation object""" number = "n" """integere of floating point number""" userType = "o" """user defined type (other)""" port = "p" """I/O port""" gdmspecListIlUSerType = "q" """ gdm spec list""" defstruct = "r" """defstruct""" rodObj = "R" """relative object design (ROD) object""" symbol = "s" """symbol""" stringSymbol = "S" """symbol or character string""" string = "t" """character string (text)""" function = "u" """function object, either the name if a function (symbol) or a lambda function body (list)""" funobj = "U" """function object""" hdbpath = "v" """""" wtype = "w" """window type""" integer = "x" """integer type""" binary = "y" """binary function""" pointer = "&" """pointer type""" @dataclass(frozen=True) class Builtin(ABC): token: str kind: ClassVar[SymbolKind] @dataclass(frozen=True) class Variable(Builtin): kind: ClassVar[SymbolKind] = SymbolKind.Variable typ: SkillDataType default: str | None = None @dataclass(frozen=True) class AnonymousVariable(Builtin): kind: ClassVar[SymbolKind] = SymbolKind.Variable typ: SkillDataType default: str | None = None @dataclass(frozen=True) class Procedure(Builtin): kind: ClassVar[SymbolKind] = SymbolKind.Function args: Mapping[str, Variable] = field(default_factory=dict) rest: Variable | None = None kwargs: Mapping[str, Variable] | Mapping[str, AnonymousVariable] = field( default_factory=dict ) """list of ``Variable` if ``@key`` was used, and ``AnonymousVariable`` if ``@option`` was used""" ret: SkillDataType = SkillDataType.nil @property def has_options(self) -> bool: return bool(self.kwargs) and isinstance( next(iter(self.kwargs.values())), AnonymousVariable, ) @property def has_keys(self) -> bool: return bool(self.kwargs) and isinstance( next(iter(self.kwargs.values())), Variable, )