You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Features needed

  • Supports matching against binary data (not just character data)
  • Implements POSIX longest leftmost match algorithm
  • Uses non-backtracking algorithm to avoid exponential worst-time behavior

Survey of Java regular expression libraries

LibraryAlgorithmPOSIX longest leftmost matchLicenseURL
java.util.regexBacktrackingNoJava (included as part of Java)
Jakarta OROBacktrackingNoApachehttp://jakarta.apache.org/oro/
Jakarta RegexBacktrackingNoApachehttp://jakarta.apache.org/regexp/
com.stevesoft.patBacktrackingUnknownLGPLhttp://www.javaregex.com/home.html
dk.brics.automatonDFAUnknownBSDhttp://www.brics.dk/automaton/index.html
JRegexBacktrackingUnknownBSDhttp://jregex.sourceforge.net/

Of these, the automaton library looks the most interesting from a DFA perspective.

No POSIX longest match regex library for java/scala (as far as we can tell)

Notes for implementing our own regular expression engine

Miscellaneous notes:

java scanner - takes Readable as input (good), doesn't allow regex that matches at beginning of stream.


Implement longest match by rotating through mulitiple regex matchers, which determine if the pattern matches immediately at the beginning of the supplied characters.

Java regex Matcher class takes only CharSequence as input.

CharSequence is finite (has length() method) which precludes (most likely) creating a virtualized stream-like behavior underneath our own CharSequence implementation.

---------------------

Scala ||| combinator of regex parsers produces longest match to the combined regex's.

Scala combinator parsers read from a Reader.

The reader can virtualize the character stream up until a decode error, or size limit of our choice, and can hide all details of when additional blocks of data must be retrieved.

val rdr = new InputStreamReader(Channels.newInputStream(rbc : ReadableByteChannel)

// Must figure out what happens if character decoding gets an error.
// Worst case, we have to implement Reader interface ourselves with code that calls the decoder.

// length limit on delimiter match could be implemented by creating a finites substream from the rbc, instead of just handing the original rbc to it.

val pr = Parser.parse(rdr)

  • No labels