signature:
public class JavascriptDecoder { /** * Calls a method on a script object compiled during a previous script execution , which is retained in the state of the ScriptEngine .
 * @ param jsEngine the JavaScript engine
 * @ param thiz the instance of the class that contains the method to be called
 * @ param name the name of the method to be called
 * @ param args the arguments to pass to the method
 * @ return the value returned by the procedure , which must be a String
 * @ throws NoSuchMethodException if method with given name or matching argument types cannot be found .
 * @ throws ScriptException if an error occurs during invocation of the method . */
private static String invokeStringMethod ( final ScriptEngine jsEngine , final Object thiz , final String name , final Object ... args ) throws NoSuchMethodException , ScriptException { } }

implementation: return ( String ) ( ( Invocable ) jsEngine ) . invokeMethod ( thiz , name , args ) ;


signature:
public class ReferencedObject { /** * Return the referenced object , potentially performing a remote DataStore lookup and deserialisation . If the object is already
 * present or has been previously acquired , it is immediately returned .
 * @ param source the implementation that provides object instances given the provided references
 * @ return the object that this container is wrapping
 * @ throws DataSourceException if the object cannot be acquired
 * @ throws IllegalStateException if there is no object or reference present */
public synchronized T acquire ( final DataSource source ) throws DataSourceException { } }

implementation: if ( object == null ) { if ( getReference ( ) == null ) { throw new IllegalStateException ( "No reference or object present" ) ; } else { object = source . getObject ( getReference ( ) , objectClass ) ; } } return object ;


signature:
public class ReferencedObject { /** * Create a ReferencedObject that uses a remote reference to data present in an ObjectSource .
 * @ param clazz the class of the referenced object
 * @ param ref the reference to be interpreted by the DataStore
 * @ param < T > the type of the referenced object
 * @ return a new ReferencedObject instance that relates to a remote object via reference */
public static < T > ReferencedObject < T > getReferencedObject ( final Class < T > clazz , final String ref ) { } }

implementation: return new ReferencedObject < > ( clazz , ref , null ) ;


signature:
public class ReferencedObject { /** * Create a ReferencedObject that directly wraps an object without a reference .
 * @ param clazz the class of the object
 * @ param obj the object to wrapper
 * @ param < T > the type of the object
 * @ return a new ReferencedObject instance that directly wraps the object specified */
public static < T > ReferencedObject < T > getWrappedObject ( final Class < T > clazz , final T obj ) { } }

implementation: return new ReferencedObject < > ( clazz , null , obj ) ;


signature:
public class RestConfigurationSource { /** * { @ inheritDoc }
 * Descend back through the full service path to try and acquire configuration . This means we will try and get a more specific
 * configuration first before going down to a more general configuration . */
@ Override protected InputStream getConfigurationStream ( final Class configClass , final Name relativePath ) throws ConfigurationException { } }

implementation: try { return remoteCall ( relativePath . toString ( ) , configClass . getSimpleName ( ) ) . getBody ( ) . in ( ) ; } catch ( final HttpConfigurationException e ) { throw new ConfigurationException ( "No configuration at path: " + relativePath , e ) ; } catch ( final IOException | InterruptedException e ) { throw new ConfigurationException ( "Failed to retrieve configuration" , e ) ; }


signature:
public class RestConfigurationSource { /** * Perform exponential backoff / retry of acquiring a data file from an HTTP source .
 * @ param configName the configuration file name
 * @ return the HTTP response
 * @ throws ConfigurationException if the data cannot be acquired
 * @ throws InterruptedException usually if the application is shutting down */
private Response remoteCall ( final String path , final String configName ) throws ConfigurationException , InterruptedException { } }

implementation:
int i = 0 ; while ( true ) { try { return remote . getRemoteConfiguration ( path , configName ) ; } catch ( final HttpConfigurationException nfe ) { // don ' t retry if we have an explicit failure from the HTTP server
throw nfe ; } catch ( final ConfigurationException e ) { LOG . debug ( "HTTP client call failed, retrying" ) ; if ( i == retries ) { throw e ; } else { Thread . sleep ( ( long ) Math . pow ( 2 , i ) * 1000L ) ; } i ++ ; } }


signature:
public class CafConfigurationSource { /** * Acquire a configuration class from the provider . The requested class will be a simple Java object that when returned , and can be
 * interacted with using getters and other standard mechanisms . Configuration classes may themselves contain other configuration
 * objects , which will be recursively acquired if marked @ Configuration . Any fields marked @ Encrypted will be decrypted , any fields
 * marked and any validation annotations will be processed .
 * @ param configClass the class that represents your configuration
 * @ param < T > the class that represents your configuration
 * @ return the configuration class requested , if it can be deserialised
 * @ throws ConfigurationException if the configuration class cannot be acquired or deserialised */
@ Override public final < T > T getConfiguration ( final Class < T > configClass ) throws ConfigurationException { } }

implementation: Objects . requireNonNull ( configClass ) ; incrementRequests ( ) ; T config = getCompleteConfig ( configClass ) ; Set < ConstraintViolation < T > > violations = getValidator ( ) . validate ( config ) ; if ( violations . isEmpty ( ) ) { return config ; } else { incrementErrors ( ) ; LOG . error ( "Configuration constraint violations found for {}: {}" , configClass . getSimpleName ( ) , violations ) ; throw new ConfigurationException ( "Configuration validation failed for " + configClass . getSimpleName ( ) ) ; }


signature:
public class CafConfigurationSource { /** * This is the recursive entry point for acquiring a complete configuration class to return . Attempt to acquire a deserialised object
 * representing the configuration class requested , and analyse it for declared fields marked @ Configuration . If any are found , the
 * method recursively calls itself until all configuration is satisfied .
 * @ param configClass the class representing configuration to acquire
 * @ param < T > the class representing configuration to acquire
 * @ return the completed ( at this level ) configuration
 * @ throws ConfigurationException if configuration cannot be acquired */
private < T > T getCompleteConfig ( final Class < T > configClass ) throws ConfigurationException { } }

implementation:
T config = getConfig ( configClass ) ; for ( final Field f : configClass . getDeclaredFields ( ) ) { if ( f . isAnnotationPresent ( Configuration . class ) ) { try { Method setter = getMethod ( f . getName ( ) , configClass , PropertyDescriptor :: getWriteMethod ) ; if ( setter != null ) { setter . invoke ( config , getCompleteConfig ( f . getType ( ) ) ) ; } } catch ( final ConfigurationException e ) { LOG . debug ( "Didn't find any overriding configuration" , e ) ; } catch ( final InvocationTargetException | IllegalAccessException e ) { incrementErrors ( ) ; throw new ConfigurationException ( "Failed to get complete configuration for " + configClass . getSimpleName ( ) , e ) ; } } else if ( f . getType ( ) . equals ( String . class ) && f . isAnnotationPresent ( Encrypted . class ) ) { try { Method getter = getMethod ( f . getName ( ) , config . getClass ( ) , PropertyDescriptor :: getReadMethod ) ; Method setter = getMethod ( f . getName ( ) , config . getClass ( ) , PropertyDescriptor :: getWriteMethod ) ; if ( getter != null && setter != null ) { final String configValue = ( String ) getter . invoke ( config ) ; final String encryptedValue = isSubstitutorEnabled ? tokenSubstitutor ( configValue ) : configValue ; setter . invoke ( config , getCipher ( ) . decrypt ( encryptedValue ) ) ; } } catch ( final CipherException | InvocationTargetException | IllegalAccessException e ) { throw new ConfigurationException ( "Failed to decrypt class fields" , e ) ; } } else if ( isSubstitutorEnabled && f . getType ( ) . equals ( String . class ) ) { try { String propertyName = f . getName ( ) ; Method getter = getMethod ( propertyName , config . getClass ( ) , PropertyDescriptor :: getReadMethod ) ; Method setter = getMethod ( propertyName , config . getClass ( ) , PropertyDescriptor :: getWriteMethod ) ; if ( getter != null && setter != null ) { // Property value may contain tokens that require substitution .
String propertyValueByToken = tokenSubstitutor ( ( String ) getter . invoke ( config ) ) ; setter . invoke ( config , propertyValueByToken ) ; } } catch ( final InvocationTargetException | IllegalAccessException e ) { throw new ConfigurationException ( "Failed to get complete configuration for " + configClass . getSimpleName ( ) , e ) ; } } } return config ;


signature:
public class CafConfigurationSource { /** * Acquire , decode and decrypt a configuration object from a data stream .
 * @ param configClass the class representing configuration to acquire
 * @ param < T > the class representing configuration to acquire
 * @ return the decoded configuration object
 * @ throws ConfigurationException if the configuration cannot be acquired */
private < T > T getConfig ( final Class < T > configClass ) throws ConfigurationException { } }

implementation: Iterator < Name > it = getServicePath ( ) . descendingPathIterator ( ) ; while ( it . hasNext ( ) ) { try ( InputStream in = getConfigurationStream ( configClass , it . next ( ) ) ) { return decoder . deserialise ( in , configClass ) ; } catch ( final ConfigurationException e ) { LOG . trace ( "No configuration at this path level" , e ) ; } catch ( final CodecException | IOException e ) { incrementErrors ( ) ; throw new ConfigurationException ( "Failed to get configuration for " + configClass . getSimpleName ( ) , e ) ; } } incrementErrors ( ) ; throw new ConfigurationException ( "No configuration found for " + configClass . getSimpleName ( ) ) ;


signature:
public class CafConfigurationSource { /** * Checks whether the string substitution functionality should be enabled .
 * @ param bootstrapConfig used to provide basic , initial startup configuration
 * @ return true if the configuration substitution should be performed */
private static boolean getIsSubstitutorEnabled ( final BootstrapConfiguration bootstrapConfig ) { } }

implementation:
final String ENABLE_SUBSTITUTOR_CONFIG_KEY = "CAF_CONFIG_ENABLE_SUBSTITUTOR" ; final boolean ENABLE_SUBSTITUTOR_CONFIG_DEFAULT = true ; // Return the default if the setting is not configured
if ( ! bootstrapConfig . isConfigurationPresent ( ENABLE_SUBSTITUTOR_CONFIG_KEY ) ) { return ENABLE_SUBSTITUTOR_CONFIG_DEFAULT ; } // Return the configured setting .
// The ConfigurationException should never happen since isConfigurationPresent ( ) has already been called .
try { return bootstrapConfig . getConfigurationBoolean ( ENABLE_SUBSTITUTOR_CONFIG_KEY ) ; } catch ( final ConfigurationException ex ) { throw new RuntimeException ( ex ) ; }


signature:
public class Jersey2ServiceIteratorProvider { /** * Excludes all " com . sun . jersey " classes . */
@ Override public < T > Iterator < Class < T > > createClassIterator ( final Class < T > service , final String serviceName , final ClassLoader loader , final boolean ignoreOnClassNotFound ) { } }

implementation: final Iterator < Class < T > > delegateClassIterator = delegate . createClassIterator ( service , serviceName , loader , ignoreOnClassNotFound ) ; Stream < Class < T > > stream = StreamSupport . stream ( Spliterators . spliteratorUnknownSize ( delegateClassIterator , Spliterator . ORDERED ) , false ) ; return stream . filter ( t -> ! t . getPackage ( ) . getName ( ) . startsWith ( "com.sun.jersey" ) ) . collect ( Collectors . toList ( ) ) . iterator ( ) ;


signature:
public class CafConfigurationDecoderProvider { /** * Returns the Decoder that should be used to interpret the configuration files .
 * @ param bootstrap used to provide basic , initial startup configuration
 * @ param defaultDecoder the Decoder to use if one is not configured
 * @ return the Decoder that should be used to interpret the configuration files */
@ Override public Decoder getDecoder ( final BootstrapConfiguration bootstrap , final Decoder defaultDecoder ) { } }

implementation:
final String DECODER_CONFIG_KEY = "CAF_CONFIG_DECODER" ; final String decoder ; try { // Return the specified default Decoder if none has been configured
if ( ! bootstrap . isConfigurationPresent ( DECODER_CONFIG_KEY ) ) { return defaultDecoder ; } // Lookup the Decoder to use
decoder = bootstrap . getConfiguration ( DECODER_CONFIG_KEY ) ; } catch ( final ConfigurationException ex ) { // Throw a RuntimeException since this shouldn ' t happen
// ( since isConfigurationPresent ( ) has already been called )
throw new RuntimeException ( ex ) ; } try { // Retrieve the Decoder using the ModuleProvider
return ModuleProvider . getInstance ( ) . getModule ( Decoder . class , decoder ) ; } catch ( final NullPointerException ex ) { throw new RuntimeException ( "Unable to get Decoder using " + DECODER_CONFIG_KEY + " value: " + decoder , ex ) ; }


signature:
public class ModuleLoader { /** * Determine the first advertised service implementation for the specified interface . The implementations are advertised via the Java
 * " ServiceLoader " mechanism .
 * @ param intf the interface to find an advertised service implementation for
 * @ param < T > the interface
 * @ return an advertised implementation of intf of type T
 * @ throws ModuleLoaderException if there is no advertised implementation available */
public static < T > T getService ( final Class < T > intf ) throws ModuleLoaderException { } }

implementation: return getService ( intf , null ) ;


