什么是“额外的决胜局"?Perl 6 最长的令牌匹配? [英] What's an "additional tie breaker" for Perl 6 longest token matching?

查看:26
本文介绍了什么是“额外的决胜局"?Perl 6 最长的令牌匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正则表达式中 Perl 6 最长交替的文档指向概要 5,以记录 最长令牌匹配.如果不同的替代方案匹配相同长度的子字符串,则存在三个规则:

The docs for Perl 6 longest alternation in regexes punt to Synopsis 5 to document the rules for longest token matching. There are three rules if different alternatives would match a substring of the same length:

  • 最长的声明性前缀打破了平局
  • 最高特异性打破平局
  • 如果仍然是平局,请使用额外的决胜局."
  • 最左边的交替最终获胜

这是我很好奇的第三条规则.

It's that third rule that I'm curious about.

推荐答案

首先,文本的组织方式表明实现的行为必须是确定性的(而不是随机的).

First the way the text is organized makes clear that the behaviour of the implementation must be deterministic (not random).

第二个——也是更重要的——描述现有实现的确切行为可能会填满整个难以理解的页面,因为每个角落案例都必须被描述.此外,这样的规范会限制实现的自由度.让我们假设某些实现支持最快实现"标志.这样的实现可以使用未指定的部分来制作捷径.因此,未指定行为.限制到最小值有一些优点.

Second - and more important - describing the exact behaviour of existing implementations could fill an entire, hard-to-understand page as every corner case has to be described. In addition such a specification would limit degrees of freedom of the implementation. Let's assume some implementation supports a "fastest implementation" flag. Such an implementation can use unspecified parts to make short-cuts. So leaving the behaviour unspecified resp. restricted to the minimum has some advantages.

这篇关于什么是“额外的决胜局"?Perl 6 最长的令牌匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