polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Why I don't like regular expressions...
Date Wed, 05 Jul 2017 07:26:43 GMT
We have

private static final Pattern DESCRIPTOR_TEXTUAL_REGEXP = Pattern.compile(
    "^"
    + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_START ) + "(.*)"
    + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_END )
    + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_START ) + "(.*)"
    + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_END )
    + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_START ) + "(" + "[^"
    + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_END +
DESCRIPTOR_TYPE_SEPARATOR )
    + "]+)" + Pattern.quote( DESCRIPTOR_COMPONENT_SEPARATOR_END ) + "$" );


in org.apache.polygene.index.sql.support.skeletons.AbstractSQLStartup

And in method stringToCompositeDescriptor()

Matcher matcher = DESCRIPTOR_TEXTUAL_REGEXP.matcher( str );
if( !matcher.matches() )
{
    throw new IllegalArgumentException( "Descriptor textual description " + str
                                        + " was invalid." );
}

and of course it says that it doesn't match with

{Domain Layer}{Organization Module}{interface
com.sensetif.sink.model.organization.CreditLimit,interface
org.apache.polygene.api.value.ValueComposite}


so where is the problem?


The RegExp "Pattern" prints out to

^\Q{\E(.*)\Q}\E\Q{\E(.*)\Q}\E\Q{\E([^\Q},\E]+)\Q}\E$

as if that helps...

So I realize that the \Q and \E are escaping markers, so it is basically
saying

^{(.*)}{(.*)}{([^},]+)}$

(where comma and curlies being ordinary characters)

But the third group shouldn't work at all...

* ([^},]+)*

So, that is a group of one or more characters but not comma and not end
brace...


Has this ever worked? Because a few lines later, the sequence of types are
being extracted, so it was intended to have multiple types.


I am at loss.


Cheers
-- 
Niclas Hedhman, Software Developer
http://polygene.apache.org - New Energy for Java

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message