signature:
public class ModuleLoader { /** * Determine the first advertised service implementation for the specified interface . The implementations are advertised via the Java
 * " ServiceLoader " mechanism .
 * @ param intf the interface to find an advertised service implementation for
 * @ param defaultImpl the default implementation class if an advertised one is not found , may be null
 * @ param < T > the interface
 * @ return an advertised implementation of intf of type T
 * @ throws ModuleLoaderException if the implementation is missing and no defaultImpl is specified */
public static < T > T getService ( final Class < T > intf , final Class < ? extends T > defaultImpl ) throws ModuleLoaderException { } }

implementation: final T implementation = getServiceOrElse ( intf , null ) ; if ( implementation != null ) { return implementation ; } if ( defaultImpl == null ) { throw new ModuleLoaderException ( "Missing implementation: " + intf ) ; } try { return defaultImpl . getConstructor ( ) . newInstance ( ) ; } catch ( final InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) { throw new ModuleLoaderException ( "Cannot instantiate class" , e ) ; }


signature:
public class ModuleLoader { /** * Determine the first advertised service implementation for the specified interface . The implementations are advertised via the Java
 * " ServiceLoader " mechanism .
 * @ param < T > the interface
 * @ param intf the interface to find an advertised service implementation for
 * @ param defaultObj the default object to return if an advertised one is not found , may be null
 * @ return an advertised implementation of intf of type T , or the default object if one is not found */
public static < T > T getServiceOrElse ( final Class < T > intf , final T defaultObj ) { } }

implementation: Objects . requireNonNull ( intf ) ; final T ret ; List < T > implementations = getServices ( intf ) ; if ( implementations . isEmpty ( ) ) { return defaultObj ; } else { ret = implementations . get ( 0 ) ; } if ( implementations . size ( ) > 1 ) { LOG . warn ( "There is more than one implementation of {} available on the classpath, taking the first available" , intf ) ; } LOG . info ( "Detected component implementation {}" , ret . getClass ( ) . getSimpleName ( ) ) ; return ret ;


signature:
public class ModuleLoader { /** * Get all advertised service implementations of the specified interface .
 * @ param intf the interface to find advertised service implementations of
 * @ param < T > the interface
 * @ return a collection of implementations of the specified interface */
public static < T > List < T > getServices ( final Class < T > intf ) { } }

implementation: Objects . requireNonNull ( intf ) ; List < T > ret = new LinkedList < > ( ) ; for ( final T t : ServiceLoader . load ( intf ) ) { ret . add ( t ) ; } return ret ;


signature:
public class ModuleProvider { /** * Retrieves a module by its simple name , that implements a particular type T
 * @ param interfaceImplemented The interface that ' moduleType ' implements and that the result should be returned as .
 * @ param moduleType Represents particular instance of a factory type object e . g . ' ExampleWorkerBuilder '
 * @ return An instance of moduleType as the type T passed in .
 * @ throws NullPointerException If the module cannot be retrieved with the specified moduleType . */
public < T > T getModule ( final Class < T > interfaceImplemented , final String moduleType ) throws NullPointerException { } }

implementation:
// check for this type in the map
Map < String , Object > computedValue = loadedModules . computeIfAbsent ( interfaceImplemented , ModuleProvider :: loadModules ) ; Object moduleInstance = computedValue . get ( moduleType ) ; Objects . requireNonNull ( moduleInstance , "Unable to find implementation of " + interfaceImplemented . getName ( ) + " with moduleType " + moduleType ) ; return ( T ) moduleInstance ;


signature:
public class ReferencedData { /** * Return the referenced data as a stream , potentially performing a remote lookup .
 * @ param source the implementation that provides object instances given the provided references
 * @ return a stream of the data that this container is wrapping
 * @ throws DataSourceException if the data cannot be acquired
 * @ throws IllegalStateException if there is no object or reference present */
public synchronized InputStream acquire ( final DataSource source ) throws DataSourceException { } }

implementation: InputStream ret ; if ( data == null ) { if ( getReference ( ) == null ) { throw new IllegalStateException ( "No data or reference present" ) ; } else { ret = source . getStream ( getReference ( ) ) ; } } else { ret = new ByteArrayInputStream ( data ) ; } return ret ;


signature:
public class ReferencedData { /** * Determine the size of the data .
 * @ param source the implementation that provides object instances given the provided references
 * @ return the size of the abstracted data , in bytes
 * @ throws DataSourceException if the size information cannot be acquired */
public synchronized long size ( final DataSource source ) throws DataSourceException { } }

implementation: if ( data == null ) { if ( getReference ( ) == null ) { throw new IllegalStateException ( "No data or reference present" ) ; } else { return source . getDataSize ( getReference ( ) ) ; } } else { return data . length ; }


signature:
public class ReferencedData { /** * Create a ReferencedData instance that wraps data but also has a reference .
 * @ param ref the reference to be interpreted by the DataStore
 * @ param data the raw data to wrapper , also accessible via the supplied reference
 * @ return a new ReferencedData instance that wraps and references the data supplied */
public static ReferencedData getWrappedData ( final String ref , final byte [ ] data ) { } }

implementation: return new ReferencedData ( Objects . requireNonNull ( ref ) , data ) ;


signature:
public class Name { /** * Get the components of the Name at the specified numeric index
 * @ param index the index of the token to return , starting from 0
 * @ return the requested Name component
 * @ throws IllegalArgumentException if you request an index that does not exist */
public String getIndex ( final int index ) { } }

implementation: if ( index < 0 || index >= components . size ( ) ) { throw new IllegalArgumentException ( "Index out of bounds" ) ; } return components . get ( index ) ;


signature:
public class Name { /** * Return a Name that consists of a subsection of the current Name .
 * @ param upperIndex the upper index ( exclusive ) of components to build the Name from
 * @ return a new Name , that is a sub - set of the current Name
 * @ throws IllegalArgumentException if you request an index that is no in the range of components of this Name */
public Name getPrefix ( final int upperIndex ) { } }

implementation: if ( upperIndex < 0 || upperIndex > components . size ( ) ) { throw new IllegalArgumentException ( "Index out of bounds" ) ; } return new Name ( components . subList ( 0 , upperIndex ) ) ;


signature:
public class Arc { /** * is an arc colored , and hence on a color chain ? */
boolean colored ( ) { } }

implementation: return type == Compiler . PLAIN || type == Compiler . AHEAD || type == Compiler . BEHIND ;


signature:
public class Runtime { /** * exec - match regular expression */
boolean exec ( HsrePattern re , CharSequence data , EnumSet < ExecFlags > execFlags ) throws RegexException { } }

implementation:
/* sanity checks */
/* setup */
if ( 0 != ( re . guts . info & Flags . REG_UIMPOSSIBLE ) ) { throw new RegexException ( "Regex marked impossible" ) ; } eflags = 0 ; for ( ExecFlags ef : execFlags ) { switch ( ef ) { case NOTBOL : eflags |= Flags . REG_NOTBOL ; break ; case NOTEOL : eflags |= Flags . REG_NOTEOL ; break ; case LOOKING_AT : eflags |= Flags . REG_LOOKING_AT ; break ; default : throw new RuntimeException ( "impossible exec flag" ) ; } } this . re = re ; this . g = re . guts ; this . data = data ; this . dataLength = this . data . length ( ) ; if ( this . match != null ) { this . match . clear ( ) ; } else { this . match = Lists . newArrayList ( ) ; } match . add ( null ) ; // make room for 1.
if ( 0 != ( g . info & Flags . REG_UBACKREF ) ) { while ( match . size ( ) < g . nsub + 1 ) { match . add ( null ) ; } } if ( mem != null && mem . length >= g . ntree ) { Arrays . fill ( mem , 0 ) ; } else { mem = new int [ g . ntree ] ; } /* do it */
assert g . tree != null ; if ( 0 != ( g . info & Flags . REG_UBACKREF ) ) { return cfind ( g . tree . machine ) ; } else { return find ( g . tree . machine ) ; }


signature:
public class Runtime { /** * find - find a match for the main NFA ( no - complications case )
 * First , it runs the ' search machine ' in non - greedy mode ( shortest ) . The ' search machine ' is the NFA with
 * . * added to the front and the back , more or less . See ' makesearch ' . In many cases , running the search machine
 * ' shortest ' is considerably faster than running the actual regular expression in greedy ( longest ) . So ,
 * even though this may seem like it would take extra time doing an extra scan , the alternative is much slower .
 * The search machine tells you if the expression can be found anywhere , and , if so , where is the furthest possible
 * end .
 * If the search machine succeeds , the does an iteration to find the exact bounds ;
 * the loop uses ' longest ' or ' shortest ' as appropriate to the flags . In C , there was an option to
 * _ only _ run the search machine and return a simple boolean with no bounds .
 * We have no API for that via an ExecFlag .
 * If the top - level API call is ' lookingAt ' , we never want to scan down the data looking for matches . But ' shortest '
 * can still be much faster than ' longest ' . So , the code runs the original machine first . If non - greedy expressions
 * were very common , I suppose that it would be faster to omit this step in that case . Thereafter , the loop has
 * a check to bail if these is no match at the beginning of the data , which is the constraint of lookingAt . */
boolean find ( Cnfa cnfa ) { } }

implementation:
int begin ; int end = - 1 ; int cold ; int open ; /* open and close of range of possible starts */
int close ; boolean hitend ; boolean shorter = 0 != ( g . tree . flags & Subre . SHORTER ) ; boolean lookingAt = 0 != ( eflags & Flags . REG_LOOKING_AT ) ; int [ ] coldp = new int [ 1 ] ; Dfa d = new Dfa ( this , cnfa ) ; if ( lookingAt ) { /* * shortest is faster than longest . So , we want to check with it .
 * However , since we aren ' t making a ' search re ' with an extra . * on
 * the front , we don ' t add an extra requirement to make progress on the
 * very first arc . If the expression has something like a * at the front ,
 * it can ' no - progress ' consuming the a characters .
 * All of this casts doubts on the ' requireInitialProgress ' feature - - at all .
 * These initial calls to shortest should be all the opportunity we need
 * to do ' lookingAt ' . */
close = d . shortest ( 0 , 0 , data . length ( ) , coldp , null ) ; cold = 0 ; } else { /* First , a shot with the search RE . */
Dfa s = new Dfa ( this , g . search ) ; close = s . shortest ( 0 , 0 , data . length ( ) , coldp , null ) ; cold = coldp [ 0 ] ; } if ( close == - 1 ) { /* not found */
return false ; } /* find starting point and match */
open = cold ; cold = - 1 ; for ( begin = open ; begin <= close ; begin ++ ) { /* * if LOOKING _ AT , we can ' t validly have a ' begin ' after ' open ' .
 * I ' m not sure this test can even ever go off , since the ' shortest ' test
 * up above should accomplish the same thing . */
if ( begin > 0 && lookingAt ) { return false ; } boolean [ ] hitendp = new boolean [ 1 ] ; if ( shorter ) { end = d . shortest ( begin , begin , data . length ( ) , null , hitendp ) ; } else { end = d . longest ( begin , data . length ( ) , hitendp ) ; } hitend = hitendp [ 0 ] ; if ( hitend && cold == - 1 ) { cold = begin ; } if ( end != - 1 ) { /* success */
break ; /* NOTE BREAK OUT */
} } if ( end == - 1 ) { return false ; } /* and pin down details */
match . set ( 0 , new RegMatch ( begin , end ) ) ; // no need to do the work .
return re . nsub <= 0 || dissect ( g . tree , begin , end ) ;


signature:
public class Runtime { /** * cfind - find a match for the main NFA ( with complications ) */
private boolean cfind ( Cnfa cnfa ) { } }

implementation: int [ ] cold = new int [ 1 ] ; Dfa s = new Dfa ( this , g . search ) ; Dfa d = new Dfa ( this , cnfa ) ; return cfindloop ( d , s , cold ) ;


signature:
public class Runtime { /** * cfindloop - the heart of cfind */
private boolean cfindloop ( Dfa d , Dfa s , int [ ] coldp ) { } }

implementation:
int begin ; int end ; int cold ; int open ; /* open and close of range of possible starts */
int close ; int estart ; int estop ; boolean shorter = 0 != ( g . tree . flags & Subre . SHORTER ) ; boolean hitend [ ] = new boolean [ 1 ] ; boolean lookingAt = 0 != ( eflags & Flags . REG_LOOKING_AT ) ; assert d != null && s != null ; close = 0 ; do { int [ ] cold0 = new int [ 1 ] ; /* * Call search NFA to see if this is possible at all . */
if ( lookingAt ) { // in the looking at case , we use the un - search - ified RE .
close = d . shortest ( close , close , data . length ( ) , cold0 , null ) ; cold = 0 ; } else { close = s . shortest ( close , close , data . length ( ) , cold0 , null ) ; cold = cold0 [ 0 ] ; } if ( close == - 1 ) { break ; /* NOTE BREAK */
} assert cold != - 1 ; open = cold ; cold = - 1 ; for ( begin = open ; begin <= close ; begin ++ ) { if ( begin > 0 && lookingAt ) { // Is this possible given the looking - at constraint in the call to shortest above ?
return false ; } estart = begin ; estop = data . length ( ) ; for ( ; ; ) { if ( shorter ) { end = d . shortest ( begin , estart , estop , null , hitend ) ; } else { end = d . longest ( begin , estop , hitend ) ; } if ( hitend [ 0 ] && cold == - 1 ) { cold = begin ; } if ( end == - 1 ) { break ; /* NOTE BREAK OUT */
} for ( int x = 0 ; x < match . size ( ) ; x ++ ) { match . set ( x , null ) ; } int maxsubno = getMaxSubno ( g . tree , 0 ) ; mem = new int [ maxsubno + 1 ] ; boolean matched = cdissect ( g . tree , begin , end ) ; if ( matched ) { // indicate the full match bounds .
match . set ( 0 , new RegMatch ( begin , end ) ) ; coldp [ 0 ] = cold ; return true ; } if ( shorter ? end == estop : end == begin ) { /* no point in trying again */
coldp [ 0 ] = cold ; return false ; } /* go around and try again */
if ( shorter ) { estart = end + 1 ; } else { estop = end - 1 ; } } } } while ( close < data . length ( ) ) ; coldp [ 0 ] = cold ; return false ;


