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 f7ce3f245fd3ce074958e7e1224222ff70f80938 Author: Marcin Mielzynski <[email protected]> Date: Sun Feb 19 02:46:56 2012 +0100 Fix look behind. --- src/org/joni/Analyser.java | 44 +++++++++++++++++++++++---------------- src/org/joni/Config.java | 1 + src/org/joni/ast/ConsAltNode.java | 5 ++--- test/org/joni/test/TestA.java | 5 +++++ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/org/joni/Analyser.java b/src/org/joni/Analyser.java index 60218b2..9586b6e 100644 --- a/src/org/joni/Analyser.java +++ b/src/org/joni/Analyser.java @@ -106,9 +106,15 @@ final class Analyser extends Parser { } } // USE_NAMED_GROUP + if (Config.DEBUG_PARSE_TREE_RAW && Config.DEBUG_PARSE_TREE) { + Config.log.println("<RAW TREE>"); + Config.log.println(root + "\n"); + } + setupTree(root, 0); if (Config.DEBUG_PARSE_TREE) { - root.verifyTree(new HashSet<Node>(),env.reg.warnings); + if (Config.DEBUG_PARSE_TREE_RAW) Config.log.println("<TREE>"); + root.verifyTree(new HashSet<Node>(), env.reg.warnings); Config.log.println(root + "\n"); } @@ -173,7 +179,6 @@ final class Analyser extends Parser { } private Node noNameDisableMap(Node node, int[]map, int[]counter) { - switch (node.getType()) { case NodeType.LIST: case NodeType.ALT: @@ -1290,14 +1295,12 @@ final class Analyser extends Parser { (?<=A|B) ==> (?<=A)|(?<=B) (?<!A|B) ==> (?<!A)(?<!B) */ - private void divideLookBehindAlternatives(Node node) { + private Node divideLookBehindAlternatives(Node node) { AnchorNode an = (AnchorNode)node; int anchorType = an.type; - Node head = an.target; Node np = ((ConsAltNode)head).car; - swap(node, head); Node tmp = node; @@ -1320,11 +1323,12 @@ final class Analyser extends Parser { ((ConsAltNode)np).toListNode(); /* alt -> list */ } while ((np = ((ConsAltNode)np).cdr) != null); } + + return node; } - private void setupLookBehind(Node node) { + private Node setupLookBehind(Node node) { AnchorNode an = (AnchorNode)node; - int len = getCharLengthTree(an.target); switch(returnCode) { case 0: @@ -1335,11 +1339,12 @@ final class Analyser extends Parser { break; case GET_CHAR_LEN_TOP_ALT_VARLEN: if (syntax.differentLengthAltLookBehind()) { - divideLookBehindAlternatives(node); + return divideLookBehindAlternatives(node); } else { newSyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN); } } + return null; } private void nextSetup(Node node, Node nextNode) { @@ -1425,7 +1430,6 @@ final class Analyser extends Parser { private boolean expandCaseFoldStringAlt(int itemNum, CaseFoldCodeItem[]items, byte[]bytes, int p, int slen, int end, Node[]node) { boolean varlen = false; - for (int i=0; i<itemNum; i++) { if (items[i].byteLen != slen) { varlen = true; @@ -1694,6 +1698,8 @@ final class Analyser extends Parser { 6. expand repeated string. */ protected final void setupTree(Node node, int state) { + restart: + while (true) { switch (node.getType()) { case NodeType.LIST: ConsAltNode lin = (ConsAltNode)node; @@ -1851,8 +1857,10 @@ final class Analyser extends Parser { AnchorType.ALLOWED_IN_LB); if (lbInvalid) newSyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN); - setupLookBehind(node); - setupTree(an.target, state); + Node n = setupLookBehind(node); + if (n != null) node = n; + if (!(node instanceof AnchorNode)) continue restart; + setupTree(((AnchorNode)node).target, state); break; case AnchorType.LOOK_BEHIND_NOT: @@ -1861,18 +1869,18 @@ final class Analyser extends Parser { AnchorType.ALLOWED_IN_LB); if (lbnInvalid) newSyntaxException(ERR_INVALID_LOOK_BEHIND_PATTERN); - - setupLookBehind(node); - setupTree(an.target, (state | IN_NOT)); + n = setupLookBehind(node); + if (n != null) node = n; + if (!(node instanceof AnchorNode)) continue restart; + setupTree(((AnchorNode)node).target, (state | IN_NOT)); break; } // inner switch break; - - default: - break; - } // switch + return; + + } // while } private static final int MAX_NODE_OPT_INFO_REF_COUNT = 5; diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java index 8a8547f..5b9fdbc 100644 --- a/src/org/joni/Config.java +++ b/src/org/joni/Config.java @@ -80,6 +80,7 @@ public interface Config extends org.jcodings.Config { final boolean DEBUG_ALL = false; final boolean DEBUG = DEBUG_ALL; final boolean DEBUG_PARSE_TREE = DEBUG_ALL; + final boolean DEBUG_PARSE_TREE_RAW = true; final boolean DEBUG_COMPILE = DEBUG_ALL; final boolean DEBUG_COMPILE_BYTE_CODE_INFO = DEBUG_ALL; final boolean DEBUG_SEARCH = DEBUG_ALL; diff --git a/src/org/joni/ast/ConsAltNode.java b/src/org/joni/ast/ConsAltNode.java index 1ffc889..7d456fe 100644 --- a/src/org/joni/ast/ConsAltNode.java +++ b/src/org/joni/ast/ConsAltNode.java @@ -95,7 +95,6 @@ public final class ConsAltNode extends Node { withCan.cdr = tmp; } } - super.swap(with); } @@ -145,8 +144,8 @@ public final class ConsAltNode extends Node { @Override public String toString(int level) { StringBuilder value = new StringBuilder(); - value.append("\n left: " + pad(car, level + 1)); - value.append("\n right: " + (cdr == null ? "NULL" : cdr.toString())); + value.append("\n car: " + pad(car, level + 1)); + value.append("\n cdr: " + (cdr == null ? "NULL" : cdr.toString())); return value.toString(); } diff --git a/test/org/joni/test/TestA.java b/test/org/joni/test/TestA.java index ed2d035..f32135f 100644 --- a/test/org/joni/test/TestA.java +++ b/test/org/joni/test/TestA.java @@ -483,6 +483,11 @@ public class TestA extends Test { ns("\\70", "70"); x2s("\\80", "80", 0, 2); x2s("\\90", "90", 0, 2); + + ns("(?<!b|aa)c", "", Option.IGNORECASE); + x2s("(?<!b|aa)", "Aac", 0, 0, Option.IGNORECASE); + x2s("(?<=b|aa)c", "Aac", 2, 3, Option.IGNORECASE); + x2s("(?<=b|aa)", "Aac", 2, 2, Option.IGNORECASE); } public static void main(String[] args) throws Throwable{ -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

