Skip to content

Add rename function for term_t and rule_t to add prefix/suffix to variables - #29

Merged
hzhangxyz merged 8 commits into
mainfrom
copilot/add-prefix-and-suffix-to-variables
Nov 25, 2025
Merged

Add rename function for term_t and rule_t to add prefix/suffix to variables#29
hzhangxyz merged 8 commits into
mainfrom
copilot/add-prefix-and-suffix-to-variables

Conversation

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor
  • Understand the codebase structure and existing ground function in src/ground.cc
  • Understand the term and rule types and their relationships
  • Build and run existing tests to verify baseline
  • Add rename function declaration to include/ds/term.hh for term_t
  • Add rename function declaration to include/ds/rule.hh for rule_t
  • Implement rename function for term_t in a new source file (following ground.cc pattern)
  • Implement rename function for rule_t in the same source file
  • Add tests for the new rename functionality
  • Run tests and verify all pass (65/65 passed)
  • Update interface to support empty prefix/suffix using ((prefix) (suffix)) format
  • Refactor: extract prefix/suffix strings once at start with helper functions
  • Use Chinese comments in rename.cc
  • Use anonymous namespace for helper functions (like match.cc)
  • Replace strlen with string_t::get_length() - 1
  • Use prefix_suffix_t struct for prefix/suffix parameters (like match.cc)
  • Replace '\0' with 0
Original prompt

This section details on the original issue you should resolve

<issue_title>给term和rule添加给所有variable添加prefix和suffix的功能</issue_title>
<issue_description></issue_description>

<agent_instructions>你需要模仿 src/ground.cc 这个文件, 实现给variable添加prefix和suffix的功能, 这个函数的declaration应该是:

term_t* rename(term_t* term, term_t* prefix_and_suffix, std::byte* check_tail = nullptr);

rule_t* rename(rule_t* rule, rule_t* prefix_and_suffix, std::byte* check_tail = nullptr);

这里把term或者rule中的所有variable添加prefix 和suffix后放在this中.

需要注意的是对于 term, prefix_and_suffix应该是一个list, 长度为2, 每个元素都是item, 分别表示prefix和suffix, 而对于rule, 是一个没有premise的rule, 也就是只有一个term.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 25, 2025 04:41
…iables

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality to add prefix and suffix to variables Add rename function for term_t and rule_t to add prefix/suffix to variables Nov 25, 2025
Copilot AI requested a review from hzhangxyz November 25, 2025 04:47
@hzhangxyz
hzhangxyz marked this pull request as ready for review November 25, 2025 04:47

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

突然发现目前这个接口无法实现只添加suffix或者只添加prefix, 所以这个长度为2的pair中, 应该允许出现空的情况, 但是我的item类型并不支持空字符串, 所以使用 "((prefix_) (suffix))" 这样的接口吧, 只有前缀就是 "((prefix) ())" ,只有后缀就是 "(() (_suffix))" .

…ffix))

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

突然发现目前这个接口无法实现只添加suffix或者只添加prefix, 所以这个长度为2的pair中, 应该允许出现空的情况, 但是我的item类型并不支持空字符串, 所以...

Updated the interface to use ((prefix) (suffix)) format where each inner list contains 0 or 1 items. Now supports:

  • ((prefix_) (_suffix)) - both prefix and suffix
  • ((prefix_) ()) - only prefix
  • (() (_suffix)) - only suffix
  • (() ()) - no changes

Commit: 558c653

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从prefix_and_suffix中抽取 prefix_str和suffix_str的工作可以在开头做一次就行了, 不用每次递归的时候都重新做一次, 为此, 你应该需要实现几个辅助函数. 另外, rename.cc这个文件中的注释使用中文.

…unctions, use Chinese comments

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

从prefix_and_suffix中抽取 prefix_str和suffix_str的工作可以在开头做一次就行了, 不用每次递归的时候都重新做一次, 为此, 你应该需要实现几个辅助函数. 另外,...

已重构为使用辅助函数 extract_prefix_suffix 在开头一次性提取prefix和suffix字符串,内部递归函数 rename_with_strings 直接使用已提取的字符串。注释已改为中文。

Commit: dc1a9e1

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 俩辅助函数应该模仿match.cc那样使用匿名namespace
  2. strlen 可以被 string_t 的 get_length 替代, 这个不需要数数, 而是直接存的, 需要注意get_length和是strlen的结果+1, 因为他算进去了末尾的\0.

…e.cc

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author
  1. 俩辅助函数应该模仿match.cc那样使用匿名namespace
  2. strlen 可以被 string_t 的 get_length 替代, 这个不需要数数, 而是直接存的, 需要注意get_length和是strlen的...
  1. 已将辅助函数改为使用匿名namespace(模仿match.cc的风格)
  2. 已将strlen替换为get_length() - 1

Commit: ee94086

@hzhangxyz hzhangxyz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请把
@param prefix_str 输出参数,prefix字符串指针,如果prefix为空则为nullptr。
@param prefix_len 输出参数,prefix字符串长度。
@param suffix_str 输出参数,suffix字符串指针,如果suffix为空则为nullptr。
@param suffix_len 输出参数,suffix字符串长度。

这四个参数放在一个struct里, 参考 match.cc 中, 我就是把一些相关的量放一起了.

另外, 请把 dst[new_len - 1] = '\0'; 换成 dst[new_len - 1] = 0; 没有为啥, 只是这个仓库的习惯.

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

请把
@param prefix_str 输出参数,prefix字符串指针,如果prefix为空则为nullptr。
@param prefix_len 输出参数,prefix字符串长度。...

已将四个参数放入prefix_suffix_t结构体中,并将'\0'替换为0

Commit: 821cf76

@hzhangxyz
hzhangxyz merged commit 0e2e67c into main Nov 25, 2025
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

给term和rule添加给所有variable添加prefix和suffix的功能

2 participants