为模板引擎代码块寻找好的括号字符
我正在寻找一个好的字符对,用于将模板代码封装在我们内部模板引擎的下一版本的模板中。
当前使用普通的 {},但这使得解析器非常复杂,无法区分模板中文字文本中的真实代码块和随机 {} 字符。
我认为像 asp.net 或 php 中使用的双字符组合是一种更好的方法,但问题是我应该使用字符字符对,还是有一些从未使用过且易于编写的完美单字符。
需要满足的一些标准:
- 无法通过 HTMLEncode 更改,源代码可通过基于 Web 的 HTML 编辑器和纯文本区域进行编辑,并且无论使用什么编辑器都需要保持不变。
- 正则表达式将用于在 HTML 编辑器中编辑后清理代码部分,这些代码部分可能已经编码了代码块的内部部分,例如 & 。字符。
- 在英语和瑞典语键盘布局上书写都应该相当容易。
- 应该是一种非常罕见的组合,模板将生成 HTML 和文本,并且可以包含 CSS 和 Javascript 文本与 JSON,因此任何可能与这些发生冲突的组合都是不好的,除非非常罕见。这意味着 JSON 中可能出现的 {{}} 已被淘汰。
- 代码块中的代码将包含空格、下划线、美元和更多组合,不仅包括字段名,还包括 if/while 结构。
- 解析器是用Antlr生成的
我正在寻找建议和反对意见,以找到一种或多种在尽可能多的情况下有效的组合,可能针对不同情况有多个替代对。
I am looking for a good character pair to use for enclosing template code within a template for the next version of our inhouse template engine.
The current one uses plain {} but this makes the parser very complex to be able to distinguish between real code blocks and random {} chars in the literal text in the template.
I think a dual char combination like the one used in asp.net or php is a better aproach but the question is char character pair should I use or is there some perfect single char that is never used and thats easy to write.
Some criteria that needs to be fullfilled:
- Cannot be changed by HTMLEncode, the sources will be editable through webbased HTML editors and plain textareas and need to stay the same no matter what editor is used.
- Regex will be used to clean code parts after editing in an HTML editor that might have encoded the internal part of the code block like & chars.
- Should be resonably easy to write on both english and swedish keyboard layout.
- Should be a very rare combination, the template will generate HTML and Text and could include CSS and Javascript literal text with JSON, so any combination that might collide with those is bad unless very rare. That means that {{}} is out as it can occur in JSON.
- The code within the code block will contain spaces, underscores, dollar and many more combinations, not only fieldnames but if/while constructs as well.
- The parser is generated with Antlr
I am looking for suggestions and objections to find one or more combinations that would work i as many situations as possible, possibly multiple alternative pairs for different situations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Template-Toolkit 默认为
[% template instructions %]
,效果相当不错。Template-Toolkit defaults to
[% template directives %]
, which works reasonably well.