Skip to content
Commits on Source (239)
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
\ No newline at end of file
language: java
notifications:
# Email notifications are disabled to not annoy anybody.
# See http://about.travis-ci.org/docs/user/build-configuration/ to learn more
# about configuring notification recipients and more.
email: false
#!/usr/bin/env groovy
pipeline {
agent none
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('OpenJDK 8') {
agent { docker 'openjdk:8-jdk' }
steps {
checkout scm
sh './mvnw test -B'
}
post {
always {
junit testResults: '**/surefire-reports/**/*.xml', allowEmptyResults: true
}
}
}
stage('Alternative Platforms') {
parallel {
stage('OpenJDK 9') {
agent { docker 'openjdk:9-jdk' }
steps {
checkout scm
sh './mvnw test -B'
}
post {
always {
junit testResults: '**/surefire-reports/**/*.xml', allowEmptyResults: true
}
}
}
stage('Alpine Linux') {
agent { docker 'openjdk:8-jdk-alpine' }
steps {
checkout scm
sh './mvnw test -B'
}
post {
always {
junit testResults: '**/surefire-reports/**/*.xml', allowEmptyResults: true
}
}
}
stage('FreeBSD 11') {
agent { label 'freebsd' }
steps {
checkout scm
sh './mvnw test -B'
}
post {
always {
junit testResults: '**/surefire-reports/**/*.xml', allowEmptyResults: true
}
}
}
/* awaiting platform support in Code Valet */
stage('Windows 2016') {
when { branch 'windows-support' }
steps {
echo 'Not yet available'
}
}
}
}
}
}
MIT License
Copyright (c) 2017 JRuby Team
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
SOFTWARE.
joni
====
[![Maven Central](https://img.shields.io/maven-central/v/org.jruby.joni/joni.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.jruby.joni%22)
[![Build Status](https://secure.travis-ci.org/jruby/joni.png)](http://travis-ci.org/jruby/joni)
Java port of Oniguruma regexp library
## Usage
......
......@@ -20,11 +20,6 @@
<target name="build" depends="compile">
<mkdir dir="${dist.dir}" />
<tstamp>
<format property="buildDate" pattern="yyyy-MM-dd" />
<format property="buildTime" pattern="HH:mm:ss" />
</tstamp>
<jar destfile="${dist.dir}/${jar.name}" manifest="MANIFEST.MF">
<fileset dir="${bin.dir}" />
......
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
......@@ -4,7 +4,7 @@
<groupId>org.jruby.joni</groupId>
<artifactId>joni</artifactId>
<packaging>jar</packaging>
<version>2.1.12-SNAPSHOT</version>
<version>2.1.17-SNAPSHOT</version>
<name>Joni</name>
<description>
Java port of Oniguruma: http://www.geocities.jp/kosako3/oniguruma
......@@ -66,12 +66,12 @@
<dependency>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
<version>1.0.13</version>
<version>1.0.30</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -97,19 +97,14 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<includes>
<include>**/TestJoni.java</include>
</includes>
</configuration>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
......@@ -137,10 +132,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<version>2.9</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<additionalparam>-Xdoclint:none</additionalparam>
<quiet>true</quiet>
</configuration>
<executions>
<execution>
......@@ -154,4 +151,59 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jacoco</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<configuration>
<excludes>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
This diff is collapsed.
......@@ -22,7 +22,7 @@ package org.joni;
import org.jcodings.ApplyAllCaseFoldFunction;
import org.jcodings.Encoding;
import org.joni.ast.CClassNode;
import org.joni.ast.ConsAltNode;
import org.joni.ast.ListNode;
import org.joni.ast.StringNode;
final class ApplyCaseFold implements ApplyAllCaseFoldFunction {
......@@ -34,25 +34,38 @@ final class ApplyCaseFold implements ApplyAllCaseFoldFunction {
ScanEnvironment env = arg.env;
Encoding enc = env.enc;
CClassNode cc = arg.cc;
CClassNode ascCc = arg.ascCc;
BitSet bs = cc.bs;
boolean addFlag;
if (ascCc == null) {
addFlag = false;
} else if (Encoding.isAscii(from) == Encoding.isAscii(to[0])) {
addFlag = true;
} else {
addFlag = ascCc.isCodeInCC(enc, from);
if (ascCc.isNot()) addFlag = !addFlag;
}
if (length == 1) {
boolean inCC = cc.isCodeInCC(enc, from);
if (Config.CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS) {
if ((inCC && !cc.isNot()) || (!inCC && cc.isNot())) {
if (addFlag) {
if (enc.minLength() > 1 || to[0] >= BitSet.SINGLE_BYTE_SIZE) {
cc.addCodeRange(env, to[0], to[0]);
cc.addCodeRange(env, to[0], to[0], false);
} else {
/* /(?i:[^A-C])/.match("a") ==> fail. */
bs.set(to[0]);
}
}
}
} else {
if (inCC) {
if (addFlag) {
if (enc.minLength() > 1 || to[0] >= BitSet.SINGLE_BYTE_SIZE) {
if (cc.isNot()) cc.clearNotFlag(enc);
cc.addCodeRange(env, to[0], to[0]);
if (cc.isNot()) cc.clearNotFlag(env);
cc.addCodeRange(env, to[0], to[0], false);
} else {
if (cc.isNot()) {
bs.clear(to[0]);
......@@ -61,6 +74,7 @@ final class ApplyCaseFold implements ApplyAllCaseFoldFunction {
}
}
}
}
} // CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS
} else {
......@@ -76,12 +90,12 @@ final class ApplyCaseFold implements ApplyAllCaseFoldFunction {
node.catCode(to[i], enc);
}
ConsAltNode alt = ConsAltNode.newAltNode(node, null);
ListNode alt = ListNode.newAlt(node, null);
if (arg.tail == null) {
arg.altRoot = alt;
} else {
arg.tail.setCdr(alt);
arg.tail.setTail(alt);
}
arg.tail = alt;
}
......
......@@ -20,16 +20,17 @@
package org.joni;
import org.joni.ast.CClassNode;
import org.joni.ast.ConsAltNode;
import org.joni.ast.ListNode;
public final class ApplyCaseFoldArg {
final class ApplyCaseFoldArg {
final ScanEnvironment env;
final CClassNode cc;
ConsAltNode altRoot;
ConsAltNode tail;
final CClassNode cc, ascCc;
ListNode altRoot;
ListNode tail;
public ApplyCaseFoldArg(ScanEnvironment env, CClassNode cc) {
ApplyCaseFoldArg(ScanEnvironment env, CClassNode cc, CClassNode ascCc) {
this.env = env;
this.cc = cc;
this.ascCc = ascCc;
}
}
This diff is collapsed.
......@@ -24,7 +24,7 @@ import org.joni.ast.BackRefNode;
import org.joni.ast.CClassNode;
import org.joni.ast.CTypeNode;
import org.joni.ast.CallNode;
import org.joni.ast.ConsAltNode;
import org.joni.ast.ListNode;
import org.joni.ast.EncloseNode;
import org.joni.ast.QuantifierNode;
......@@ -56,7 +56,7 @@ final class AsmCompiler extends AsmCompilerSupport {
}
@Override
protected void compileAltNode(ConsAltNode node) {
protected void compileAltNode(ListNode node) {
}
@Override
......
......@@ -22,27 +22,21 @@ package org.joni;
public final class BitSet {
static final int BITS_PER_BYTE = 8;
public static final int SINGLE_BYTE_SIZE = (1 << BITS_PER_BYTE);
private static final int BITS_IN_ROOM = 4 * BITS_PER_BYTE;
static final int BITSET_SIZE = (SINGLE_BYTE_SIZE / BITS_IN_ROOM);
public static final int BITS_IN_ROOM = 4 * BITS_PER_BYTE;
public static final int BITSET_SIZE = (SINGLE_BYTE_SIZE / BITS_IN_ROOM);
static final int ROOM_SHIFT = log2(BITS_IN_ROOM);
final int[] bits = new int[BITSET_SIZE];
private static final int BITS_TO_STRING_WRAP = 4;
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("BitSet");
for (int i=0; i<SINGLE_BYTE_SIZE; i++) {
if ((i % (SINGLE_BYTE_SIZE / BITS_TO_STRING_WRAP)) == 0) buffer.append("\n ");
buffer.append(at(i) ? "1" : "0");
}
return buffer.toString();
}
public final int[] bits = new int[BITSET_SIZE];
public boolean at(int pos) {
return (bits[pos >>> ROOM_SHIFT] & bit(pos)) != 0;
}
public void set(ScanEnvironment env, int pos) {
if (at(pos)) env.ccDuplicateWarn();
set(pos);
}
public void set(int pos) {
bits[pos >>> ROOM_SHIFT] |= bit(pos);
}
......@@ -66,8 +60,11 @@ public final class BitSet {
return true;
}
public void setRange(int from, int to) {
for (int i=from; i<=to && i < SINGLE_BYTE_SIZE; i++) set(i);
public void setRange(ScanEnvironment env, int from, int to) {
for (int i=from; i<=to && i < SINGLE_BYTE_SIZE; i++) {
if (env != null && at(i)) env.ccDuplicateWarn();
set(i);
}
}
public void setAll() {
......@@ -94,7 +91,7 @@ public final class BitSet {
for (int i=0; i<BITSET_SIZE; i++) bits[i] = other.bits[i];
}
public int numOn() {
int numOn() {
int num = 0;
for (int i=0; i<SINGLE_BYTE_SIZE; i++) {
if (at(i)) num++;
......@@ -102,7 +99,7 @@ public final class BitSet {
return num;
}
static int bit(int pos){
private static int bit(int pos){
return 1 << (pos % SINGLE_BYTE_SIZE);
}
......@@ -112,4 +109,14 @@ public final class BitSet {
return log;
}
private static final int BITS_TO_STRING_WRAP = 4;
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("BitSet");
for (int i=0; i<SINGLE_BYTE_SIZE; i++) {
if ((i % (SINGLE_BYTE_SIZE / BITS_TO_STRING_WRAP)) == 0) buffer.append("\n ");
buffer.append(at(i) ? "1" : "0");
}
return buffer.toString();
}
}
This diff is collapsed.
......@@ -20,7 +20,6 @@
package org.joni;
import org.jcodings.Encoding;
import org.joni.ast.CClassNode;
import org.joni.constants.Arguments;
import org.joni.constants.OPCode;
import org.joni.constants.OPSize;
......@@ -30,21 +29,13 @@ class ByteCodePrinter {
final int[]code;
final int codeLength;
final byte[][] templates;
Object[]operands;
int operantCount;
Encoding enc;
WarnCallback warnings;
final Encoding enc;
public ByteCodePrinter(Regex regex) {
code = regex.code;
codeLength = regex.codeLength;
operands = regex.operands;
operantCount = regex.operandLength;
templates = regex.templates;
enc = regex.enc;
warnings = regex.warnings;
}
public String byteCodeListToString() {
......@@ -56,11 +47,6 @@ class ByteCodePrinter {
while (len-- > 0) sb.append(new String(new byte[]{(byte)code[s++]}));
}
private void pStringFromTemplate(StringBuilder sb, int len, byte[]tm, int idx) {
sb.append(":T:");
while (len-- > 0) sb.append(new String(new byte[]{tm[idx++]}));
}
private void pLenString(StringBuilder sb, int len, int mbLen, int s) {
int x = len * mbLen;
sb.append(":" + len + ":");
......@@ -70,13 +56,12 @@ class ByteCodePrinter {
private void pLenStringFromTemplate(StringBuilder sb, int len, int mbLen, byte[]tm, int idx) {
int x = len * mbLen;
sb.append(":T:" + len + ":");
while (x-- > 0) sb.append(new String(new byte[]{(byte)tm[idx++]}));
while (x-- > 0) sb.append(new String(tm, idx++, 1));
}
public int compiledByteCodeToString(StringBuilder sb, int bp) {
int len, n, mem, addr, scn, cod;
BitSet bs;
CClassNode cc;
int tm, idx;
sb.append("[" + OPCode.OpCodeNames[code[bp]]);
......@@ -123,8 +108,6 @@ class ByteCodePrinter {
case OPCode.EXACT1:
case OPCode.ANYCHAR_STAR_PEEK_NEXT:
case OPCode.ANYCHAR_ML_STAR_PEEK_NEXT:
case OPCode.ANYCHAR_STAR_PEEK_NEXT_SB:
case OPCode.ANYCHAR_ML_STAR_PEEK_NEXT_SB:
pString(sb, 1, bp++);
break;
......@@ -221,11 +204,9 @@ class ByteCodePrinter {
idx = code[bp];
bp += OPSize.INDEX;
sb.append(":T:" + mbLen + ":" + len + ":");
while (n-- > 0) sb.append(new String(new byte[]{templates[tm][idx++]}));
while (n-- > 0) sb.append(new String(templates[tm], idx++, 1));
} else {
sb.append(":" + mbLen + ":" + len + ":");
while (n-- > 0) sb.append(new String(new byte[]{(byte)code[bp++]}));
}
......@@ -258,7 +239,6 @@ class ByteCodePrinter {
break;
case OPCode.CCLASS:
case OPCode.CCLASS_SB:
bs = new BitSet();
System.arraycopy(code, bp, bs.bits, 0, BitSet.BITSET_SIZE);
n = bs.numOn();
......@@ -267,7 +247,6 @@ class ByteCodePrinter {
break;
case OPCode.CCLASS_NOT:
case OPCode.CCLASS_NOT_SB:
bs = new BitSet();
System.arraycopy(code, bp, bs.bits, 0, BitSet.BITSET_SIZE);
n = bs.numOn();
......@@ -299,13 +278,6 @@ class ByteCodePrinter {
sb.append(":" + n + ":" + cod + ":" + len);
break;
case OPCode.CCLASS_NODE:
cc = (CClassNode)operands[code[bp]];
bp += OPSize.POINTER;
n = cc.bs.numOn();
sb.append(":" + cc + ":" + n);
break;
case OPCode.BACKREFN_IC:
mem = code[bp];
bp += OPSize.MEMNUM;
......@@ -363,7 +335,6 @@ class ByteCodePrinter {
break;
case OPCode.LOOK_BEHIND:
case OPCode.LOOK_BEHIND_SB:
len = code[bp];
bp += OPSize.LENGTH;
sb.append(":" + len);
......@@ -400,26 +371,19 @@ class ByteCodePrinter {
}
sb.append("]");
// @opcode_address(opcode_size)
if (Config.DEBUG_COMPILE_BYTE_CODE_INFO) sb.append("@" + ip + "(" + (bp - ip) + ")");
return bp;
}
private String compiledByteCodeListToString() {
StringBuilder sb = new StringBuilder();
sb.append("code length: " + codeLength + "\n");
int ncode = 0;
StringBuilder sb = new StringBuilder("code length: " + codeLength + "\n");
int ncode = -1;
int bp = 0;
int end = codeLength;
while (bp < end) {
ncode++;
if (bp > 0) sb.append(ncode % 5 == 0 ? "\n" : " ");
sb.append(ncode % 5 == 0 ? "\n" : " ");
bp = compiledByteCodeToString(sb, bp);
}
sb.append("\n");
......
......@@ -19,9 +19,7 @@
*/
package org.joni;
public class CaptureTreeNode {
final class CaptureTreeNode {
int group;
int beg;
int end;
......@@ -36,6 +34,7 @@ public class CaptureTreeNode {
}
static final int HISTORY_TREE_INIT_ALLOC_SIZE = 8;
void addChild(CaptureTreeNode child) {
if (children == null) {
children = new CaptureTreeNode[HISTORY_TREE_INIT_ALLOC_SIZE];
......@@ -69,6 +68,4 @@ public class CaptureTreeNode {
}
return clone;
}
}
......@@ -25,15 +25,10 @@ import org.joni.exception.ValueException;
public final class CodeRangeBuffer {
private static final int INIT_MULTI_BYTE_RANGE_SIZE = 5;
private static final int ALL_MULTI_BYTE_RANGE = 0x7fffffff;
public static final int LAST_CODE_POINT = 0x7fffffff;
int[]p;
int used;
public CodeRangeBuffer(int[]ranges) {
p = ranges;
used = ranges[0] + 1;
}
private int[]p;
private int used;
public CodeRangeBuffer() {
p = new int[INIT_MULTI_BYTE_RANGE_SIZE];
......@@ -44,31 +39,16 @@ public final class CodeRangeBuffer {
return p;
}
public int getUsed() {
return used;
}
private CodeRangeBuffer(CodeRangeBuffer orig) {
p = new int[orig.p.length];
System.arraycopy(orig.p, 0, p, 0, p.length);
used = orig.used;
}
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("CodeRange");
buf.append("\n used: " + used);
buf.append("\n code point: " + p[0]);
buf.append("\n ranges: ");
for (int i=0; i<p[0]; i++) {
buf.append("[" + rangeNumToString(p[i * 2 + 1]) + ".." + rangeNumToString(p[i * 2 + 2]) + "]");
if (i > 0 && i % 6 == 0) buf.append("\n ");
}
return buf.toString();
}
private static String rangeNumToString(int num){
return "0x" + Integer.toString(num, 16);
}
public void expand(int low) {
int length = p.length;
do { length <<= 1; } while (length < low);
......@@ -113,9 +93,12 @@ public final class CodeRangeBuffer {
return new CodeRangeBuffer(this);
}
// ugly part: these methods should be made OO
// add_code_range_to_buf
public static CodeRangeBuffer addCodeRangeToBuff(CodeRangeBuffer pbuf, int from, int to) {
public static CodeRangeBuffer addCodeRangeToBuff(CodeRangeBuffer pbuf, ScanEnvironment env, int from, int to) {
return addCodeRangeToBuff(pbuf, env, from, to, true);
}
public static CodeRangeBuffer addCodeRangeToBuff(CodeRangeBuffer pbuf, ScanEnvironment env, int from, int to, boolean checkDup) {
if (from > to) {
int n = from;
from = to;
......@@ -127,24 +110,22 @@ public final class CodeRangeBuffer {
int[]p = pbuf.p;
int n = p[0];
int bound = from == 0 ? 0 : n;
int low = 0;
int bound = n;
while (low < bound) {
int x = (low + bound) >>> 1;
if (from > p[x * 2 + 2]) {
if (from - 1 > p[x * 2 + 2]) {
low = x + 1;
} else {
bound = x;
}
}
int high = low;
int high = to == LAST_CODE_POINT ? n : low;
bound = n;
while (high < bound) {
int x = (high + bound) >>> 1;
if (to >= p[x * 2 + 1] - 1) {
if (to + 1 >= p[x * 2 + 1]) {
high = x + 1;
} else {
bound = x;
......@@ -153,20 +134,26 @@ public final class CodeRangeBuffer {
int incN = low + 1 - high;
if (n + incN > Config.MAX_MULTI_BYTE_RANGES_NUM) throw new ValueException(ErrorMessages.ERR_TOO_MANY_MULTI_BYTE_RANGES);
if (n + incN > Config.MAX_MULTI_BYTE_RANGES_NUM) throw new ValueException(ErrorMessages.TOO_MANY_MULTI_BYTE_RANGES);
if (incN != 1) {
if (checkDup) {
if (from <= p[low * 2 + 2] && (p[low * 2 + 1] <= from || p[low * 2 + 2] <= to)) env.ccDuplicateWarn();
}
if (from > p[low * 2 + 1]) from = p[low * 2 + 1];
if (to < p[(high - 1) * 2 + 2]) to = p[(high - 1) * 2 + 2];
}
if (incN != 0 && high < n) {
if (incN != 0) {
int fromPos = 1 + high * 2;
int toPos = 1 + (low + 1) * 2;
int size = (n - high) * 2;
if (incN > 0) {
if (high < n) {
int size = (n - high) * 2;
pbuf.moveRight(fromPos, toPos, size);
}
} else {
pbuf.moveLeftAndReduce(fromPos, toPos);
}
......@@ -184,39 +171,48 @@ public final class CodeRangeBuffer {
// add_code_range, be aware of it returning null!
public static CodeRangeBuffer addCodeRange(CodeRangeBuffer pbuf, ScanEnvironment env, int from, int to) {
return addCodeRange(pbuf, env, from, to, true);
}
public static CodeRangeBuffer addCodeRange(CodeRangeBuffer pbuf, ScanEnvironment env, int from, int to, boolean checkDup) {
if (from >to) {
if (env.syntax.allowEmptyRangeInCC()) {
return pbuf;
} else {
throw new ValueException(ErrorMessages.ERR_EMPTY_RANGE_IN_CHAR_CLASS);
throw new ValueException(ErrorMessages.EMPTY_RANGE_IN_CHAR_CLASS);
}
}
return addCodeRangeToBuff(pbuf, env, from, to, checkDup);
}
return addCodeRangeToBuff(pbuf, from, to);
private static int mbcodeStartPosition(Encoding enc) {
return enc.minLength() > 1 ? 0 : 0x80;
}
// SET_ALL_MULTI_BYTE_RANGE
protected static CodeRangeBuffer setAllMultiByteRange(Encoding enc, CodeRangeBuffer pbuf) {
return addCodeRangeToBuff(pbuf, enc.mbcodeStartPosition(), ALL_MULTI_BYTE_RANGE);
protected static CodeRangeBuffer setAllMultiByteRange(ScanEnvironment env, CodeRangeBuffer pbuf) {
return addCodeRangeToBuff(pbuf, env, mbcodeStartPosition(env.enc), LAST_CODE_POINT);
}
// ADD_ALL_MULTI_BYTE_RANGE
public static CodeRangeBuffer addAllMultiByteRange(Encoding enc, CodeRangeBuffer pbuf) {
if (!enc.isSingleByte()) return setAllMultiByteRange(enc, pbuf);
public static CodeRangeBuffer addAllMultiByteRange(ScanEnvironment env, CodeRangeBuffer pbuf) {
if (!env.enc.isSingleByte()) return setAllMultiByteRange(env, pbuf);
return pbuf;
}
// not_code_range_buf
public static CodeRangeBuffer notCodeRangeBuff(Encoding enc, CodeRangeBuffer bbuf) {
public static CodeRangeBuffer notCodeRangeBuff(ScanEnvironment env, CodeRangeBuffer bbuf) {
CodeRangeBuffer pbuf = null;
if (bbuf == null) return setAllMultiByteRange(enc, pbuf);
if (bbuf == null) return setAllMultiByteRange(env, pbuf);
int[]p = bbuf.p;
int n = p[0];
if (n <= 0) return setAllMultiByteRange(enc, pbuf);
if (n <= 0) return setAllMultiByteRange(env, pbuf);
int pre = enc.mbcodeStartPosition();
int pre = mbcodeStartPosition(env.enc);
int from;
int to = 0;
......@@ -224,24 +220,24 @@ public final class CodeRangeBuffer {
from = p[i * 2 + 1];
to = p[i * 2 + 2];
if (pre <= from - 1) {
pbuf = addCodeRangeToBuff(pbuf, pre, from - 1);
pbuf = addCodeRangeToBuff(pbuf, env, pre, from - 1);
}
if (to == ALL_MULTI_BYTE_RANGE) break;
if (to == LAST_CODE_POINT) break;
pre = to + 1;
}
if (to < ALL_MULTI_BYTE_RANGE) pbuf = addCodeRangeToBuff(pbuf, to + 1, ALL_MULTI_BYTE_RANGE);
if (to < LAST_CODE_POINT) pbuf = addCodeRangeToBuff(pbuf, env, to + 1, LAST_CODE_POINT);
return pbuf;
}
// or_code_range_buf
public static CodeRangeBuffer orCodeRangeBuff(Encoding enc, CodeRangeBuffer bbuf1, boolean not1,
public static CodeRangeBuffer orCodeRangeBuff(ScanEnvironment env, CodeRangeBuffer bbuf1, boolean not1,
CodeRangeBuffer bbuf2, boolean not2) {
CodeRangeBuffer pbuf = null;
if (bbuf1 == null && bbuf2 == null) {
if (not1 || not2) {
return setAllMultiByteRange(enc, pbuf);
return setAllMultiByteRange(env, pbuf);
}
return null;
}
......@@ -256,12 +252,12 @@ public final class CodeRangeBuffer {
if (bbuf1 == null) {
if (not1) {
return setAllMultiByteRange(enc, pbuf);
return setAllMultiByteRange(env, pbuf);
} else {
if (!not2) {
return bbuf2.clone();
} else {
return notCodeRangeBuff(enc, bbuf2);
return notCodeRangeBuff(env, bbuf2);
}
}
}
......@@ -277,7 +273,7 @@ public final class CodeRangeBuffer {
if (!not2 && !not1) { /* 1 OR 2 */
pbuf = bbuf2.clone();
} else if (!not1) { /* 1 OR (not 2) */
pbuf = notCodeRangeBuff(enc, bbuf2);
pbuf = notCodeRangeBuff(env, bbuf2);
}
int[]p1 = bbuf1.p;
......@@ -286,14 +282,14 @@ public final class CodeRangeBuffer {
for (int i=0; i<n1; i++) {
int from = p1[i * 2 + 1];
int to = p1[i * 2 + 2];
pbuf = addCodeRangeToBuff(pbuf, from, to);
pbuf = addCodeRangeToBuff(pbuf, env, from, to);
}
return pbuf;
}
// and_code_range1
public static CodeRangeBuffer andCodeRange1(CodeRangeBuffer pbuf, int from1, int to1, int[]data, int n) {
public static CodeRangeBuffer andCodeRange1(CodeRangeBuffer pbuf, ScanEnvironment env, int from1, int to1, int[]data, int n) {
for (int i=0; i<n; i++) {
int from2 = data[i * 2 + 1];
int to2 = data[i * 2 + 2];
......@@ -306,7 +302,7 @@ public final class CodeRangeBuffer {
} else if (from2 <= to1) {
if (to2 < to1) {
if (from1 <= from2 - 1) {
pbuf = addCodeRangeToBuff(pbuf, from1, from2 - 1);
pbuf = addCodeRangeToBuff(pbuf, env, from1, from2 - 1);
}
from1 = to2 + 1;
} else {
......@@ -319,7 +315,7 @@ public final class CodeRangeBuffer {
}
if (from1 <= to1) {
pbuf = addCodeRangeToBuff(pbuf, from1, to1);
pbuf = addCodeRangeToBuff(pbuf, env, from1, to1);
}
return pbuf;
......@@ -327,7 +323,7 @@ public final class CodeRangeBuffer {
// and_code_range_buf
public static CodeRangeBuffer andCodeRangeBuff(CodeRangeBuffer bbuf1, boolean not1,
CodeRangeBuffer bbuf2, boolean not2) {
CodeRangeBuffer bbuf2, boolean not2, ScanEnvironment env) {
CodeRangeBuffer pbuf = null;
if (bbuf1 == null) {
......@@ -364,17 +360,36 @@ public final class CodeRangeBuffer {
if (to2 < from1) continue;
int from = from1 > from2 ? from1 : from2;
int to = to1 < to2 ? to1 : to2;
pbuf = addCodeRangeToBuff(pbuf, from, to);
pbuf = addCodeRangeToBuff(pbuf, env, from, to);
}
}
} else if (!not1) { /* 1 AND (not 2) */
for (int i=0; i<n1; i++) {
int from1 = p1[i * 2 + 1];
int to1 = p1[i * 2 + 2];
pbuf = andCodeRange1(pbuf, from1, to1, p2, n2);
pbuf = andCodeRange1(pbuf, env, from1, to1, p2, n2);
}
}
return pbuf;
}
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("CodeRange");
buf.append("\n used: " + used);
buf.append(", size: " + p[0]);
buf.append("\n ranges: ");
for (int i=0; i<p[0]; i++) {
buf.append("[" + rangeNumToString(p[i * 2 + 1]) + ".." + rangeNumToString(p[i * 2 + 2]) + "]");
if (i > 0 && i % 6 == 0) buf.append("\n ");
}
return buf.toString();
}
private static String rangeNumToString(int num){
return "0x" + Integer.toString(num, 16);
}
}