[jruby-joni] 187/279: Squash all the JS options to OP2_OPTION_ECMASCRIPT

Hideki Yamane henrich at moszumanska.debian.org
Mon Nov 16 11:27:29 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 e197e1833a5e7ac6d596e4af406a77bcd665f13d
Author: Ben Browning <bbrownin at redhat.com>
Date:   Fri Oct 25 10:19:55 2013 -0400

    Squash all the JS options to OP2_OPTION_ECMASCRIPT
    
    This also guards against a couple of minor behavioral changes to
    ensure they only happen when OP2_OPTION_ECMASCRIPT is set.
---
 src/org/joni/Analyser.java                   |  8 ++++----
 src/org/joni/Lexer.java                      |  2 +-
 src/org/joni/Parser.java                     | 14 +++++++-------
 src/org/joni/Syntax.java                     | 28 +++++-----------------------
 src/org/joni/ast/CClassNode.java             |  2 +-
 src/org/joni/ast/QuantifierNode.java         |  4 +++-
 src/org/joni/constants/SyntaxProperties.java |  9 ++-------
 7 files changed, 23 insertions(+), 44 deletions(-)

diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java
index 59063ff..9665ba6 100644
--- a/src/org/joni/Analyser.java
+++ b/src/org/joni/Analyser.java
@@ -413,14 +413,14 @@ final class Analyser extends Parser {
             if (br.isRecursion()) break;
 
             if (br.back[0] > env.numMem) {
-                if (syntax.strictCheckBackref()) newValueException(ERR_INVALID_BACKREF);
+                if (!syntax.op2OptionECMAScript()) newValueException(ERR_INVALID_BACKREF);
             } else {
                 min = getMinMatchLength(env.memNodes[br.back[0]]);
             }
 
             for (int i=1; i<br.backNum; i++) {
                 if (br.back[i] > env.numMem) {
-                    if (syntax.strictCheckBackref()) newValueException(ERR_INVALID_BACKREF);
+                    if (!syntax.op2OptionECMAScript()) newValueException(ERR_INVALID_BACKREF);
                 } else {
                     int tmin = getMinMatchLength(env.memNodes[br.back[i]]);
                     if (min > tmin) min = tmin;
@@ -553,7 +553,7 @@ final class Analyser extends Parser {
 
             for (int i=0; i<br.backNum; i++) {
                 if (br.back[i] > env.numMem) {
-                    if(syntax.strictCheckBackref()) newValueException(ERR_INVALID_BACKREF);
+                    if(!syntax.op2OptionECMAScript()) newValueException(ERR_INVALID_BACKREF);
                 } else {
                     int tmax = getMaxMatchLength(env.memNodes[br.back[i]]);
                     if (max < tmax) max = tmax;
@@ -1790,7 +1790,7 @@ final class Analyser extends Parser {
             BackRefNode br = (BackRefNode)node;
             for (int i=0; i<br.backNum; i++) {
                 if (br.back[i] > env.numMem) {
-                    if (syntax.strictCheckBackref()) newValueException(ERR_INVALID_BACKREF);
+                    if (!syntax.op2OptionECMAScript()) newValueException(ERR_INVALID_BACKREF);
                 } else {
                     env.backrefedMem = bsOnAt(env.backrefedMem, br.back[i]);
                     env.btMemStart = bsOnAt(env.btMemStart, br.back[i]);
diff --git a/src/org/joni/Lexer.java b/src/org/joni/Lexer.java
index e50be33..0b70271 100644
--- a/src/org/joni/Lexer.java
+++ b/src/org/joni/Lexer.java
@@ -185,7 +185,7 @@ class Lexer extends ScannerSupport {
 
     private void fetchEscapedValueControl() {
         if (!left()) {
-            if (syntax.op2EscIdentity()) {
+            if (syntax.op2OptionECMAScript()) {
                 return;
             } else {
                 newSyntaxException(ERR_END_PATTERN_AT_CONTROL);
diff --git a/src/org/joni/Parser.java b/src/org/joni/Parser.java
index 95e5618..62208a7 100644
--- a/src/org/joni/Parser.java
+++ b/src/org/joni/Parser.java
@@ -157,7 +157,7 @@ class Parser extends Lexer {
             neg = false;
         }
 
-        if (token.type == TokenType.CC_CLOSE && !syntax.allowEmptyCC()) {
+        if (token.type == TokenType.CC_CLOSE && !syntax.op2OptionECMAScript()) {
             if (!codeExistCheck(']', true)) newSyntaxException(ERR_EMPTY_CHAR_CLASS);
             env.ccEscWarn("]");
             token.type = TokenType.CHAR; /* allow []...] */
@@ -429,7 +429,7 @@ class Parser extends Lexer {
                 break;
             case '!':  /*         preceding read */
                 node = new AnchorNode(AnchorType.PREC_READ_NOT);
-                if (syntax.ignoreBackrefPrecReadNot()) {
+                if (syntax.op2OptionECMAScript()) {
                     env.pushPrecReadNotNode(node);
                 }
                 break;
@@ -582,14 +582,14 @@ class Parser extends Lexer {
         if (node.getType() == NodeType.ANCHOR) {
             AnchorNode an = (AnchorNode) node;
             an.setTarget(target);
-            if (syntax.ignoreBackrefPrecReadNot() && an.type == AnchorType.PREC_READ_NOT) {
+            if (syntax.op2OptionECMAScript() && an.type == AnchorType.PREC_READ_NOT) {
                 env.popPrecReadNotNode(an);
             }
         } else {
             EncloseNode en = (EncloseNode)node;
             en.setTarget(target);
             if (en.type == EncloseType.MEMORY) {
-                if (syntax.ignoreBackrefPrecReadNot()) {
+                if (syntax.op2OptionECMAScript()) {
                     en.containingAnchor = env.currentPrecReadNotNode();
                 }
                 /* Don't move this to previous of parse_subexp() */
@@ -759,7 +759,7 @@ class Parser extends Lexer {
             break;
 
         case BACKREF:
-            if (syntax.ignoreBackrefPrecReadNot() && token.getBackrefNum() == 1 && env.memNodes != null) {
+            if (syntax.op2OptionECMAScript() && token.getBackrefNum() == 1 && env.memNodes != null) {
                 EncloseNode encloseNode = (EncloseNode) env.memNodes[token.getBackrefRef1()];
                 boolean shouldIgnore = false;
                 if (encloseNode != null && encloseNode.containingAnchor != null) {
@@ -890,7 +890,7 @@ 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) {
+            if (syntax.op2OptionECMAScript() && target.getType() == NodeType.QTFR) {
                 newSyntaxException(ERR_NESTED_REPEAT_NOT_ALLOWED);
             }
             QuantifierNode qtfr = new QuantifierNode(token.getRepeatLower(),
@@ -907,7 +907,7 @@ class Parser extends Lexer {
                 qn = en;
             }
 
-            if (ret == 0 || ret == 1) {
+            if (ret == 0 || (syntax.op2OptionECMAScript() && 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 4cd349b..4e7b5e7 100644
--- a/src/org/joni/Syntax.java
+++ b/src/org/joni/Syntax.java
@@ -278,12 +278,8 @@ public final class Syntax implements SyntaxProperties{
         return isOp2(OP2_INEFFECTIVE_ESCAPE);
     }
 
-    public boolean op2EscIdentity() {
-        return isOp2(OP2_ESC_IDENTITY);
-    }
-
-    public boolean op2UnicodeWhitespace() {
-        return isOp2(OP2_UNICODE_WHITESPACE);
+    public boolean op2OptionECMAScript() {
+        return isOp2(OP2_OPTION_ECMASCRIPT);
     }
 
     /**
@@ -334,14 +330,6 @@ public final class Syntax implements SyntaxProperties{
         return isBehavior(FIXED_INTERVAL_IS_GREEDY_ONLY);
     }
 
-    public boolean ignoreBackrefPrecReadNot() {
-        return isBehavior(IGNORE_BACKREF_PREC_READ_NOT);
-    }
-
-
-    public boolean allowEmptyCC() {
-        return isBehavior(ALLOW_EMPTY_CC);
-    }
 
     public boolean notNewlineInNegativeCC() {
         return isBehavior(NOT_NEWLINE_IN_NEGATIVE_CC);
@@ -359,10 +347,6 @@ 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);
     }
@@ -624,7 +608,7 @@ public final class Syntax implements SyntaxProperties{
         )
     );
 
-    public static final Syntax JavaScript = new Syntax(
+    public static final Syntax ECMAScript = new Syntax(
         (( GNU_REGEX_OP | OP_QMARK_NON_GREEDY |
         OP_ESC_OCTAL3 | OP_ESC_X_HEX2 |
         OP_ESC_CONTROL_CHARS | OP_ESC_C_CONTROL |
@@ -637,17 +621,15 @@ public final class Syntax implements SyntaxProperties{
         OP2_ESC_P_BRACE_CHAR_PROPERTY |
         OP2_ESC_P_BRACE_CIRCUMFLEX_NOT |
         OP2_ESC_U_HEX4 | OP2_ESC_V_VTAB |
-        OP2_ESC_IDENTITY | OP2_UNICODE_WHITESPACE ),
+        OP2_OPTION_ECMASCRIPT ),
 
         ( CONTEXT_INDEP_ANCHORS |
         CONTEXT_INDEP_REPEAT_OPS |
         CONTEXT_INVALID_REPEAT_OPS |
         ALLOW_INVALID_INTERVAL |
-        ALLOW_EMPTY_CC |
         BACKSLASH_ESCAPE_IN_CC | 
         ALLOW_DOUBLE_RANGE_OP_IN_CC |
-        DIFFERENT_LEN_ALT_LOOK_BEHIND |
-        IGNORE_BACKREF_PREC_READ_NOT ),
+        DIFFERENT_LEN_ALT_LOOK_BEHIND ),
 
         Option.NONE,
 
diff --git a/src/org/joni/ast/CClassNode.java b/src/org/joni/ast/CClassNode.java
index f3a9306..6dd5d7f 100644
--- a/src/org/joni/ast/CClassNode.java
+++ b/src/org/joni/ast/CClassNode.java
@@ -336,7 +336,7 @@ public final class CClassNode extends Node {
         if (Config.NON_UNICODE_SDW) {
             switch(ctype) {
             case CharacterType.S:
-                if (!not && env.syntax.op2UnicodeWhitespace()) {
+                if (!not && env.syntax.op2OptionECMAScript()) {
                     // treat \u2028 and \u2029 as whitespace
                     addCodeRange(env, 8232, 8233);
                 }
diff --git a/src/org/joni/ast/QuantifierNode.java b/src/org/joni/ast/QuantifierNode.java
index 39be333..d75aa27 100644
--- a/src/org/joni/ast/QuantifierNode.java
+++ b/src/org/joni/ast/QuantifierNode.java
@@ -201,7 +201,9 @@ 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) {
-            setTarget(tgt);
+            if (env.syntax.op2OptionECMAScript()) {
+                setTarget(tgt);
+            }
             return 1;
         }
 
diff --git a/src/org/joni/constants/SyntaxProperties.java b/src/org/joni/constants/SyntaxProperties.java
index 4fb159d..075324c 100644
--- a/src/org/joni/constants/SyntaxProperties.java
+++ b/src/org/joni/constants/SyntaxProperties.java
@@ -74,8 +74,7 @@ public interface SyntaxProperties {
     /* final int OP2_CHAR_PROPERTY_PREFIX_IS = (1<<18); */
     final int OP2_ESC_H_XDIGIT               = (1<<19); /* \h, \H */
     final int OP2_INEFFECTIVE_ESCAPE         = (1<<20); /* \ */
-    final int OP2_ESC_IDENTITY               = (1<<21); /* \a, \b, \c */
-    final int OP2_UNICODE_WHITESPACE         = (1<<22); /* \s matches \u2028 */
+    final int OP2_OPTION_ECMASCRIPT          = (1<<21); /* EcmaScript quirks */
 
     /* syntax (behavior); */
     final int CONTEXT_INDEP_ANCHORS           = (1<<31); /* not implemented */
@@ -89,11 +88,8 @@ 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} */
-    final int IGNORE_BACKREF_PREC_READ_NOT    = (1<<11); /* /(?!(a+)b\2c)\2 */
 
     /* syntax (behavior); in char class [...] */
-    final int ALLOW_EMPTY_CC                  = (1<<19); /* [] */
     final int NOT_NEWLINE_IN_NEGATIVE_CC      = (1<<20); /* [^...] */
     final int BACKSLASH_ESCAPE_IN_CC          = (1<<21); /* [..\w..] etc.. */
     final int ALLOW_EMPTY_RANGE_IN_CC         = (1<<22);
@@ -125,6 +121,5 @@ 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 |
-                            ALLOW_NESTED_REPEAT;
+                            BACKSLASH_ESCAPE_IN_CC | ALLOW_DOUBLE_RANGE_OP_IN_CC;
 }

-- 
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