aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2016-08-12 08:05:19 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2016-08-12 08:05:19 +0200
commit8d9f343cd41465c554bb4ed4d21fc05b076069d4 (patch)
treed9985ef3114b9a4c3e6e22175e40e541594f586a
parentfd5d5d6961e25ade4104daa52f066e7cf59d4a90 (diff)
downloadCompiler-8d9f343cd41465c554bb4ed4d21fc05b076069d4.zip
Compiler-8d9f343cd41465c554bb4ed4d21fc05b076069d4.tar.gz
Compiler-8d9f343cd41465c554bb4ed4d21fc05b076069d4.tar.bz2
Rule: Restore infinite max in a repetition.
`-1` is a special value representing infinity. This is useful for repetition like `*`, `+` or `{x,}`.
-rw-r--r--Llk/Rule/Repetition.php16
1 files changed, 13 insertions, 3 deletions
diff --git a/Llk/Rule/Repetition.php b/Llk/Rule/Repetition.php
index fab3cff..31d0d23 100644
--- a/Llk/Rule/Repetition.php
+++ b/Llk/Rule/Repetition.php
@@ -78,10 +78,10 @@ class Repetition extends Rule
{
parent::__construct($name, $children, $nodeId);
- $min = max(0, (int) $min);
- $max = max(0, (int) $max);
+ $min = max( 0, (int) $min);
+ $max = max(-1, (int) $max);
- if ($min > $max) {
+ if (-1 !== $max && $min > $max) {
throw new Compiler\Exception\Rule(
'Cannot repeat with a min (%d) greater than max (%d).',
0,
@@ -114,4 +114,14 @@ class Repetition extends Rule
{
return $this->_max;
}
+
+ /**
+ * Check whether the maximum repetition is unbounded.
+ *
+ * @return bool
+ */
+ public function isInfinite()
+ {
+ return -1 === $this->getMax();
+ }
}