signature:
public class Runtime { /** * subset - set any subexpression relevant to a successful subre */
private void subset ( RuntimeSubexpression sub , int begin , int end ) { } }

implementation: int n = sub . number ; assert n > 0 ; while ( match . size ( ) < ( n + 1 ) ) { match . add ( null ) ; } match . set ( n , new RegMatch ( begin , end ) ) ;


signature:
public class Runtime { /** * dissect - determine subexpression matches ( uncomplicated case ) */
private boolean dissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation:
switch ( t . op ) { case '=' : /* terminal node */
assert t . left == null && t . right == null ; return true ; /* no action , parent did the work */
case '|' : /* alternation */
assert t . left != null ; return altdissect ( t , begin , end ) ; case 'b' : /* back ref - - shouldn ' t be calling us ! */
throw new RuntimeException ( "impossible backref" ) ; case '.' : /* concatenation */
assert t . left != null && t . right != null ; return condissect ( t , begin , end ) ; case '(' : /* capturing */
assert t . left != null && t . right == null ; assert t . number > 0 ; subset ( t , begin , end ) ; return dissect ( t . left , begin , end ) ; default : throw new RuntimeException ( "Impossible op" ) ; }


signature:
public class Runtime { /** * condissect - determine concatenation subexpression matches ( uncomplicated ) */
private boolean condissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation:
Dfa d ; Dfa d2 ; int mid ; assert t . op == '.' ; assert t . left != null && t . left . machine . states . length > 0 ; assert t . right != null && t . right . machine . states . length > 0 ; boolean shorter = ( t . left . flags & Subre . SHORTER ) != 0 ; int stop = shorter ? end : begin ; d = new Dfa ( this , t . left . machine ) ; d2 = new Dfa ( this , t . right . machine ) ; /* pick a tentative midpoint */
if ( shorter ) { mid = d . shortest ( begin , begin , end , null , null ) ; } else { mid = d . longest ( begin , end , null ) ; } if ( mid == - 1 ) { throw new RuntimeException ( "Impossible mid." ) ; } /* iterate until satisfaction or failure */
while ( d2 . longest ( mid , end , null ) != end ) { /* that midpoint didn ' t work , find a new one */
if ( mid == stop ) { /* all possibilities exhausted ! */
throw new RuntimeException ( "no midpoint" ) ; } if ( shorter ) { mid = d . shortest ( begin , mid + 1 , end , null , null ) ; } else { mid = d . longest ( begin , mid - 1 , null ) ; } if ( mid == - 1 ) { throw new RuntimeException ( "Failed midpoint" ) ; } } /* satisfaction */
boolean dissectMatch = dissect ( t . left , begin , mid ) ; if ( ! dissectMatch ) { return false ; } return dissect ( t . right , mid , end ) ;


signature:
public class Runtime { /** * altdissect - determine alternative subexpression matches ( uncomplicated ) */
private boolean altdissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation: Dfa d ; assert t != null ; assert t . op == '|' ; for ( ; t != null ; t = t . right ) { assert t . left != null && t . left . machine . states . length > 0 ; d = new Dfa ( this , t . left . machine ) ; if ( d . longest ( begin , end , null ) == end ) { return dissect ( t . left , begin , end ) ; } } throw new RuntimeException ( "none matched" ) ;


signature:
public class Runtime { /** * cdissect - determine subexpression matches ( with complications )
 * The retry memory stores the offset of the trial midpoint from begin ,
 * plus 1 so that 0 uniquely means " clean slate " . */
private boolean cdissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation:
assert t != null ; switch ( t . op ) { case '=' : /* terminal node */
assert t . left == null && t . right == null ; return true ; /* no action , parent did the work */
case '|' : /* alternation */
assert t . left != null ; return caltdissect ( t , begin , end ) ; case 'b' : /* back ref - - shouldn ' t be calling us ! */
assert t . left == null && t . right == null ; return cbrdissect ( t , begin , end ) ; case '.' : /* concatenation */
assert t . left != null && t . right != null ; return ccondissect ( t , begin , end ) ; case '(' : /* capturing */
assert t . left != null && t . right == null ; assert t . number > 0 ; boolean cdmatch = cdissect ( t . left , begin , end ) ; if ( cdmatch ) { subset ( t , begin , end ) ; } return cdmatch ; default : throw new RuntimeException ( "Impossible op" ) ; }


signature:
public class Runtime { /** * crevdissect - determine backref shortest - first subexpression matches
 * The retry memory stores the offset of the trial midpoint from begin ,
 * plus 1 so that 0 uniquely means " clean slate " . */
private boolean crevdissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation:
Dfa d ; Dfa d2 ; int mid ; assert t . op == '.' ; assert t . left != null && t . left . machine . states . length > 0 ; assert t . right != null && t . right . machine . states . length > 0 ; assert 0 != ( t . left . flags & Subre . SHORTER ) ; /* concatenation - - need to split the substring between parts */
d = new Dfa ( this , t . left . machine ) ; d2 = new Dfa ( this , t . right . machine ) ; /* pick a tentative midpoint */
if ( mem [ t . retry ] == 0 ) { mid = d . shortest ( begin , begin , end , null , null ) ; if ( mid == - 1 ) { return false ; } mem [ t . retry ] = ( mid - begin ) + 1 ; } else { mid = begin + ( mem [ t . retry ] - 1 ) ; } /* iterate until satisfaction or failure */
for ( ; ; ) { /* try this midpoint on for size */
boolean cdmatch = cdissect ( t . left , begin , mid ) ; if ( cdmatch && d2 . longest ( mid , end , null ) == end && ( cdissect ( t . right , mid , end ) ) ) { break ; /* NOTE BREAK OUT */
} /* that midpoint didn ' t work , find a new one */
if ( mid == end ) { /* all possibilities exhausted */
return false ; } mid = d . shortest ( begin , mid + 1 , end , null , null ) ; if ( mid == - 1 ) { /* failed to find a new one */
return false ; } mem [ t . retry ] = ( mid - begin ) + 1 ; zapmem ( t . left ) ; zapmem ( t . right ) ; } /* satisfaction */
return true ;


signature:
public class Runtime { /** * cbrdissect - determine backref subexpression matches */
private boolean cbrdissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation:
int i ; int n = t . number ; int len ; int paren ; int p ; int stop ; int min = t . min ; int max = t . max ; assert t . op == 'b' ; assert n >= 0 ; // TODO : could this get be out of range ?
if ( match . get ( n ) == null ) { return false ; } paren = match . get ( n ) . start ; len = match . get ( n ) . end - match . get ( n ) . start ; /* no room to maneuver - - retries are pointless */
if ( 0 != mem [ t . retry ] ) { return false ; } mem [ t . retry ] = 1 ; /* special - case zero - length string */
if ( len == 0 ) { return begin == end ; } /* and too - short string */
assert end >= begin ; if ( ( end - begin ) < len ) { return false ; } stop = end - len ; /* count occurrences */
i = 0 ; for ( p = begin ; p <= stop && ( i < max || max == Compiler . INFINITY ) ; p += len ) { // paren is index of
if ( g . compare . compare ( data , paren , p , len ) != 0 ) { break ; } i ++ ; } /* and sort it out */
if ( p != end ) { /* didn ' t consume all of it */
return false ; } return min <= i && ( i <= max || max == Compiler . INFINITY ) ;


signature:
public class Runtime { /** * - caltdissect - determine alternative subexpression matches ( w . complications )
 * ^ static int caltdissect ( struct vars * , struct Subre , int , int ) ; */
private boolean caltdissect ( RuntimeSubexpression t , int begin , int end ) { } }

implementation: Dfa d ; if ( t == null ) { return false ; } assert t . op == '|' ; if ( mem [ t . retry ] == TRIED ) { return caltdissect ( t . right , begin , end ) ; } if ( mem [ t . retry ] == UNTRIED ) { d = new Dfa ( this , t . left . machine ) ; if ( d . longest ( begin , end , null ) != end ) { mem [ t . retry ] = TRIED ; return caltdissect ( t . right , begin , end ) ; } mem [ t . retry ] = TRYING ; } boolean cdmatch = cdissect ( t . left , begin , end ) ; if ( cdmatch ) { return true ; } mem [ t . retry ] = TRIED ; return caltdissect ( t . right , begin , end ) ;


signature:
public class Compiler { /** * makesearch - turn an NFA into a search NFA ( implicit prepend of . * ? )
 * NFA must have been optimize ( ) d already . */
private void makesearch ( Nfa nfa ) { } }

implementation:
Arc a ; Arc b ; State pre = nfa . pre ; State s ; State s2 ; State slist ; /* no loops are needed if it ' s anchored */
for ( a = pre . outs ; a != null ; a = a . outchain ) { assert a . type == PLAIN ; if ( a . co != nfa . bos [ 0 ] && a . co != nfa . bos [ 1 ] ) { break ; } } if ( a != null ) { /* add implicit . * in front */
cm . rainbow ( nfa , PLAIN , Constants . COLORLESS , pre , pre ) ; /* and ^ * and \ A * too - - not always necessary , but harmless */
nfa . newarc ( PLAIN , nfa . bos [ 0 ] , pre , pre ) ; nfa . newarc ( PLAIN , nfa . bos [ 1 ] , pre , pre ) ; } /* * Now here ' s the subtle part . Because many REs have no lookback
 * constraints , often knowing when you were in the pre state tells
 * you little ; it ' s the next state ( s ) that are informative . But
 * some of them may have other inarcs , i . e . it may be possible to
 * make actual progress and then return to one of them . We must
 * de - optimize such cases , splitting each such state into progress
 * and no - progress states . */
/* first , make a list of the states */
slist = null ; for ( a = pre . outs ; a != null ; a = a . outchain ) { s = a . to ; for ( b = s . ins ; b != null ; b = b . inchain ) { if ( b . from != pre ) { break ; } } if ( b != null ) { /* must be split */
if ( s . tmp == null ) { /* if not already in the list */
/* ( fixes bugs 505048 , 230589, */
/* 840258 , 504785) */
s . tmp = slist ; slist = s ; } } } /* do the splits */
for ( s = slist ; s != null ; s = s2 ) { s2 = nfa . newstate ( ) ; copyouts ( nfa , s , s2 ) ; for ( a = s . ins ; a != null ; a = b ) { b = a . inchain ; if ( a . from != pre ) { cparc ( nfa , a , a . from , s2 ) ; nfa . freearc ( a ) ; } } s2 = s . tmp ; s . tmp = null ; /* clean up while we ' re at it */
}


signature:
public class Compiler { /** * cloneouts - copy out arcs of a state to another state pair , modifying type */
private void cloneouts ( Nfa nfa , State old , State from , State to , int type ) { } }

implementation: Arc a ; assert old != from ; for ( a = old . outs ; a != null ; a = a . outchain ) { nfa . newarc ( type , a . co , from , to ) ; }


signature:
public class Compiler { /** * optst - optimize a subRE subtree */
private void optst ( Subre t ) { } }

implementation:
if ( t == null ) { return ; } /* recurse through children */
if ( t . left != null ) { optst ( t . left ) ; } if ( t . right != null ) { optst ( t . right ) ; }


signature:
public class Compiler { /** * numst - number tree nodes ( assigning retry indexes )
 * @ return next number */
private int numst ( Subre t , int start ) { } }

implementation: int i ; assert t != null ; i = start ; t . retry = ( short ) i ++ ; if ( t . left != null ) { i = numst ( t . left , i ) ; } if ( t . right != null ) { i = numst ( t . right , i ) ; } return i ;


signature:
public class Compiler { /** * markst - mark tree nodes as INUSE */
private void markst ( Subre t ) { } }

implementation: assert t != null ; t . flags |= Subre . INUSE ; if ( t . left != null ) { markst ( t . left ) ; } if ( t . right != null ) { markst ( t . right ) ; }


signature:
public class Compiler { /** * / * optimize results from top node */
private long nfatree ( Subre t ) throws RegexException { } }

implementation: assert t != null && t . begin != null ; if ( t . left != null ) { nfatree ( t . left ) ; } if ( t . right != null ) { nfatree ( t . right ) ; } return nfanode ( t ) ;


signature:
public class Compiler { /** * nfanode - do one NFA for nfatree
 * @ return results of { @ link Nfa # optimize ( ) } */
private long nfanode ( Subre t ) throws RegexException { } }

implementation:
long ret ; assert t . begin != null ; if ( LOG . isDebugEnabled ( ) && IS_DEBUG ) { LOG . debug ( String . format ( "========= TREE NODE %s ==========" , t . shortId ( ) ) ) ; } Nfa newNfa = new Nfa ( nfa ) ; newNfa . dupnfa ( t . begin , t . end , newNfa . init , newNfa . finalState ) ; newNfa . specialcolors ( ) ; ret = newNfa . optimize ( ) ; t . cnfa = newNfa . compact ( ) ; // freenfa . . . depend on our friend the GC .
return ret ;


signature:
public class Compiler { /** * parse - parse an RE
 * This is actually just the top level , which parses a bunch of branches
 * tied together with ' | ' . They appear in the tree as the left children
 * of a chain of ' | ' subres . */
private Subre parse ( int stopper , int type , State initState , State finalState ) throws RegexException { } }

implementation:
State left ; /* scaffolding for branch */
State right ; Subre branches ; /* top level */
Subre branch ; /* current branch */
Subre t ; /* temporary */
int firstbranch ; /* is this the first branch ? */
assert stopper == ')' || stopper == EOS ; branches = new Subre ( '|' , Subre . LONGER , initState , finalState ) ; branch = branches ; firstbranch = 1 ; do { /* a branch */
if ( 0 == firstbranch ) { /* need a place to hang it */
branch . right = new Subre ( '|' , Subre . LONGER , initState , finalState ) ; branch = branch . right ; } firstbranch = 0 ; left = nfa . newstate ( ) ; right = nfa . newstate ( ) ; nfa . emptyarc ( initState , left ) ; nfa . emptyarc ( right , finalState ) ; branch . left = parsebranch ( stopper , type , left , right , false ) ; branch . flags |= up ( branch . flags | branch . left . flags ) ; if ( ( branch . flags & ~ branches . flags ) != 0 ) /* new flags */
{ for ( t = branches ; t != branch ; t = t . right ) { t . flags |= branch . flags ; } } } while ( eat ( '|' ) ) ; assert see ( stopper ) || see ( EOS ) ; if ( ! see ( stopper ) ) { assert stopper == ')' && see ( EOS ) ; // ERR ( REG _ EPAREN ) ;
throw new RegexException ( "Unbalanced parentheses." ) ; } /* optimize out simple cases */
if ( branch == branches ) { /* only one branch */
assert branch . right == null ; t = branch . left ; branch . left = null ; branches = t ; } else if ( ! messy ( branches . flags ) ) { /* no interesting innards */
branches . left = null ; branches . right = null ; branches . op = '=' ; } return branches ;


signature:
public class Compiler { /** * parsebranch - parse one branch of an RE
 * This mostly manages concatenation , working closely with parseqatom ( ) .
 * Concatenated things are bundled up as much as possible , with separate
 * ' , ' nodes introduced only when necessary due to substructure . */
private Subre parsebranch ( int stopper , int type , State left , State right , boolean partial ) throws RegexException { } }

implementation:
State lp ; /* left end of current construct */
boolean seencontent = false ; /* is there anything in this branch yet ? */
Subre t ; lp = left ; t = new Subre ( '=' , 0 , left , right ) ; /* op ' = ' is tentative */
while ( ! see ( '|' ) && ! see ( stopper ) && ! see ( EOS ) ) { if ( seencontent ) { /* implicit concat operator */
lp = nfa . newstate ( ) ; moveins ( nfa , right , lp ) ; } seencontent = true ; /* NB , recursion in parseqatom ( ) may swallow rest of branch */
parseqatom ( stopper , type , lp , right , t ) ; } if ( ! seencontent ) { /* empty branch */
if ( ! partial ) { note ( Flags . REG_UUNSPEC ) ; } nfa . emptyarc ( left , right ) ; } return t ;


signature:
public class Compiler { /** * CHECKSTYLE : OFF */
private void parseqatom ( int stopper , int type , State lp , State rp , Subre top ) throws RegexException { } }

implementation:
State s ; /* temporaries for new states */
State s2 ; int m ; int n ; Subre atom ; /* atom ' s subtree */
Subre t ; boolean cap ; /* capturing parens ? */
int pos ; /* positive lookahead ? */
int subno ; /* capturing - parens or backref number */
int atomtype ; int qprefer ; /* quantifier short / long preference */
int f ; AtomSetter atomp ; /* initial bookkeeping */
atom = null ; assert lp . nouts == 0 ; /* must string new code */
assert rp . nins == 0 ; /* between lp and rp */
subno = 0 ; /* just to shut lint up */
/* an atom or constraint . . . */
atomtype = nexttype ; switch ( atomtype ) { /* first , constraints , which end by returning */
case '^' : nfa . newarc ( '^' , ( short ) 1 , lp , rp ) ; if ( 0 != ( cflags & Flags . REG_NLANCH ) ) { nfa . newarc ( BEHIND , nlcolor , lp , rp ) ; } lex . next ( ) ; return ; case '$' : nfa . newarc ( '$' , ( short ) 1 , lp , rp ) ; if ( 0 != ( cflags & Flags . REG_NLANCH ) ) { nfa . newarc ( AHEAD , nlcolor , lp , rp ) ; } lex . next ( ) ; return ; case SBEGIN : nfa . newarc ( '^' , ( short ) 1 , lp , rp ) ; /* BOL */
nfa . newarc ( '^' , ( short ) 0 , lp , rp ) ; /* or BOS */
lex . next ( ) ; return ; case SEND : nfa . newarc ( '$' , ( short ) 1 , lp , rp ) ; /* EOL */
nfa . newarc ( '$' , ( short ) 0 , lp , rp ) ; /* or EOS */
lex . next ( ) ; return ; case '<' : wordchrs ( ) ; /* does next ( ) */
s = nfa . newstate ( ) ; nonword ( BEHIND , lp , s ) ; word ( AHEAD , s , rp ) ; return ; case '>' : wordchrs ( ) ; /* does next ( ) */
s = nfa . newstate ( ) ; word ( BEHIND , lp , s ) ; nonword ( AHEAD , s , rp ) ; return ; case WBDRY : wordchrs ( ) ; /* does next ( ) */
s = nfa . newstate ( ) ; nonword ( BEHIND , lp , s ) ; word ( AHEAD , s , rp ) ; s = nfa . newstate ( ) ; word ( BEHIND , lp , s ) ; nonword ( AHEAD , s , rp ) ; return ; case NWBDRY : wordchrs ( ) ; /* does next ( ) */
s = nfa . newstate ( ) ; word ( BEHIND , lp , s ) ; word ( AHEAD , s , rp ) ; s = nfa . newstate ( ) ; nonword ( BEHIND , lp , s ) ; nonword ( AHEAD , s , rp ) ; return ; case LACON : /* lookahead constraint */
pos = nextvalue ; lex . next ( ) ; s = nfa . newstate ( ) ; s2 = nfa . newstate ( ) ; parse ( ')' , LACON , s , s2 ) ; // parse for side - effect .
assert see ( ')' ) ; lex . next ( ) ; n = newlacon ( s , s2 , pos ) ; nfa . newarc ( LACON , ( short ) n , lp , rp ) ; return ; /* then errors , to get them out of the way */
case '*' : case '+' : case '?' : case '{' : throw new RegexException ( "Pattern syntax error (*+?} misplaced)." ) ; /* then plain characters , and minor variants on that theme */
case ')' : /* unbalanced paren */
if ( ( cflags & Flags . REG_ADVANCED ) != Flags . REG_EXTENDED ) { throw new RegexException ( "Unbalanced parenthesis." ) ; } /* legal in EREs due to specification botch */
note ( Flags . REG_UPBOTCH ) ; /* fallthrough into case PLAIN */
case PLAIN : // look out for surrogates as ordinary chars .
if ( nextvalue < Character . MAX_VALUE && Character . isHighSurrogate ( ( char ) nextvalue ) ) { char high = ( char ) nextvalue ; lex . next ( ) ; char low = ( char ) nextvalue ; int codepoint = Character . toCodePoint ( high , low ) ; onechr ( codepoint , lp , rp ) ; } else { onechr ( nextvalue , lp , rp ) ; } cm . okcolors ( nfa ) ; lex . next ( ) ; break ; case '[' : if ( nextvalue == 1 ) { bracket ( lp , rp ) ; } else { cbracket ( lp , rp ) ; } assert see ( ']' ) ; lex . next ( ) ; break ; case '.' : cm . rainbow ( nfa , PLAIN , ( 0 != ( cflags & Flags . REG_NLSTOP ) ) ? nlcolor : Constants . COLORLESS , lp , rp ) ; lex . next ( ) ; break ; /* and finally the ugly stuff */
case '(' : /* value flags as capturing or non */
if ( type == LACON ) { cap = false ; } else { cap = nextvalue != 0 ; } if ( cap ) { subno = subs . size ( ) + 1 ; // first subno is 1.
/* * This recurses via a call to parse just below .
 * So , the size ( ) just above has to reflect this new sub ,
 * even though we won ' t create the object until a little further
 * down . */
subs . add ( null ) ; } else { atomtype = PLAIN ; /* something that ' s not ' ( ' */
} lex . next ( ) ; /* need new endpoints because tree will contain pointers */
s = nfa . newstate ( ) ; s2 = nfa . newstate ( ) ; nfa . emptyarc ( lp , s ) ; nfa . emptyarc ( s2 , rp ) ; atom = parse ( ')' , PLAIN , s , s2 ) ; assert see ( ')' ) ; lex . next ( ) ; if ( cap ) { // we can ' t assert anything about the size of ' subs ' , recursion may have added to it .
// but we can check that nothing has used our slot .
assert subs . get ( subno - 1 ) == null ; subs . set ( subno - 1 , atom ) ; t = new Subre ( '(' , atom . flags | Subre . CAP , lp , rp ) ; t . subno = subno ; t . left = atom ; atom = t ; } /* postpone everything else pending possible { 0} */
break ; case BACKREF : /* the Feature From The Black Lagoon */
if ( type == LACON ) { throw new RegexException ( "REG_ESUBREG" ) ; } if ( nextvalue > subs . size ( ) ) { throw new RegexException ( String . format ( "Backreference to %d out of range of defined subexpressions (%d)" , nextvalue , subs . size ( ) ) ) ; } if ( subs . get ( nextvalue - 1 ) == null ) { // \1 is first backref , living in slot 0.
throw new RegexException ( String . format ( "Backreference to %d refers to non-capturing group." , nextvalue ) ) ; } assert nextvalue > 0 ; atom = new Subre ( 'b' , Subre . BACKR , lp , rp ) ; subno = nextvalue ; atom . subno = subno ; nfa . emptyarc ( lp , rp ) ; /* temporarily , so there ' s something */
lex . next ( ) ; break ; default : throw new RuntimeException ( "Impossible type in lex" ) ; } /* . . . and an atom may be followed by a quantifier */
switch ( nexttype ) { case '*' : m = 0 ; n = INFINITY ; qprefer = ( nextvalue != 0 ) ? Subre . LONGER : Subre . SHORTER ; lex . next ( ) ; break ; case '+' : m = 1 ; n = INFINITY ; qprefer = ( nextvalue != 0 ) ? Subre . LONGER : Subre . SHORTER ; lex . next ( ) ; break ; case '?' : m = 0 ; n = 1 ; qprefer = ( nextvalue != 0 ) ? Subre . LONGER : Subre . SHORTER ; lex . next ( ) ; break ; case '{' : lex . next ( ) ; m = scannum ( ) ; if ( eat ( ',' ) ) { if ( see ( DIGIT ) ) { n = scannum ( ) ; } else { n = INFINITY ; } if ( m > n ) { throw new RegexException ( "First quantity is larger than second quantity in {m,n} quantifier." ) ; } /* { m , n } exercises preference , even if it ' s { m , m } */
qprefer = ( nextvalue != 0 ) ? Subre . LONGER : Subre . SHORTER ; } else { n = m ; /* { m } passes operand ' s preference through */
qprefer = 0 ; } if ( ! see ( '}' ) ) { /* catches errors too */
throw new RegexException ( "Invalid syntax for {m,n} quantifier." ) ; } lex . next ( ) ; break ; default : /* no quantifier */
m = 1 ; n = 1 ; qprefer = 0 ; break ; } /* annoying special case : { 0 } or { 0,0 } cancels everything */
if ( m == 0 && n == 0 ) { if ( atomtype == '(' ) { assert subno == subs . size ( ) - 1 ; subs . remove ( subs . size ( ) - 1 ) ; } delsub ( nfa , lp , rp ) ; nfa . emptyarc ( lp , rp ) ; return ; } /* if not a messy case , avoid hard part */
assert ! messy ( top . flags ) ; f = top . flags | qprefer | ( ( atom != null ) ? atom . flags : 0 ) ; if ( atomtype != '(' && atomtype != BACKREF && ! messy ( up ( f ) ) ) { if ( ! ( m == 1 && n == 1 ) ) { repeat ( lp , rp , m , n ) ; } top . flags = f ; return ; } /* * hard part : something messy
 * That is , capturing parens , back reference , short / long clash , or
 * an atom with substructure containing one of those . */
/* now we ' ll need a subre for the contents even if they ' re boring */
if ( atom == null ) { atom = new Subre ( '=' , 0 , lp , rp ) ; } /* * prepare a general - purpose state skeleton
 * - - . [ s ] - - - prefix - - . [ begin ] - - - atom - - . [ end ] - - - - rest - - . [ rp ]
 * [ lp ] - - - . [ s2 ] - - - - bypass - - - - -
 * where bypass is an empty , and prefix is some repetitions of atom */
s = nfa . newstate ( ) ; /* first , new endpoints for the atom */
s2 = nfa . newstate ( ) ; nfa . moveouts ( lp , s ) ; nfa . moveins ( rp , s2 ) ; atom . begin = s ; atom . end = s2 ; s = nfa . newstate ( ) ; /* and spots for prefix and bypass */
s2 = nfa . newstate ( ) ; nfa . emptyarc ( lp , s ) ; nfa . emptyarc ( lp , s2 ) ; /* break remaining subRE into x { . . . } and what follows */
t = new Subre ( '.' , Subre . combine ( qprefer , atom . flags ) , lp , rp ) ; t . left = atom ; final Subre target = t ; atomp = new AtomSetter ( ) { @ Override public void set ( Subre s ) { target . left = s ; } } ; /* here we should recurse . . . but we must postpone that to the end */
/* split top into prefix and remaining */
assert top . op == '=' && top . left == null && top . right == null ; top . left = new Subre ( '=' , top . flags , top . begin , lp ) ; top . op = '.' ; top . right = t ; /* if it ' s a backref , now is the time to replicate the subNFA */
if ( atomtype == BACKREF ) { assert atom . begin . nouts == 1 ; /* just the EMPTY */
delsub ( nfa , atom . begin , atom . end ) ; assert subs . get ( subno - 1 ) != null ; /* and here ' s why the recursion got postponed : it must */
/* wait until the skeleton is filled in , because it may */
/* hit a backref that wants to copy the filled - in skeleton */
nfa . dupnfa ( subs . get ( subno - 1 ) . begin , subs . get ( subno - 1 ) . end , atom . begin , atom . end ) ; } /* it ' s quantifier time ; first , turn x { 0 , . . . } into x { 1 , . . . } | empty */
if ( m == 0 ) { nfa . emptyarc ( s2 , atom . end ) ; /* the bypass */
assert Subre . pref ( qprefer ) != 0 ; f = Subre . combine ( qprefer , atom . flags ) ; t = new Subre ( '|' , f , lp , atom . end ) ; t . left = atom ; t . right = new Subre ( '|' , Subre . pref ( f ) , s2 , atom . end ) ; t . right . left = new Subre ( '=' , 0 , s2 , atom . end ) ; atomp . set ( t ) ; final Subre target2 = t ; atomp = new AtomSetter ( ) { @ Override public void set ( Subre s ) { target2 . left = s ; } } ; m = 1 ; } /* deal with the rest of the quantifier */
if ( atomtype == BACKREF ) { /* special case : backrefs have internal quantifiers */
nfa . emptyarc ( s , atom . begin ) ; /* empty prefix */
/* just stuff everything into atom */
repeat ( atom . begin , atom . end , m , n ) ; atom . min = ( short ) m ; atom . max = ( short ) n ; atom . flags |= Subre . combine ( qprefer , atom . flags ) ; } else if ( m == 1 && n == 1 ) { /* no / vacuous quantifier : done */
nfa . emptyarc ( s , atom . begin ) ; /* empty prefix */
} else { /* turn x { m , n } into x { m - 1 , n - 1 } x , with capturing */
/* parens in only second x */
nfa . dupnfa ( atom . begin , atom . end , s , atom . begin ) ; assert m >= 1 && m != INFINITY && n >= 1 ; repeat ( s , atom . begin , m - 1 , ( n == INFINITY ) ? n : n - 1 ) ; f = Subre . combine ( qprefer , atom . flags ) ; t = new Subre ( '.' , f , s , atom . end ) ; /* prefix and atom */
t . left = new Subre ( '=' , Subre . pref ( f ) , s , atom . begin ) ; t . right = atom ; atomp . set ( t ) ; } /* and finally , look after that postponed recursion */
t = top . right ; if ( ! ( see ( '|' ) || see ( stopper ) || see ( EOS ) ) ) { t . right = parsebranch ( stopper , type , atom . end , rp , true ) ; } else { nfa . emptyarc ( atom . end , rp ) ; t . right = new Subre ( '=' , 0 , atom . end , rp ) ; } assert see ( '|' ) || see ( stopper ) || see ( EOS ) ; t . flags |= Subre . combine ( t . flags , t . right . flags ) ; top . flags |= Subre . combine ( top . flags , t . flags ) ;


signature:
public class Compiler { /** * CHECKSTYLE : ON */
private void delsub ( Nfa nfa , State lp , State rp ) { } }

implementation:
rp . tmp = rp ; deltraverse ( nfa , lp , lp ) ; assert lp . nouts == 0 && rp . nins == 0 ; /* did the job */
assert lp . no != State . FREESTATE && rp . no != State . FREESTATE ; /* no more */
lp . tmp = null ; rp . tmp = null ;


signature:
public class Compiler { /** * deltraverse - the recursive heart of delsub
 * This routine ' s basic job is to destroy all out - arcs of the state . */
private void deltraverse ( Nfa nfa , State leftend , State s ) { } }

implementation:
Arc a ; State to ; if ( s . nouts == 0 ) { return ; /* nothing to do */
} if ( s . tmp != null ) { return ; /* already in progress */
} s . tmp = s ; /* mark as in progress */
while ( ( a = s . outs ) != null ) { to = a . to ; deltraverse ( nfa , leftend , to ) ; assert to . nouts == 0 || to . tmp != null ; nfa . freearc ( a ) ; if ( to . nins == 0 && to . tmp == null ) { assert to . nouts == 0 ; nfa . freestate ( to ) ; } } assert s . no != State . FREESTATE ; /* we ' re still here */
assert s == leftend || s . nins != 0 ; /* and still reachable */
assert s . nouts == 0 ; /* but have no outarcs */
s . tmp = null ; /* we ' re done here */


signature:
public class Compiler { /** * nonword - generate arcs for non - word - character ahead or behind */
private void nonword ( int dir , State lp , State rp ) { } }

implementation: int anchor = ( dir == AHEAD ) ? '$' : '^' ; assert dir == AHEAD || dir == BEHIND ; nfa . newarc ( anchor , ( short ) 1 , lp , rp ) ; nfa . newarc ( anchor , ( short ) 0 , lp , rp ) ; cm . colorcomplement ( nfa , dir , wordchrs , lp , rp ) ; /* ( no need for special attention to \ n ) */


signature:
public class Compiler { /** * word - generate arcs for word character ahead or behind */
private void word ( int dir , State lp , State rp ) { } }

implementation: assert dir == AHEAD || dir == BEHIND ; cloneouts ( nfa , wordchrs , lp , rp , dir ) ; /* ( no need for special attention to \ n ) */


signature:
public class Compiler { /** * scannum - scan a number
 * @ return value < = DUPMAX */
private int scannum ( ) throws RegexException { } }

implementation: int n = 0 ; while ( see ( DIGIT ) && n < DUPMAX ) { n = n * 10 + nextvalue ; lex . next ( ) ; } if ( see ( DIGIT ) || n > DUPMAX ) { throw new RegexException ( "Unvalid reference number." ) ; } return n ;


signature:
public class Compiler { /** * repeat - replicate subNFA for quantifiers
 * The duplication sequences used here are chosen carefully so that any
 * pointers starting out pointing into the subexpression end up pointing into
 * the last occurrence . ( Note that it may not be strung between the same
 * left and right end states , however ! ) This used to be important for the
 * subRE tree , although the important bits are now handled by the in - line
 * code in parse ( ) , and when this is called , it doesn ' t matter any more . */
private void repeat ( State lp , State rp , int m , int n ) throws RegexException { } }

implementation:
final int rm = reduce ( m ) ; final int rn = reduce ( n ) ; State s ; State s2 ; switch ( pair ( rm , rn ) ) { // pair ( 0 , 0)
case 0 : /* empty string */
// never get here ; other code optimizes this out .
delsub ( nfa , lp , rp ) ; nfa . emptyarc ( lp , rp ) ; break ; // case PAIR ( 0 , 1 ) : / * do as x | * /
case 1 : nfa . emptyarc ( lp , rp ) ; break ; // case PAIR ( 0 , SOME ) : / * do as x { 1 , n } | * /
case SOME : repeat ( lp , rp , 1 , n ) ; nfa . emptyarc ( lp , rp ) ; break ; // case PAIR ( 0 , INF ) : / * loop x around * /
case INF : s = nfa . newstate ( ) ; nfa . moveouts ( lp , s ) ; nfa . moveins ( rp , s ) ; nfa . emptyarc ( lp , s ) ; nfa . emptyarc ( s , rp ) ; break ; // case PAIR ( 1 , 1 ) : / * no action required * /
case 4 * 1 + 1 : break ; // case PAIR ( 1 , SOME ) : / * do as x { 0 , n - 1 } x = ( x { 1 , n - 1 } | ) x * /
case 4 * 1 + SOME : s = nfa . newstate ( ) ; nfa . moveouts ( lp , s ) ; nfa . dupnfa ( s , rp , lp , s ) ; repeat ( lp , s , 1 , n - 1 ) ; nfa . emptyarc ( lp , s ) ; break ; // case PAIR ( 1 , INF ) : / * add loopback arc * /
case 4 * 1 + INF : s = nfa . newstate ( ) ; s2 = nfa . newstate ( ) ; nfa . moveouts ( lp , s ) ; nfa . moveins ( rp , s2 ) ; nfa . emptyarc ( lp , s ) ; nfa . emptyarc ( s2 , rp ) ; nfa . emptyarc ( s2 , s ) ; break ; // case PAIR ( SOME , SOME ) : / * do as x { m - 1 , n - 1 } x * /
case 4 * SOME + SOME : s = nfa . newstate ( ) ; nfa . moveouts ( lp , s ) ; nfa . dupnfa ( s , rp , lp , s ) ; repeat ( lp , s , m - 1 , n - 1 ) ; break ; // case PAIR ( SOME , INF ) : / * do as x { m - 1 , } x * /
case 4 * SOME + INF : s = nfa . newstate ( ) ; nfa . moveouts ( lp , s ) ; nfa . dupnfa ( s , rp , lp , s ) ; repeat ( lp , s , m - 1 , n ) ; break ; default : throw new RuntimeException ( "Impossible quantification" ) ; }


signature:
public class Compiler { /** * wordchrs - set up word - chr list for word - boundary stuff , if needed
 * The list is kept as a bunch of arcs between two dummy states ; it ' s
 * disposed of by the unreachable - states sweep in NFA optimization .
 * Does NEXT ( ) . Must not be called from any unusual lexical context .
 * This should be reconciled with the \ w etc . handling in lex . c , and
 * should be cleaned up to reduce dependencies on input scanning . */
private void wordchrs ( ) throws RegexException { } }

implementation:
State left ; State right ; if ( wordchrs != null ) { lex . next ( ) ; /* for consistency */
return ; } left = nfa . newstate ( ) ; right = nfa . newstate ( ) ; /* fine point : implemented with [ : : ] , and lexer will set REG _ ULOCALE */
lex . lexword ( ) ; lex . next ( ) ; assert savepattern != null && see ( '[' ) ; bracket ( left , right ) ; assert savepattern != null && see ( ']' ) ; lex . next ( ) ; wordchrs = left ;


signature:
public class Compiler { /** * bracket - handle non - complemented bracket expression
 * Also called from cbracket for complemented bracket expressions . */
private void bracket ( State lp , State rp ) throws RegexException { } }

implementation: assert see ( '[' ) ; lex . next ( ) ; while ( ! see ( ']' ) && ! see ( EOS ) ) { brackpart ( lp , rp ) ; } assert see ( ']' ) ; cm . okcolors ( nfa ) ;


signature:
public class Compiler { /** * brackpart - handle one item ( or range ) within a bracket expression */
private void brackpart ( State lp , State rp ) throws RegexException { } }

implementation:
UnicodeSet set ; /* * OK , well ; if the user uses \ U the item that comes next can be a full codepoint .
 * If the user does not , it might be part of a surrogate . */
int c ; // start and end chars of a range
int startc ; int endc = 0 ; int ele ; /* parse something , get rid of special cases , take shortcuts */
switch ( nexttype ) { case RANGE : /* a - b - c or other botch */
throw new RegexException ( "Invalid syntax in range expression." ) ; case PLAIN : c = nextvalue ; lex . next ( ) ; if ( c <= Character . MAX_VALUE && Character . isHighSurrogate ( ( char ) c ) ) { // some idiot could write a high surrogate and then immediate \ \ Uxxxxx , woof .
char low = ( char ) nextvalue ; lex . next ( ) ; startc = Character . toCodePoint ( ( char ) c , low ) ; } else { startc = c ; } /* shortcut for ordinary char ( not range , not MCCE leader ) */
if ( ! see ( RANGE ) ) { onechr ( startc , lp , rp ) ; return ; } break ; // COLLEL and ECLASS are of dubious utility and don ' t try to get surrogates right .
case COLLEL : String charName = scanplain ( ) ; if ( charName . length ( ) == 0 ) { throw new RegexException ( "Missing character name for collation." ) ; } ele = Locale . element ( charName ) ; if ( ele == - 1 ) { throw new RegexException ( "Invalid character name " + charName ) ; } else { startc = ( char ) ele ; } break ; case ECLASS : charName = scanplain ( ) ; if ( charName . length ( ) == 0 ) { throw new RegexException ( "Unterminated or invalid equivalence class." ) ; } ele = Locale . element ( charName ) ; if ( ele == - 1 ) { throw new RegexException ( "Invalid character name " + charName ) ; } else { startc = ( char ) ele ; } set = Locale . eclass ( ( char ) startc , 0 != ( cflags & Flags . REG_ICASE ) ) ; dovec ( set , lp , rp ) ; return ; case CCLASS : String className = scanplain ( ) ; if ( className . length ( ) == 0 ) { throw new RegexException ( "Missing class name for char class." ) ; } set = Locale . cclass ( className , 0 != ( cflags & Flags . REG_ICASE ) ) ; dovec ( set , lp , rp ) ; return ; default : throw new RegexException ( "Impossible lexical state." ) ; } if ( see ( RANGE ) ) { lex . next ( ) ; switch ( nexttype ) { case PLAIN : case RANGE : c = nextvalue ; lex . next ( ) ; if ( c <= Character . MAX_VALUE && Character . isHighSurrogate ( ( char ) c ) ) { char low = ( char ) nextvalue ; lex . next ( ) ; endc = Character . toCodePoint ( ( char ) c , low ) ; } else { endc = c ; } break ; case COLLEL : String charName = scanplain ( ) ; if ( charName . length ( ) == 0 ) { throw new RegexException ( "Missing character name in collation." ) ; } // look up named character .
ele = Locale . element ( charName ) ; if ( ele == - 1 ) { throw new RegexException ( "Invalid character name " + charName ) ; } break ; default : throw new RegexException ( "Invalid syntax in range." ) ; } } else { endc = startc ; } set = new UnicodeSet ( startc , endc ) ; if ( 0 != ( cflags & Flags . REG_ICASE ) ) { set . closeOver ( UnicodeSet . ADD_CASE_MAPPINGS ) ; } dovec ( set , lp , rp ) ;


signature:
public class Compiler { /** * scanplain - scan PLAIN contents of [ . etc .
 * Certain bits of trickery in lex . c know that this code does not try
 * to look past the final bracket of the [ . etc .
 * @ return the string . It can ' t return a pos ; a nested pattern is popped by
 * the last lex . next ( ) in here and so the offsets don ' t work . */
private String scanplain ( ) throws RegexException { } }

implementation: int startp = now ; int endp ; assert see ( COLLEL ) || see ( ECLASS ) || see ( CCLASS ) ; lex . next ( ) ; endp = now ; while ( see ( PLAIN ) ) { endp = now ; lex . next ( ) ; } String ret = new String ( pattern , startp , endp - startp ) ; assert see ( END ) ; lex . next ( ) ; return ret ;


signature:
public class Compiler { /** * cbracket - handle complemented bracket expression
 * We do it by calling bracket ( ) with dummy endpoints , and then complementing
 * the result . The alternative would be to invoke rainbow ( ) , and then delete
 * arcs as the b . e . is seen . . . but that gets messy . */
private void cbracket ( State lp , State rp ) throws RegexException { } }

implementation:
State left = nfa . newstate ( ) ; State right = nfa . newstate ( ) ; bracket ( left , right ) ; if ( 0 != ( cflags & Flags . REG_NLSTOP ) ) { nfa . newarc ( PLAIN , nlcolor , left , right ) ; } assert lp . nouts == 0 ; /* all outarcs will be ours */
/* easy part of complementing */
cm . colorcomplement ( nfa , PLAIN , left , lp , rp ) ; // No MCCE in Java .
nfa . dropstate ( left ) ; assert right . nins == 0 ; nfa . freestate ( right ) ;


signature:
public class Compiler { /** * newlacon - allocate a lookahead - constraint subRE
 * @ return lacon number */
private int newlacon ( State begin , State end , int pos ) { } }

implementation:
if ( lacons . size ( ) == 0 ) { // skip 0
lacons . add ( null ) ; } Subre sub = new Subre ( ( char ) 0 , 0 , begin , end ) ; sub . subno = pos ; lacons . add ( sub ) ; return lacons . size ( ) - 1 ; // it ' s the index into the array , - 1.


signature:
public class Compiler { /** * onechr - fill in arcs for a plain character , and possible case complements
 * This is mostly a shortcut for efficient handling of the common case . */
private void onechr ( int c , State lp , State rp ) throws RegexException { } }

implementation:
if ( 0 == ( cflags & Flags . REG_ICASE ) ) { nfa . newarc ( PLAIN , cm . subcolor ( c ) , lp , rp ) ; return ; } /* rats , need general case anyway . . . */
dovec ( Locale . allcases ( c ) , lp , rp ) ;


signature:
public class Compiler { /** * dovec - fill in arcs for each element of a cvec
 * all kinds of MCCE complexity removed . */
private void dovec ( UnicodeSet set , State lp , State rp ) throws RegexException { } }

implementation:
int rangeCount = set . getRangeCount ( ) ; for ( int rx = 0 ; rx < rangeCount ; rx ++ ) { int rangeStart = set . getRangeStart ( rx ) ; int rangeEnd = set . getRangeEnd ( rx ) ; /* * Note : ICU operates in UTF - 32 here , and the ColorMap is happy to play along . */
if ( LOG . isDebugEnabled ( ) && IS_DEBUG ) { LOG . debug ( String . format ( "%s %d %4x %4x" , set , rx , rangeStart , rangeEnd ) ) ; } // TODO : this arc is probably redundant .
if ( rangeStart == rangeEnd ) { nfa . newarc ( PLAIN , cm . subcolor ( rangeStart ) , lp , rp ) ; } cm . subrange ( rangeStart , rangeEnd , lp , rp ) ; }


signature:
public class HsrePattern { /** * Compile a pattern .
 * @ param pattern the pattern .
 * @ param flags flags that determine the interpretation of the pattern .
 * @ return the compiled pattern .
 * @ throws RegexException */
public static RePattern compile ( String pattern , EnumSet < PatternFlags > flags ) throws RegexException { } }

implementation: return Compiler . compile ( pattern , flags ) ;


signature:
public class HsrePattern { /** * Compile a pattern .
 * @ param pattern the pattern .
 * @ param flags flags that determine the interpretation of the pattern .
 * @ return the compiled pattern .
 * @ throws RegexException */
public static RePattern compile ( String pattern , PatternFlags ... flags ) throws RegexException { } }

implementation: EnumSet < PatternFlags > flagSet = EnumSet . noneOf ( PatternFlags . class ) ; Collections . addAll ( flagSet , flags ) ; return Compiler . compile ( pattern , flagSet ) ;


signature:
public class State { /** * / * back chain */
Arc findarc ( int type , short co ) { } }

implementation: for ( Arc a = outs ; a != null ; a = a . outchain ) { if ( a . type == type && a . co == co ) { return a ; } } return null ;


signature:
public class ColorMap { /** * Retrieve the color for a character .
 * @ param c input char .
 * @ return output color . */
private short getcolor ( int c ) { } }

implementation: try { return map . get ( c ) ; } catch ( NullPointerException npe ) { throw new RegexRuntimeException ( String . format ( "Failed to map codepoint U+%08X." , c ) ) ; }


signature:
public class ColorMap { /** * pseudocolor - allocate a false color to be managed by other means .
 * @ return a color , otherwise unused . */
short pseudocolor ( ) { } }

implementation: short co = newcolor ( ) ; ColorDesc cd = colorDescs . get ( co ) ; cd . setNChars ( 1 ) ; cd . markPseudo ( ) ; return co ;


signature:
public class ColorMap { /** * subcolor - allocate a new subcolor ( if necessary ) to this char
 * Internal API that can do a range of characters ; called from
 * { @ link # subrange } .
 * @ param c The character , or first character in a range , to process .
 * @ param rangeCount the number of characters . */
private short subcolor ( int c , int rangeCount ) throws RegexException { } }

implementation:
short co ; /* current color of c */
short sco ; /* new subcolor */
co = getcolor ( c ) ; sco = newsub ( co ) ; assert sco != Constants . COLORLESS ; if ( co == sco ) /* already in an open subcolor */
{ return co ; /* rest is redundant */
} ColorDesc cd = colorDescs . get ( co ) ; cd . incrementNChars ( - rangeCount ) ; ColorDesc scd = colorDescs . get ( sco ) ; scd . incrementNChars ( rangeCount ) ; map . put ( Range . closedOpen ( c , c + rangeCount ) , sco ) ; return sco ;


signature:
public class ColorMap { /** * newsub - allocate a new subcolor ( if necessary ) for a color */
private short newsub ( short co ) throws RegexException { } }

implementation:
short sco ; // new subcolor .
ColorDesc cd = colorDescs . get ( co ) ; sco = colorDescs . get ( co ) . sub ; if ( sco == Constants . NOSUB ) { /* color has no open subcolor */
if ( cd . getNChars ( ) == 1 ) { /* optimization */
return co ; } sco = newcolor ( ) ; /* must create subcolor */
if ( sco == Constants . COLORLESS ) { throw new RegexException ( "Invalid color allocation" ) ; } ColorDesc subcd = colorDescs . get ( sco ) ; cd . sub = sco ; subcd . sub = sco ; /* open subcolor points to self */
} return sco ;


signature:
public class ColorMap { /** * subrange - allocate new subcolors to this range of chars , fill in arcs .
 * The range will overlap existing ranges ; even in the simplest case ,
 * it will overlap the initial WHITE range . For each existing range that
 * it overlaps , allocate a new color , mark the range as mapping to that color ,
 * and add an arc between the states for that color . */
void subrange ( int from , int to , State lp , State rp ) throws RegexException { } }

implementation:
/* Avoid one call to map . get ( ) for each character in the range .
 * This map will usually contain one item , but in complex cases more .
 * For example , if we had [ a - f ] [ g - h ] and then someone asked for [ f - g ] , there
 * would be two . Each of these new ranges will get a new color via subcolor . */
Map < Range < Integer > , Short > curColors = map . subRangeMap ( Range . closed ( from , to ) ) . asMapOfRanges ( ) ; /* * To avoid concurrent mod problems , we need to copy the ranges we are working from . */
List < Range < Integer > > ranges = Lists . newArrayList ( curColors . keySet ( ) ) ; for ( Range < Integer > rangeToProcess : ranges ) { // bound management here irritating .
int start = rangeToProcess . lowerEndpoint ( ) ; if ( rangeToProcess . lowerBoundType ( ) == BoundType . OPEN ) { start ++ ; } int end = rangeToProcess . upperEndpoint ( ) ; if ( rangeToProcess . upperBoundType ( ) == BoundType . CLOSED ) { end ++ ; } // allocate a new subcolor and account it owning the entire range .
short color = subcolor ( start , end - start ) ; compiler . getNfa ( ) . newarc ( Compiler . PLAIN , color , lp , rp ) ; }


signature:
public class ColorMap { /** * okcolors - promote subcolors to full colors */
void okcolors ( Nfa nfa ) { } }

implementation:
ColorDesc cd ; ColorDesc scd ; Arc a ; short sco ; for ( short co = 0 ; co < colorDescs . size ( ) ; co ++ ) { cd = colorDescs . get ( co ) ; if ( cd == null ) { continue ; // not in use at all , so can ' t have a subcolor .
} sco = cd . sub ; if ( sco == Constants . NOSUB ) { /* has no subcolor , no further action */
} else if ( sco == co ) { /* is subcolor , let parent deal with it */
} else if ( cd . getNChars ( ) == 0 ) { /* parent empty , its arcs change color to subcolor */
cd . sub = Constants . NOSUB ; scd = colorDescs . get ( sco ) ; assert scd . getNChars ( ) > 0 ; assert scd . sub == sco ; scd . sub = Constants . NOSUB ; while ( ( a = cd . arcs ) != null ) { assert a . co == co ; cd . arcs = a . colorchain ; a . setColor ( sco ) ; a . colorchain = scd . arcs ; scd . arcs = a ; } freecolor ( co ) ; } else { /* parent ' s arcs must gain parallel subcolor arcs */
cd . sub = Constants . NOSUB ; scd = colorDescs . get ( sco ) ; assert scd . getNChars ( ) > 0 ; assert scd . sub == sco ; scd . sub = Constants . NOSUB ; for ( a = cd . arcs ; a != null ; a = a . colorchain ) { assert a . co == co ; nfa . newarc ( a . type , sco , a . from , a . to ) ; } } }


signature:
public class ColorMap { /** * colorchain - add this arc to the color chain of its color */
void colorchain ( Arc a ) { } }

implementation: ColorDesc cd = colorDescs . get ( a . co ) ; a . colorchain = cd . arcs ; cd . arcs = a ;


signature:
public class ColorMap { /** * uncolorchain - delete this arc from the color chain of its color */
void uncolorchain ( Arc a ) { } }

implementation:
ColorDesc cd = colorDescs . get ( a . co ) ; Arc aa ; aa = cd . arcs ; if ( aa == a ) { /* easy case */
cd . arcs = a . colorchain ; } else { for ( ; aa != null && aa . colorchain != a ; aa = aa . colorchain ) { } assert aa != null ; aa . colorchain = a . colorchain ; } a . colorchain = null ; /* paranoia */


signature:
public class ColorMap { /** * rainbow - add arcs of all full colors ( but one ) between specified states
 * @ param but is COLORLESS if no exceptions */
void rainbow ( Nfa nfa , int type , short but , State from , State to ) { } }

implementation: ColorDesc cd ; short co ; for ( co = 0 ; co < colorDescs . size ( ) ; co ++ ) { cd = colorDescs . get ( co ) ; if ( cd != null && cd . sub != co && co != but && ! cd . pseudo ( ) ) { nfa . newarc ( type , co , from , to ) ; } }


signature:
public class ColorMap { /** * colorcomplement - add arcs of complementary colors
 * The calling sequence ought to be reconciled with cloneouts ( ) .
 * @ param of complements of this guy ' s PLAIN outarcs */
void colorcomplement ( Nfa nfa , int type , State of , State from , State to ) { } }

implementation: ColorDesc cd ; short co ; assert of != from ; for ( co = 0 ; co < colorDescs . size ( ) ; co ++ ) { cd = colorDescs . get ( co ) ; if ( cd != null && ! cd . pseudo ( ) ) { if ( of . findarc ( Compiler . PLAIN , co ) == null ) { nfa . newarc ( type , co , from , to ) ; } } }


signature:
public class ColorMap { /** * dumpcolors - debugging output */
void dumpcolors ( ) { } }

implementation:
/* * we want to organize this by colors . */
for ( int co = 0 ; co < colorDescs . size ( ) ; co ++ ) { ColorDesc cd = colorDescs . get ( co ) ; if ( cd != null ) { dumpcolor ( co , cd ) ; } }


signature:
public class ColorMap { /** * Not speedy . This is for debugging . */
private void dumpcolor ( int co , ColorDesc cd ) { } }

implementation: StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw ) ; pw . format ( "Color %d - %d chars %s\n" , co , cd . getNChars ( ) , cd . pseudo ( ) ? " (pseudo)" : "" ) ; for ( Map . Entry < Range < Integer > , Short > me : map . asMapOfRanges ( ) . entrySet ( ) ) { if ( me . getValue ( ) == co ) { pw . format ( " %s %s\n" , me . getKey ( ) , UCharacter . getExtendedName ( me . getKey ( ) . lowerEndpoint ( ) ) ) ; } } pw . flush ( ) ; String r = sw . toString ( ) ; System . out . println ( r ) ;


signature:
public class Lex { /** * lexstart - set up lexical stuff , scan leading options */
void lexstart ( ) throws RegexException { } }

implementation:
prefixes ( ) ; /* may turn on new type bits etc . */
if ( 0 != ( v . cflags & Flags . REG_QUOTE ) ) { assert 0 == ( v . cflags & ( Flags . REG_ADVANCED | Flags . REG_EXPANDED | Flags . REG_NEWLINE ) ) ; intocon ( L_Q ) ; } else if ( 0 != ( v . cflags & Flags . REG_EXTENDED ) ) { assert 0 == ( v . cflags & Flags . REG_QUOTE ) ; intocon ( L_ERE ) ; } else { assert 0 == ( v . cflags & ( Flags . REG_QUOTE | Flags . REG_ADVF ) ) ; intocon ( L_BRE ) ; } v . nexttype = Compiler . EMPTY ; /* remember we were at the start */
next ( ) ; /* set up the first token */


signature:
public class Lex { /** * prefixes - implement various special prefixes */
void prefixes ( ) throws RegexException { } }

implementation:
/* literal string doesn ' t get any of this stuff */
if ( 0 != ( v . cflags & Flags . REG_QUOTE ) ) { return ; } /* initial " * * * " gets special things */
if ( have ( 4 ) && next3 ( '*' , '*' , '*' ) ) { switch ( charAtNowPlus ( 3 ) ) { case '?' : /* " * * * ? " error , msg shows version */
throw new RegexException ( "REG_BADPAT" ) ; case '=' : /* " * * * = " shifts to literal string */
v . note ( Flags . REG_UNONPOSIX ) ; v . cflags |= Flags . REG_QUOTE ; v . cflags &= ~ ( Flags . REG_ADVANCED | Flags . REG_EXPANDED | Flags . REG_NEWLINE ) ; v . now += 4 ; return ; /* and there can be no more prefixes */
case ':' : /* " * * * : " shifts to AREs */
v . note ( Flags . REG_UNONPOSIX ) ; v . cflags |= Flags . REG_ADVANCED ; v . now += 4 ; break ; default : /* otherwise * * * is just an error */
throw new RegexException ( "REG_BADRPT" ) ; } } /* BREs and EREs don ' t get embedded options */
if ( ( v . cflags & Flags . REG_ADVANCED ) != Flags . REG_ADVANCED ) { return ; } /* embedded options ( AREs only ) */
if ( have ( 3 ) && next2 ( '(' , '?' ) && iscalpha ( charAtNowPlus ( 2 ) ) ) { v . note ( Flags . REG_UNONPOSIX ) ; v . now += 2 ; for ( ; ! ateos ( ) && iscalpha ( charAtNow ( ) ) ; v . now ++ ) { switch ( charAtNow ( ) ) { case 'b' : /* BREs ( but why ? ? ? ) */
v . cflags &= ~ ( Flags . REG_ADVANCED | Flags . REG_QUOTE ) ; break ; case 'c' : /* case sensitive */
v . cflags &= ~ Flags . REG_ICASE ; break ; case 'e' : /* plain EREs */
v . cflags |= Flags . REG_EXTENDED ; v . cflags &= ~ ( Flags . REG_ADVF | Flags . REG_QUOTE ) ; break ; case 'i' : /* case insensitive */
v . cflags |= Flags . REG_ICASE ; break ; case 'm' : /* Perloid synonym for n */
case 'n' : /* \ n affects ^ $ . [ ^ */
v . cflags |= Flags . REG_NEWLINE ; break ; case 'p' : /* ~ Perl , \ n affects . [ ^ */
v . cflags |= Flags . REG_NLSTOP ; v . cflags &= ~ Flags . REG_NLANCH ; break ; case 'q' : /* literal string */
v . cflags |= Flags . REG_QUOTE ; v . cflags &= ~ Flags . REG_ADVANCED ; break ; case 's' : /* single line , \ n ordinary */
v . cflags &= ~ Flags . REG_NEWLINE ; break ; case 't' : /* tight syntax */
v . cflags &= ~ Flags . REG_EXPANDED ; break ; case 'w' : /* weird , \ n affects ^ $ only */
v . cflags &= ~ Flags . REG_NLSTOP ; v . cflags |= Flags . REG_NLANCH ; break ; case 'x' : /* expanded syntax */
v . cflags |= Flags . REG_EXPANDED ; break ; default : throw new RegexException ( "REG_BADOPT" ) ; } } if ( ! next1 ( ')' ) ) { throw new RegexException ( "REG_BADOPT" ) ; } v . now ++ ; if ( 0 != ( v . cflags & Flags . REG_QUOTE ) ) { v . cflags &= ~ ( Flags . REG_EXPANDED | Flags . REG_NEWLINE ) ; } }


signature:
public class Lex { /** * lexnest - " call a subroutine " , interpolating string at the lexical level
 * Note , this is not a very general facility . There are a number of
 * implicit assumptions about what sorts of strings can be subroutines . */
void lexnest ( char [ ] interpolated ) { } }

implementation:
assert v . savepattern == null ; /* only one level of nesting */
v . savepattern = v . pattern ; v . savenow = v . now ; v . savestop = v . stop ; v . savenow = v . now ; v . pattern = interpolated ; v . now = 0 ; v . stop = v . pattern . length ;


signature:
public class Lex { /** * next - get next token */
boolean next ( ) throws RegexException { } }

implementation:
char c ; /* remember flavor of last token */
v . lasttype = v . nexttype ; /* REG _ BOSONLY */
if ( v . nexttype == Compiler . EMPTY && ( 0 != ( v . cflags & Flags . REG_BOSONLY ) ) ) { /* at start of a REG _ BOSONLY RE */
return retv ( Compiler . SBEGIN , ( char ) 0 ) ; /* same as \ A */
} /* if we ' re nested and we ' ve hit end , return to outer level */
if ( v . savepattern != null && ateos ( ) ) { v . now = v . savenow ; v . stop = v . savestop ; v . savenow = - 1 ; v . savestop = - 1 ; v . pattern = v . savepattern ; v . savepattern = null ; // mark that it ' s not saved .
} /* skip white space etc . if appropriate ( not in literal or [ ] ) */
if ( 0 != ( v . cflags & Flags . REG_EXPANDED ) ) { switch ( v . lexcon ) { case L_ERE : case L_BRE : case L_EBND : case L_BBND : skip ( ) ; break ; } } /* handle EOS , depending on context */
if ( ateos ( ) ) { switch ( v . lexcon ) { case L_ERE : case L_BRE : case L_Q : return ret ( Compiler . EOS ) ; case L_EBND : case L_BBND : throw new RegexException ( "Unbalanced braces." ) ; case L_BRACK : case L_CEL : case L_ECL : case L_CCL : throw new RegexException ( "Unbalanced brackets." ) ; } assert false ; } /* okay , time to actually get a character */
c = charAtNowAdvance ( ) ; /* deal with the easy contexts , punt EREs to code below */
switch ( v . lexcon ) { case L_BRE : /* punt BREs to separate function */
return brenext ( c ) ; case L_ERE : /* see below */
break ; case L_Q : /* literal strings are easy */
return retv ( Compiler . PLAIN , c ) ; case L_BBND : /* bounds are fairly simple */
case L_EBND : switch ( c ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : return retv ( Compiler . DIGIT , digitval ( c ) ) ; case ',' : return ret ( ',' ) ; case '}' : /* ERE bound ends with } */
if ( incon ( L_EBND ) ) { intocon ( L_ERE ) ; if ( 0 != ( v . cflags & Flags . REG_ADVF ) && next1 ( '?' ) ) { v . now ++ ; note ( Flags . REG_UNONPOSIX ) ; return retv ( '}' , 0 ) ; } return retv ( '}' , 1 ) ; } else { throw new RegexException ( "Errors.REG_BADBR" ) ; } case '\\' : /* BRE bound ends with \ } */
if ( incon ( L_BBND ) && next1 ( '}' ) ) { v . now ++ ; intocon ( L_BRE ) ; return ret ( '}' ) ; } else { throw new RegexException ( "Errors.REG_BADBR" ) ; } default : throw new RegexException ( "Errors.REG_BADBR" ) ; } case L_BRACK : /* brackets are not too hard */
switch ( c ) { case ']' : if ( lasttype ( '[' ) ) { return retv ( Compiler . PLAIN , c ) ; } else { intocon ( 0 != ( v . cflags & Flags . REG_EXTENDED ) ? L_ERE : L_BRE ) ; return ret ( ']' ) ; } case '\\' : note ( Flags . REG_UBBS ) ; if ( 0 == ( v . cflags & Flags . REG_ADVF ) ) { return retv ( Compiler . PLAIN , c ) ; } note ( Flags . REG_UNONPOSIX ) ; if ( ateos ( ) ) { throw new RegexException ( "REG_EESCAPE" ) ; } lexescape ( ) ; switch ( v . nexttype ) { /* not all escapes okay here */
case Compiler . PLAIN : return true ; case Compiler . CCLASS : switch ( v . nextvalue ) { case 'd' : lexnest ( brbackd ) ; break ; case 's' : lexnest ( brbacks ) ; break ; case 'w' : lexnest ( brbackw ) ; break ; default : throw new RegexException ( "Errors.REG_EESCAPE" ) ; } /* lexnest done , back up and try again */
v . nexttype = v . lasttype ; return next ( ) ; } /* not one of the acceptable escapes */
throw new RegexException ( "Errors.REG_EESCAPE" ) ; case '-' : if ( lasttype ( '[' ) || next1 ( ']' ) ) { return retv ( Compiler . PLAIN , c ) ; } else { return retv ( Compiler . RANGE , c ) ; } case '[' : if ( ateos ( ) ) { throw new RegexException ( "Errors.REG_EBRACK" ) ; } switch ( charAtNowAdvance ( ) ) { case '.' : intocon ( L_CEL ) ; /* might or might not be locale - specific */
return ret ( Compiler . COLLEL ) ; case '=' : intocon ( L_ECL ) ; note ( Flags . REG_ULOCALE ) ; return ret ( Compiler . ECLASS ) ; case ':' : intocon ( L_CCL ) ; note ( Flags . REG_ULOCALE ) ; return ret ( Compiler . CCLASS ) ; default : /* oops */
v . now -- ; return retv ( Compiler . PLAIN , c ) ; } default : return retv ( Compiler . PLAIN , c ) ; } case L_CEL : /* collating elements are easy */
if ( c == '.' && next1 ( ']' ) ) { v . now ++ ; intocon ( L_BRACK ) ; return retv ( Compiler . END , '.' ) ; } else { return retv ( Compiler . PLAIN , c ) ; } case L_ECL : /* ditto equivalence classes */
if ( c == '=' && next1 ( ']' ) ) { v . now ++ ; intocon ( L_BRACK ) ; return retv ( Compiler . END , '=' ) ; } else { return retv ( Compiler . PLAIN , c ) ; } case L_CCL : /* ditto character classes */
if ( c == ':' && next1 ( ']' ) ) { v . now ++ ; intocon ( L_BRACK ) ; return retv ( Compiler . END , ':' ) ; } else { return retv ( Compiler . PLAIN , c ) ; } default : assert false ; break ; } /* that got rid of everything except EREs and AREs */
assert incon ( L_ERE ) ; /* deal with EREs and AREs , except for backslashes */
switch ( c ) { case '|' : return ret ( '|' ) ; case '*' : if ( 0 != ( v . cflags & Flags . REG_ADVF ) && next1 ( '?' ) ) { v . now ++ ; note ( Flags . REG_UNONPOSIX ) ; return retv ( '*' , 0 ) ; } return retv ( '*' , 1 ) ; case '+' : if ( 0 != ( v . cflags & Flags . REG_ADVF ) && next1 ( '?' ) ) { v . now ++ ; note ( Flags . REG_UNONPOSIX ) ; return retv ( '+' , 0 ) ; } return retv ( '+' , 1 ) ; case '?' : if ( 0 != ( v . cflags & Flags . REG_ADVF ) && next1 ( '?' ) ) { v . now ++ ; note ( Flags . REG_UNONPOSIX ) ; return retv ( '?' , 0 ) ; } return retv ( '?' , 1 ) ; case '{' : /* bounds start or plain character */
if ( 0 != ( v . cflags & Flags . REG_EXPANDED ) ) { skip ( ) ; } if ( ateos ( ) || ! iscdigit ( charAtNow ( ) ) ) { note ( Flags . REG_UBRACES ) ; note ( Flags . REG_UUNSPEC ) ; return retv ( Compiler . PLAIN , c ) ; } else { note ( Flags . REG_UBOUNDS ) ; intocon ( L_EBND ) ; return ret ( '{' ) ; } case '(' : /* parenthesis , or advanced extension */
if ( 0 != ( v . cflags & Flags . REG_ADVF ) && next1 ( '?' ) ) { note ( Flags . REG_UNONPOSIX ) ; v . now ++ ; char flagChar = charAtNowAdvance ( ) ; switch ( flagChar ) { case ':' : /* non - capturing paren */
return retv ( '(' , 0 ) ; case '#' : /* comment */
while ( ! ateos ( ) && charAtNow ( ) != ')' ) { v . now ++ ; } if ( ! ateos ( ) ) { v . now ++ ; } assert v . nexttype == v . lasttype ; return next ( ) ; case '=' : /* positive lookahead */
note ( Flags . REG_ULOOKAHEAD ) ; return retv ( Compiler . LACON , 1 ) ; case '!' : /* negative lookahead */
note ( Flags . REG_ULOOKAHEAD ) ; return retv ( Compiler . LACON , 0 ) ; default : throw new RegexException ( String . format ( "Invalid flag after '(?': %c" , flagChar ) ) ; } } if ( 0 != ( v . cflags & Flags . REG_NOSUB ) || 0 != ( v . cflags & Flags . REG_NOCAPT ) ) { return retv ( '(' , 0 ) ; /* all parens non - capturing */
} else { return retv ( '(' , 1 ) ; } case ')' : if ( lasttype ( '(' ) ) { note ( Flags . REG_UUNSPEC ) ; } return retv ( ')' , c ) ; case '[' : /* easy except for [ [ : < : ] ] and [ [ : > : ] ] */
if ( have ( 6 ) && charAtNow ( ) == '[' && charAtNowPlus ( 1 ) == ':' && ( charAtNowPlus ( 2 ) == '<' || charAtNowPlus ( 2 ) == '>' ) && charAtNowPlus ( 3 ) == ':' && charAtNowPlus ( 4 ) == ']' && charAtNowPlus ( 5 ) == ']' ) { c = charAtNowPlus ( 2 ) ; v . now += 6 ; note ( Flags . REG_UNONPOSIX ) ; return ret ( ( c == '<' ) ? '<' : '>' ) ; } intocon ( L_BRACK ) ; if ( next1 ( '^' ) ) { v . now ++ ; return retv ( '[' , 0 ) ; } return retv ( '[' , 1 ) ; case '.' : return ret ( '.' ) ; case '^' : return ret ( '^' ) ; case '$' : return ret ( '$' ) ; case '\\' : /* mostly punt backslashes to code below */
if ( ateos ( ) ) { throw new RegexException ( "REG_EESCAPE" ) ; } break ; default : /* ordinary character */
return retv ( Compiler . PLAIN , c ) ; } /* ERE / ARE backslash handling ; backslash already eaten */
assert ! ateos ( ) ; if ( 0 == ( v . cflags & Flags . REG_ADVF ) ) { /* only AREs have non - trivial escapes */
if ( iscalnum ( charAtNow ( ) ) ) { note ( Flags . REG_UBSALNUM ) ; note ( Flags . REG_UUNSPEC ) ; } return retv ( Compiler . PLAIN , charAtNowAdvance ( ) ) ; } lexescape ( ) ; if ( v . nexttype == Compiler . CCLASS ) { /* fudge at lexical level */
switch ( v . nextvalue ) { case 'd' : lexnest ( backd ) ; break ; case 'D' : lexnest ( backD ) ; break ; case 's' : lexnest ( backs ) ; break ; case 'S' : lexnest ( backS ) ; break ; case 'w' : lexnest ( backw ) ; break ; case 'W' : lexnest ( backW ) ; break ; default : throw new RuntimeException ( "Invalid escape " + Character . toString ( ( char ) v . nextvalue ) ) ; } /* lexnest done , back up and try again */
v . nexttype = v . lasttype ; return next ( ) ; } /* otherwise , lexescape has already done the work */
return true ;


signature:
public class Lex { /** * brenext - get next BRE token
 * This is much like EREs except for all the stupid backslashes and the */
boolean brenext ( char pc ) throws RegexException { } }

implementation:
char c = pc ; switch ( c ) { case '*' : if ( lasttype ( Compiler . EMPTY ) || lasttype ( '(' ) || lasttype ( '^' ) ) { return retv ( Compiler . PLAIN , c ) ; } return ret ( '*' ) ; case '[' : // CHECKSTYLE : OFF
if ( have ( 6 ) && charAtNow ( ) == '[' && charAtNowPlus ( 1 ) == ':' && ( charAtNowPlus ( 2 ) == '<' || charAtNowPlus ( 2 ) == '>' ) && charAtNowPlus ( 3 ) == ':' && charAtNowPlus ( 4 ) == ']' && charAtNowPlus ( 5 ) == ']' ) { c = charAtNowPlus ( 2 ) ; v . now += 6 ; note ( Flags . REG_UNONPOSIX ) ; return ret ( ( c == '<' ) ? '<' : '>' ) ; // CHECKSTYLE : ON
} intocon ( L_BRACK ) ; if ( next1 ( '^' ) ) { v . now ++ ; return retv ( '[' , 0 ) ; } return retv ( '[' , 1 ) ; case '.' : return ret ( '.' ) ; case '^' : if ( lasttype ( Compiler . EMPTY ) ) { return ret ( '^' ) ; } if ( lasttype ( '(' ) ) { note ( Flags . REG_UUNSPEC ) ; return ret ( '^' ) ; } return retv ( Compiler . PLAIN , c ) ; case '$' : if ( 0 != ( v . cflags & Flags . REG_EXPANDED ) ) { skip ( ) ; } if ( ateos ( ) ) { return ret ( '$' ) ; } if ( next2 ( '\\' , ')' ) ) { note ( Flags . REG_UUNSPEC ) ; return ret ( '$' ) ; } return retv ( Compiler . PLAIN , c ) ; case '\\' : break ; /* see below */
default : return retv ( Compiler . PLAIN , c ) ; } assert c == '\\' ; if ( ateos ( ) ) { throw new RegexException ( "REG_EESCAPE" ) ; } c = charAtNowAdvance ( ) ; switch ( c ) { case '{' : intocon ( L_BBND ) ; note ( Flags . REG_UBOUNDS ) ; return ret ( '{' ) ; case '(' : return retv ( '(' , 1 ) ; case ')' : return retv ( ')' , c ) ; case '<' : note ( Flags . REG_UNONPOSIX ) ; return ret ( '<' ) ; case '>' : note ( Flags . REG_UNONPOSIX ) ; return ret ( '>' ) ; case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : note ( Flags . REG_UBACKREF ) ; return retv ( Compiler . BACKREF , digitval ( c ) ) ; default : if ( iscalnum ( c ) ) { note ( Flags . REG_UBSALNUM ) ; note ( Flags . REG_UUNSPEC ) ; } return retv ( Compiler . PLAIN , c ) ; }


signature:
public class Lex { /** * CHECKSTYLE : OFF */
boolean lexescape ( ) throws RegexException { } }

implementation:
int c ; int save ; assert 0 != ( v . cflags & Flags . REG_ADVF ) ; assert ! ateos ( ) ; c = charAtNowAdvance ( ) ; if ( ! iscalnum ( ( char ) c ) ) { return retv ( Compiler . PLAIN , c ) ; } note ( Flags . REG_UNONPOSIX ) ; switch ( c ) { case 'a' : return retv ( Compiler . PLAIN , '\007' ) ; case 'A' : return retv ( Compiler . SBEGIN , 0 ) ; case 'b' : return retv ( Compiler . PLAIN , '\b' ) ; case 'B' : return retv ( Compiler . PLAIN , '\\' ) ; case 'c' : if ( ateos ( ) ) { throw new RegexException ( "Incomplete \\c escape." ) ; } return retv ( Compiler . PLAIN , ( char ) ( charAtNowAdvance ( ) & 037 ) ) ; case 'd' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . CCLASS , 'd' ) ; case 'D' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . CCLASS , 'D' ) ; case 'e' : return retv ( Compiler . PLAIN , '\033' ) ; case 'f' : return retv ( Compiler . PLAIN , '\f' ) ; case 'm' : return ret ( '<' ) ; case 'M' : return ret ( '>' ) ; case 'n' : return retv ( Compiler . PLAIN , '\n' ) ; case 'r' : return retv ( Compiler . PLAIN , '\r' ) ; case 's' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . CCLASS , 's' ) ; case 'S' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . CCLASS , 'S' ) ; case 't' : return retv ( Compiler . PLAIN , '\t' ) ; case 'u' : c = lexdigits ( 16 , 4 , 4 ) ; return retv ( Compiler . PLAIN , c ) ; case 'U' : c = lexdigits ( 16 , 8 , 8 ) ; // This escape is for UTF - 32 characters . There are , ahem , certain requirements .
if ( c > Character . MAX_CODE_POINT ) { throw new RegexException ( "Invalid UTF-32 escape." ) ; } return retv ( Compiler . PLAIN , c ) ; case 'v' : return retv ( Compiler . PLAIN , '\u000b' ) ; case 'w' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . CCLASS , 'w' ) ; case 'W' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . CCLASS , 'W' ) ; case 'x' : c = lexdigits ( 16 , 1 , 255 ) ; /* REs > 255 long outside spec */
return retv ( Compiler . PLAIN , c ) ; case 'y' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . WBDRY , 0 ) ; case 'Y' : note ( Flags . REG_ULOCALE ) ; return retv ( Compiler . NWBDRY , 0 ) ; case 'Z' : return retv ( Compiler . SEND , 0 ) ; case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : save = v . now ; v . now -- ; /* put first digit back */
c = lexdigits ( 10 , 1 , 255 ) ; /* REs > 255 long outside spec */
/* ugly heuristic ( first test is " exactly 1 digit ? " ) */
if ( v . now - save == 0 || c <= v . getSubs ( ) . size ( ) ) { note ( Flags . REG_UBACKREF ) ; return retv ( Compiler . BACKREF , ( char ) c ) ; } /* oops , doesn ' t look like it ' s a backref after all . . . */
v . now = save ; /* and fall through into octal number */
case '0' : v . now -- ; /* put first digit back */
c = lexdigits ( 8 , 1 , 3 ) ; return retv ( Compiler . PLAIN , c ) ; default : throw new RegexException ( "Invalid escape" ) ; // unknown escape .
}


