[jruby-joni] 155/223: Add ALLOW_NESTED_REPEAT syntax option

Hideki Yamane henrich at moszumanska.debian.org
Mon Nov 16 11:22:04 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit fe3178f44f832040e017e12f0fef11d974a8da9c
Author: Ben Browning <bbrownin at redhat.com>
Date:   Wed Sep 4 17:11:37 2013 -0400

    Add ALLOW_NESTED_REPEAT syntax option
    
    Not all languages allow nested repeats (/a***/, /a{1}{1,}/, etc) in
    their regular expression handling. This adds an additional Syntax
    behavior to control whether nested repeats should be allowed. The
    default behavior, GNU_REGEX_BV, was updated to allow nested repeats.
    
    This also required modifying the logic that looks at the return value
    of QuantifierNode.setQuantifier to update the repeat's target even
    when the repeat option given was "{1}" or "{1,1}".
---
 src/org/joni/Parser.java                     | 5 ++++-
 src/org/joni/Syntax.java                     | 4 ++++
 src/org/joni/ast/QuantifierNode.java         | 5 ++++-
 src/org/joni/constants/SyntaxProperties.java | 4 +++-
 src/org/joni/exception/ErrorMessages.java    | 1 +
 5 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/org/joni/Parser.java b/src/org/joni/Parser.java
index 3d56e9e..f0a049b 100644
--- a/src/org/joni/Parser.java
+++ b/src/org/joni/Parser.java
@@ -857,6 +857,9 @@ class Parser extends Lexer {
         while (token.type == TokenType.OP_REPEAT || token.type == TokenType.INTERVAL) { // repeat:
             if (target.isInvalidQuantifier()) newSyntaxException(ERR_TARGET_OF_REPEAT_OPERATOR_INVALID);
 
+            if (!syntax.allowNestedRepeat() && target.getType() == NodeType.QTFR) {
+                newSyntaxException(ERR_NESTED_REPEAT_NOT_ALLOWED);
+            }
             QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
                                                      token.getRepeatUpper(),
                                                      token.type == TokenType.INTERVAL);
@@ -871,7 +874,7 @@ class Parser extends Lexer {
                 qn = en;
             }
 
-            if (ret == 0) {
+            if (ret == 0 || ret == 1) {
                 target = qn;
             } else if (ret == 2) { /* split case: /abc+/ */
                 target = ConsAltNode.newListNode(target, null);
diff --git a/src/org/joni/Syntax.java b/src/org/joni/Syntax.java
index 74662a8..774284c 100644
--- a/src/org/joni/Syntax.java
+++ b/src/org/joni/Syntax.java
@@ -343,6 +343,10 @@ public final class Syntax implements SyntaxProperties{
         return isBehavior(ALLOW_DOUBLE_RANGE_OP_IN_CC);
     }
 
+    public boolean allowNestedRepeat() {
+        return isBehavior(ALLOW_NESTED_REPEAT);
+    }
+
     public boolean warnCCOpNotEscaped() {
         return isBehavior(WARN_CC_OP_NOT_ESCAPED);
     }
diff --git a/src/org/joni/ast/QuantifierNode.java b/src/org/joni/ast/QuantifierNode.java
index 8ec53cb..39be333 100644
--- a/src/org/joni/ast/QuantifierNode.java
+++ b/src/org/joni/ast/QuantifierNode.java
@@ -200,7 +200,10 @@ public final class QuantifierNode extends StateNode {
     }
 
     public int setQuantifier(Node tgt, boolean group, ScanEnvironment env, byte[]bytes, int p, int end) {
-        if (lower == 1 && upper == 1) return 1;
+        if (lower == 1 && upper == 1) {
+            setTarget(tgt);
+            return 1;
+        }
 
         switch(tgt.getType()) {
 
diff --git a/src/org/joni/constants/SyntaxProperties.java b/src/org/joni/constants/SyntaxProperties.java
index 61f2269..78191ec 100644
--- a/src/org/joni/constants/SyntaxProperties.java
+++ b/src/org/joni/constants/SyntaxProperties.java
@@ -87,6 +87,7 @@ public interface SyntaxProperties {
     final int CAPTURE_ONLY_NAMED_GROUP        = (1<<7);  /* see doc/RE */
     final int ALLOW_MULTIPLEX_DEFINITION_NAME = (1<<8);  /* (?<x>);(?<x>); */
     final int FIXED_INTERVAL_IS_GREEDY_ONLY   = (1<<9);  /* a{n}?=(?:a{n});? */
+    final int ALLOW_NESTED_REPEAT             = (1<<10); /* a{0,}{1}{2} */
 
     /* syntax (behavior); in char class [...] */
     final int NOT_NEWLINE_IN_NEGATIVE_CC      = (1<<20); /* [^...] */
@@ -120,5 +121,6 @@ public interface SyntaxProperties {
     final int GNU_REGEX_BV =
                             CONTEXT_INDEP_ANCHORS | CONTEXT_INDEP_REPEAT_OPS |
                             CONTEXT_INVALID_REPEAT_OPS | ALLOW_INVALID_INTERVAL |
-                            BACKSLASH_ESCAPE_IN_CC | ALLOW_DOUBLE_RANGE_OP_IN_CC;
+                            BACKSLASH_ESCAPE_IN_CC | ALLOW_DOUBLE_RANGE_OP_IN_CC |
+                            ALLOW_NESTED_REPEAT;
 }
diff --git a/src/org/joni/exception/ErrorMessages.java b/src/org/joni/exception/ErrorMessages.java
index f490713..683ff62 100644
--- a/src/org/joni/exception/ErrorMessages.java
+++ b/src/org/joni/exception/ErrorMessages.java
@@ -54,6 +54,7 @@ public interface ErrorMessages extends org.jcodings.exception.ErrorMessages {
     final String ERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS = "unmatched range specifier in char-class";
     final String ERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED = "target of repeat operator is not specified";
     final String ERR_TARGET_OF_REPEAT_OPERATOR_INVALID = "target of repeat operator is invalid";
+    final String ERR_NESTED_REPEAT_NOT_ALLOWED = "nested repeat is not allowed";
     final String ERR_NESTED_REPEAT_OPERATOR = "nested repeat operator";
     final String ERR_UNMATCHED_CLOSE_PARENTHESIS = "unmatched close parenthesis";
     final String ERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS = "end pattern with unmatched parenthesis";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list