dragon87836215 2017-11-06 19:07
浏览 36

如何增加token.File的大小?

I'm working on a rewriter that uses go/ast to add some things to a file. Everything is working well, except for the comments, which go/ast is notoriously awful at. But part of the problem seems to be that it's actively conspiring against my efforts to fix it.

I have an insertion near the end of the file that is larger than what was left in the file. There are a couple other funcs after that point, and they have comments on them. I used a visitor to calculate the appropriate Pos for my update and then update the remaining nodes with a new Pos so that they wouldn't lose their association with their comments, but now the comments are getting moved to above my insertion!

After tracing through the execution, what I found is that func (s *FileSet) PositionFor in position.go is returning 0 on the position of those remaining comments, because their new Pos is beyond the end of the associated token.File data. Well, then it looks like I need to update the size on that token.File, but it's a lower-case field so I can't do that directly, and there doesn't appear to be any method that will do it for me. size appears to be immutable, only set at construction time, which is odd because other parts of the token.File structs can be updated.

How in the world do I resolve this? I just want my comments to print where they're supposed to be, but every time I think I've fixed the problem, there's some other problem lurking behind it, and now I run into an immutable problem!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题