signature:
public class Lex { /** * / * chr value ; errors signalled via ERR */
private int lexdigits ( int base , int minlen , int maxlen ) throws RegexException { } }

implementation:
int n ; /* unsigned to avoid overflow misbehavior */
int len ; int c ; int d ; final char ub = ( char ) base ; n = 0 ; for ( len = 0 ; len < maxlen && ! ateos ( ) ; len ++ ) { c = charAtNowAdvance ( ) ; switch ( c ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : d = digitval ( ( char ) c ) ; break ; case 'a' : case 'A' : d = 10 ; break ; case 'b' : case 'B' : d = 11 ; break ; case 'c' : case 'C' : d = 12 ; break ; case 'd' : case 'D' : d = 13 ; break ; case 'e' : case 'E' : d = 14 ; break ; case 'f' : case 'F' : d = 15 ; break ; default : v . now -- ; /* oops , not a digit at all */
d = - 1 ; break ; } if ( d >= base ) { /* not a plausible digit */
v . now -- ; d = - 1 ; } if ( d < 0 ) { break ; /* NOTE BREAK OUT */
} n = n * ub + d ; } if ( len < minlen ) { throw new RegexException ( "Not enough digits." ) ; } return n ;


signature:
public class RuntimeColorMap { /** * Retrieve the color for a full codepoint .
 * @ param codepoint
 * @ return */
short getcolor ( int codepoint ) { } }

implementation: try { return fullMap . get ( codepoint ) ; } catch ( NullPointerException npe ) { throw new RuntimeException ( String . format ( " CP %08x no mapping" , codepoint ) ) ; }


signature:
public class Dfa { /** * Called at the start of a match .
 * arguably we could just construct a new DFA each time . */
StateSet initialize ( int start ) { } }

implementation:
// Discard state sets ; reuse would be faster if we kept them ,
// but then we ' d need the real cache .
stateSets . clear ( ) ; StateSet stateSet = new StateSet ( nstates , ncolors ) ; stateSet . states . set ( cnfa . pre ) ; stateSet . noprogress = true ; // Insert into hash table based on that one state .
stateSets . put ( stateSet . states , stateSet ) ; stateSet . setLastSeen ( start ) ; return stateSet ;