[jruby-joni] 89/279: Update for character class node
Hideki Yamane
henrich at moszumanska.debian.org
Mon Nov 16 11:26:56 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 34c338dd5cc028badca1a97de5c424e9b25c8d33
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date: Sun Feb 12 20:40:12 2012 +0100
Update for character class node
---
src/org/joni/ast/CClassNode.java | 191 ++++++++++++++++++++-------------------
1 file changed, 99 insertions(+), 92 deletions(-)
diff --git a/src/org/joni/ast/CClassNode.java b/src/org/joni/ast/CClassNode.java
index 40c7c90..c05c9f3 100644
--- a/src/org/joni/ast/CClassNode.java
+++ b/src/org/joni/ast/CClassNode.java
@@ -1,20 +1,20 @@
/*
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.joni.ast;
@@ -38,29 +38,29 @@ import org.joni.exception.ValueException;
public final class CClassNode extends Node {
private static final int FLAG_NCCLASS_NOT = 1<<0;
private static final int FLAG_NCCLASS_SHARE = 1<<1;
-
+
int flags;
public final BitSet bs = new BitSet(); // conditional creation ?
public CodeRangeBuffer mbuf; /* multi-byte info or NULL */
-
+
private int ctype; // for hashing purposes
- private Encoding enc; // ...
+ private Encoding enc; // ...
// node_new_cclass
public CClassNode() {}
-
+
public CClassNode(int ctype, Encoding enc, boolean not, int sbOut, int[]ranges) {
this(not, sbOut, ranges);
this.ctype = ctype;
this.enc = enc;
}
-
+
// node_new_cclass_by_codepoint_range, only used by shared Char Classes
public CClassNode(boolean not, int sbOut, int[]ranges) {
if (not) setNot();
// bs.clear();
-
+
if (sbOut > 0 && ranges != null) {
int n = ranges[0];
for (int i=0; i<n; i++) {
@@ -71,30 +71,30 @@ public final class CClassNode extends Node {
setupBuffer(ranges);
return;
}
- bs.set(j);
+ bs.set(j);
}
}
}
setupBuffer(ranges);
}
-
+
@Override
public int getType() {
- return CCLASS;
+ return CCLASS;
}
-
+
@Override
public String getName() {
return "Character Class";
}
-
+
@Override
public boolean equals(Object other) {
if (!(other instanceof CClassNode)) return false;
CClassNode cc = (CClassNode)other;
return ctype == cc.ctype && isNot() == cc.isNot() && enc == cc.enc;
}
-
+
@Override
public int hashCode() {
if (Config.USE_SHARED_CCLASS_TABLE) {
@@ -107,51 +107,51 @@ public final class CClassNode extends Node {
return super.hashCode();
}
}
-
+
@Override
public String toString(int level) {
StringBuilder value = new StringBuilder();
value.append("\n flags: " + flagsToString());
value.append("\n bs: " + pad(bs, level + 1));
value.append("\n mbuf: " + pad(mbuf, level + 1));
-
+
return value.toString();
- }
-
+ }
+
public String flagsToString() {
StringBuilder flags = new StringBuilder();
if (isNot()) flags.append("NOT ");
if (isShare()) flags.append("SHARE ");
return flags.toString();
}
-
- private void setupBuffer(int[]ranges) {
+
+ private void setupBuffer(int[]ranges) {
if (ranges != null) {
if (ranges[0] == 0) return;
mbuf = new CodeRangeBuffer(ranges);
}
}
-
+
public boolean isEmpty() {
return mbuf == null && bs.isEmpty();
}
-
+
public void addCodeRangeToBuf(int from, int to) {
mbuf = CodeRangeBuffer.addCodeRangeToBuff(mbuf, from, to);
}
-
+
public void addCodeRange(ScanEnvironment env, int from, int to) {
mbuf = CodeRangeBuffer.addCodeRange(mbuf, env, from, to);
}
-
+
public void addAllMultiByteRange(Encoding enc) {
mbuf = CodeRangeBuffer.addAllMultiByteRange(enc, mbuf);
}
-
+
public void clearNotFlag(Encoding enc) {
if (isNot()) {
bs.invert();
-
+
if (!enc.isSingleByte()) {
mbuf = CodeRangeBuffer.notCodeRangeBuff(enc, mbuf);
}
@@ -173,41 +173,41 @@ public final class CClassNode extends Node {
bsr1.invertTo(bs1);
bsr1 = bs1;
}
-
+
if (not2) {
BitSet bs2 = new BitSet();
bsr2.invertTo(bs2);
bsr2 = bs2;
}
-
+
bsr1.and(bsr2);
-
+
if (bsr1 != bs) {
bs.copy(bsr1);
bsr1 = bs;
}
-
+
if (not1) {
bs.invert();
}
-
+
CodeRangeBuffer pbuf = null;
-
+
if (!enc.isSingleByte()) {
- if (not1 && not2) {
+ if (not1 && not2) {
pbuf = CodeRangeBuffer.orCodeRangeBuff(enc, buf1, false, buf2, false);
} else {
pbuf = CodeRangeBuffer.andCodeRangeBuff(buf1, not1, buf2, not2);
-
+
if (not1) {
pbuf = CodeRangeBuffer.notCodeRangeBuff(enc, pbuf);
}
}
mbuf = pbuf;
}
-
+
}
-
+
// or_cclass
public void or(CClassNode other, Encoding enc) {
boolean not1 = isNot();
@@ -216,30 +216,30 @@ public final class CClassNode extends Node {
boolean not2 = other.isNot();
BitSet bsr2 = other.bs;
CodeRangeBuffer buf2 = other.mbuf;
-
+
if (not1) {
BitSet bs1 = new BitSet();
bsr1.invertTo(bs1);
bsr1 = bs1;
}
-
+
if (not2) {
BitSet bs2 = new BitSet();
bsr2.invertTo(bs2);
bsr2 = bs2;
}
-
+
bsr1.or(bsr2);
-
+
if (bsr1 != bs) {
bs.copy(bsr1);
bsr1 = bs;
}
-
+
if (not1) {
bs.invert();
}
-
+
if (!enc.isSingleByte()) {
CodeRangeBuffer pbuf = null;
if (not1 && not2) {
@@ -247,13 +247,13 @@ public final class CClassNode extends Node {
} else {
pbuf = CodeRangeBuffer.orCodeRangeBuff(enc, buf1, not1, buf2, not2);
if (not1) {
- pbuf = CodeRangeBuffer.notCodeRangeBuff(enc, pbuf);
+ pbuf = CodeRangeBuffer.notCodeRangeBuff(enc, pbuf);
}
}
mbuf = pbuf;
}
}
-
+
// add_ctype_to_cc_by_range // Encoding out!
public void addCTypeByRange(int ctype, boolean not, Encoding enc, int sbOut, int mbr[]) {
int n = mbr[0];
@@ -262,14 +262,21 @@ public final class CClassNode extends Node {
for (int i=0; i<n; i++) {
for (int j=mbr[i * 2 + 1]; j<=mbr[i * 2 + 2]; j++) {
if (j >= sbOut) {
- if (j == mbr[i * 2 + 2]) {
- i++;
- } else if (j > mbr[i * 2 + 1]) {
- addCodeRangeToBuf(j, mbr[i * 2 + 2]);
- i++;
+ if (Config.VANILLA) {
+ if (j == mbr[i * 2 + 2]) {
+ i++;
+ } else if (j > mbr[i * 2 + 1]) {
+ addCodeRangeToBuf(j, mbr[i * 2 + 2]);
+ i++;
+ }
+ } else {
+ if (j >= mbr[i * 2 + 1]) {
+ addCodeRangeToBuf(j, mbr[i * 2 + 2]);
+ i++;
+ }
}
// !goto sb_end!, remove duplication!
- for (; i<n; i++) {
+ for (; i<n; i++) {
addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
}
return;
@@ -278,13 +285,13 @@ public final class CClassNode extends Node {
}
}
// !sb_end:!
- for (int i=0; i<n; i++) {
+ for (int i=0; i<n; i++) {
addCodeRangeToBuf(mbr[2 * i + 1], mbr[2 * i + 2]);
}
-
+
} else {
int prev = 0;
-
+
for (int i=0; i<n; i++) {
for (int j=prev; j < mbr[2 * i + 1]; j++) {
if (j >= sbOut) {
@@ -305,7 +312,7 @@ public final class CClassNode extends Node {
for (int j=prev; j<sbOut; j++) {
bs.set(j);
}
-
+
// !sb_end2:!
prev = sbOut;
for (int i=0; i<n; i++) {
@@ -315,7 +322,7 @@ public final class CClassNode extends Node {
if (prev < 0x7fffffff/*!!!*/) addCodeRangeToBuf(prev, 0x7fffffff);
}
}
-
+
public void addCType(int ctype, boolean not, ScanEnvironment env, IntHolder sbOut) {
Encoding enc = env.enc;
@@ -349,7 +356,7 @@ public final class CClassNode extends Node {
}
}
break;
-
+
case CharacterType.GRAPH:
case CharacterType.PRINT:
if (not) {
@@ -363,7 +370,7 @@ public final class CClassNode extends Node {
addAllMultiByteRange(enc);
}
break;
-
+
case CharacterType.WORD:
if (!not) {
for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
@@ -375,17 +382,17 @@ public final class CClassNode extends Node {
for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
try {
if (enc.codeToMbcLength(c) > 0 && /* check invalid code point */
- !enc.isWord(c)) bs.set(c);
+ !enc.isWord(c)) bs.set(c);
} catch (EncodingException ve) {};
}
}
break;
-
+
default:
throw new InternalException(ErrorMessages.ERR_PARSER_BUG);
} // switch
}
-
+
public static final class CCStateArg {
public int v;
public int vs;
@@ -395,12 +402,12 @@ public final class CClassNode extends Node {
public CCVALTYPE type;
public CCSTATE state;
}
-
+
public void nextStateClass(CCStateArg arg, ScanEnvironment env) {
if (arg.state == CCSTATE.RANGE) throw new SyntaxException(ErrorMessages.ERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE);
-
+
if (arg.state == CCSTATE.VALUE && arg.type != CCVALTYPE.CLASS) {
- if (arg.type == CCVALTYPE.SB) {
+ if (arg.type == CCVALTYPE.SB) {
bs.set(arg.vs);
} else if (arg.type == CCVALTYPE.CODE_POINT) {
addCodeRange(env, arg.vs, arg.vs);
@@ -409,24 +416,24 @@ public final class CClassNode extends Node {
arg.state = CCSTATE.VALUE;
arg.type = CCVALTYPE.CLASS;
}
-
+
public void nextStateValue(CCStateArg arg, ScanEnvironment env) {
switch(arg.state) {
case VALUE:
if (arg.type == CCVALTYPE.SB) {
if (arg.vs > 0xff) throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
- bs.set(arg.vs);
+ bs.set(arg.vs);
} else if (arg.type == CCVALTYPE.CODE_POINT) {
addCodeRange(env, arg.vs, arg.vs);
}
break;
-
+
case RANGE:
if (arg.inType == arg.type) {
if (arg.inType == CCVALTYPE.SB) {
if (arg.vs > 0xff || arg.v > 0xff) throw new ValueException(ErrorMessages.ERR_INVALID_CODE_POINT_VALUE);
-
+
if (arg.vs > arg.v) {
if (env.syntax.allowEmptyRangeInCC()) {
// goto ccs_range_end
@@ -448,7 +455,7 @@ public final class CClassNode extends Node {
break;
} else {
throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
- }
+ }
}
bs.setRange(arg.vs, arg.v < 0xff ? arg.v : 0xff);
addCodeRange(env, arg.vs, arg.v);
@@ -456,26 +463,26 @@ public final class CClassNode extends Node {
// ccs_range_end:
arg.state = CCSTATE.COMPLETE;
break;
-
+
case COMPLETE:
case START:
arg.state = CCSTATE.VALUE;
break;
-
+
default:
break;
} // switch
-
+
arg.vsIsRaw = arg.vIsRaw;
arg.vs = arg.v;
arg.type = arg.inType;
}
-
+
// onig_is_code_in_cc_len
public boolean isCodeInCCLength(int encLength, int code) {
boolean found;
-
+
if (encLength > 1 || code >= BitSet.SINGLE_BYTE_SIZE) {
if (mbuf == null) {
found = false;
@@ -485,7 +492,7 @@ public final class CClassNode extends Node {
} else {
found = bs.at(code);
}
-
+
if (isNot()) {
return !found;
} else {
@@ -493,7 +500,7 @@ public final class CClassNode extends Node {
}
}
- // onig_is_code_in_cc
+ // onig_is_code_in_cc
public boolean isCodeInCC(Encoding enc, int code) {
int len;
if (enc.minLength() > 1) {
@@ -501,31 +508,31 @@ public final class CClassNode extends Node {
} else {
len = enc.codeToMbcLength(code);
}
- return isCodeInCCLength(len, code);
+ return isCodeInCCLength(len, code);
}
-
+
public void setNot() {
flags |= FLAG_NCCLASS_NOT;
}
-
+
public void clearNot() {
flags &= ~FLAG_NCCLASS_NOT;
}
-
+
public boolean isNot() {
return (flags & FLAG_NCCLASS_NOT) != 0;
}
-
+
public void setShare() {
flags |= FLAG_NCCLASS_SHARE;
}
-
+
public void clearShare() {
flags &= ~FLAG_NCCLASS_SHARE;
}
-
+
public boolean isShare() {
return (flags & FLAG_NCCLASS_SHARE) != 0;
}
-
+
}
--
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