You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rascal MPL:如何提取loc额外段及转换loc值为字符串?

Rascal中Location的起始位置提取与字符串转换

提取<BL, BC>段

Rascal的loc类型自带begin字段,直接对应你要的<BL, BC>部分,该字段是pos类型,包含line(行号BL)和column(列号BC)属性。示例代码:

loc l = |java+compilationUnit:///test/src/main.java|(0,123,<1,0>,<7,1>);
// 获取完整的<BL, BC>起始位置
pos startPos = l.begin;
// 单独提取行号和列号
int beginLine = startPos.line;
int beginColumn = startPos.column;

将loc转换为字符串

如果toString(l)无法生效,试试这两种方法:

  1. 字符串插值:直接把loc变量嵌入字符串中
string locStr = "<l>";
  1. 显式类型转换:使用string()函数强制转换
string locStr = string(l);

内容的提问来源于stack exchange,提问作者Teun M.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 16:25:35