feat(selector): 增加离线候选遍历与严格回放验证 Demo
- 新增 selector_candidate_demo,移除 provenance intent 后枚举候选 selector - 对候选分支执行有界重建与严格 STEP 比较 - 仅在候选遍历完整且唯一 strict 通过时生成 selector 映射记录 - 增加 selector 候选搜索、预算限制和记录生成的测试 - 保持生产 selector resolver 不受 Demo 逻辑影响 - 更新 CADFS 能力台账,记录 IMPRINT 派生 profile 的 lineage selector 缺口
This commit is contained in:
@@ -6,6 +6,27 @@ from .featurescript_lexer import Token, lex
|
||||
from .ir import Call, FeatureIR, ModelIR, SketchIR
|
||||
|
||||
|
||||
_IMPORT_RE = re.compile(r"\bimport\s*\(\s*(?P<arguments>.*?)\s*\)\s*;", re.DOTALL)
|
||||
_IMPORT_PATH_RE = re.compile(r"\bpath\s*:\s*['\"]([^'\"]+)['\"]")
|
||||
_IMPORT_VERSION_RE = re.compile(r"\bversion\s*:\s*['\"]([^'\"]+)['\"]")
|
||||
|
||||
|
||||
def _standard_library_imports(source: str) -> list[dict[str, str]]:
|
||||
"""Preserve each directly imported Onshape standard-library revision."""
|
||||
imports: list[dict[str, str]] = []
|
||||
for match in _IMPORT_RE.finditer(source):
|
||||
arguments = match.group("arguments")
|
||||
path = _IMPORT_PATH_RE.search(arguments)
|
||||
if path is None or "onshape/std/" not in path.group(1):
|
||||
continue
|
||||
item = {"path": path.group(1)}
|
||||
version = _IMPORT_VERSION_RE.search(arguments)
|
||||
if version is not None:
|
||||
item["version"] = version.group(1)
|
||||
imports.append(item)
|
||||
return imports
|
||||
|
||||
|
||||
def _string(value: Any) -> Any:
|
||||
if isinstance(value, str) and len(value) >= 2 and value[0] in {'"', "'"} and value[-1] == value[0]:
|
||||
try:
|
||||
@@ -133,15 +154,15 @@ def _arg_map(call: Call) -> dict[str, Any]:
|
||||
def parse_featurescript(source: str, sample_id: str = "unknown") -> ModelIR:
|
||||
parser = Parser(source); calls = parser.statements()
|
||||
version = re.search(r"\bFeatureScript\s+(\d+(?:\.\d+)*)\s*;", source)
|
||||
standard_library = re.search(
|
||||
r"\bimport\s*\(\s*path\s*:\s*[\"']([^\"']*onshape/std/[^\"']*)[\"']",
|
||||
source,
|
||||
)
|
||||
standard_library_imports = _standard_library_imports(source)
|
||||
primary_standard_library = standard_library_imports[0] if standard_library_imports else {}
|
||||
model = ModelIR(
|
||||
sample_id,
|
||||
raw_source=source,
|
||||
featurescript_version=version.group(1) if version else None,
|
||||
standard_library=standard_library.group(1) if standard_library else None,
|
||||
standard_library=primary_standard_library.get("path"),
|
||||
standard_library_version=primary_standard_library.get("version"),
|
||||
standard_library_imports=standard_library_imports,
|
||||
)
|
||||
for call in calls:
|
||||
if call.name == "newSketch":
|
||||
|
||||
Reference in New Issue
Block a user