gpt4 book ai didi

eclipse-emf - 如何在 Acceleo 中使用循环删除模板后多余的新行?

转载 作者:行者123 更新时间:2023-12-02 21:52:16 26 4
gpt4 key购买 nike

这是一个简单的 MOF 模型到文本脚本:

[comment encoding = UTF-8 /]
[module test('http://www.eclipse.org/uml2/2.1.0/UML')/]

[template public test(element : Model)]
[comment @main /]
[file ('test.txt', false, 'UTF-8')]
start
[loop(element)/]
[loop(element)/]
end
[/file]
[/template]

[template public loop(element : Model)]
[for (var : Integer | Sequence{1..3})]
[var/]
[/for]
[/template]

它生成以下文本:

start
1
2
3

1
2
3

end

如何删除3行之后多余的新行?谢谢!

最佳答案

您可以在 for 中使用分隔符:

[template public loop(element : Model)]
[for (var : Integer | Sequence{1..3}) separator('\n')]
[var/][/for]
[/template]

或者您可以修剪模板“循环”的结果:

[template public loop(element : Model) post(trim())]
[for (var : Integer | Sequence{1..3})]
[var/]
[/for]
[/template]

关于eclipse-emf - 如何在 Acceleo 中使用循环删除模板后多余的新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18373256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com