1

I have a simple Go library (~300 lines, mostly type declarations and nice methods and compatibility methods for gomobile etc., also pretty-printing scripts). The heart of the whole project are two regexes, placed in a separate file in my Go repository.

Now I want to port that simple library to Python, Java (Android), maybe Javascript. I want the regexes to rest in a single Git repository (maybe even the Golang one).

What is the best way to include the regexes at compile/build time as string constants? In case of Golang, it seems that the only way is to use go generate, which generates source code files and could include those regexes from a plain text file. So I decided to make a separate Go source code file for easy parsing by other build tools in case of Python, Java, Javascript. I would appreciate any advice how to do it efficiently that way. I could also make a separate repository for two regexes and use git submodules (or even treat it as a sepratate Go package in Go project).

But I've lost my hope for a pretty solution, and that's why I'm asking here and not on SO; how do you solve such problems? The simplest way would be to manually "cherry-pick" commits from each repository, setting author field manually.

  • Submodule is a quite universal way to get it done and good in practice. Also it allows for selective updating of every repository and testing updates in the regex before releasing. – Luc Franken Jul 26 '16 at 20:05
  • @LucFranken Yeah, but a separate repository for two ~200 characters long lines? – Michał Krzysztof Feiler Jul 26 '16 at 20:13
  • Your question is unclear (to me at least). Are you porting a Go project to Python, or are you using Python and Go code in a single project? – gardenhead Jul 27 '16 at 1:39
  • 1
    Regex syntax isn't necessarily the same in all languages. (Or even between regex libraries in the same language.) – Kevin Krumwiede Jul 27 '16 at 4:58
  • @KevinKrumwiede I am using re2. – Michał Krzysztof Feiler Jul 27 '16 at 7:59
1

It is a simple solution, but you could always put the regexes into a properties file, and then have the various code bases load their regexes as text values and compile them at runtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.