hyperpape / needle

Compiling string matching algorithms and regular expressions to java bytecode
MIT License
56 stars 2 forks source link

Support precompilation #3

Open hyperpape opened 4 years ago

hyperpape commented 4 years ago

Users might want to create subclasses of Pattern at build-time, not run-time. A solution could be more or less involved (these aren’t mutually exclusive):

  1. A method to compile a regex and write it to a .class file.
  2. Methods to compile one or more regexes and package as a jar.
  3. A maven plug-in to create classes/jars.
  4. Use annotations to define classes that should be created.

3 & 4 are probably overkill.

hyperpape commented 3 years ago

I don't know why I wrote that 3 & 4 seemed like overkill. They seem worthwhile.

Riduidel commented 6 months ago

I've juste discovered your project and find it incredible. I have no time, yet, but I would gladly try to help you about this subject (I have some experience in writing maven plugin that read Java code - using as an example JavaParser libray for direct source access)

hyperpape commented 6 months ago

Cool! I haven't spent much time actively thinking about this since I created the initial issue, and I must admit, on second thought, I can't 100% reconstruct what I was thinking with (4).

Writing an annotation that describes a regex is straightforward enough. You'd have to provide the regex string, the classname and the package. But what would the annotation be applied to? I guess it could be a class level annotation?

As for (3) I don't really have a feel for how code-generation plugins are typically used. I know Immutables has a thing where you have to run the plugin for the first time on compiling a project, but I haven't looked into how that's achieved.