Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better to use macros #5

Open
PallHaraldsson opened this issue Aug 31, 2020 · 8 comments
Open

Better to use macros #5

PallHaraldsson opened this issue Aug 31, 2020 · 8 comments

Comments

@PallHaraldsson
Copy link

PallHaraldsson commented Aug 31, 2020

[Hi, I happened to be reading your abbreviations thread.]

I'm partial to this idea, but just as regexes in Julia are implemented by macros, I think this would also need to to be (as) fast.

Because of your package I looked more into Regexes, and discovered, the options i, s, m and more you can add after, see in docs:

julia> @edit r""ism

I think with your package would be missing.

@bramtayl
Copy link
Owner

I'm not quite sure what you mean, so let me know this is the answer to the wrong question:

In terms of performance, there's definitely an issue that this code allocates a whole bunch of unnecessary strings. I think this could be avoided using a similar strategy to @printf in Base. Is constructing regular expressions ever a performance bottleneck?

@bramtayl
Copy link
Owner

In terms of options, I think those are all implemented.

julia> show(OPTIONS)
(caseless = "i", duplicate_names = "J", multi_line = "m", no_auto_capture = "n", single_line = "s", lazy = "U", ignore_space = "x", ignore_all_space = "xx", unset = "^", recur = "R", callout = "C")

@PallHaraldsson
Copy link
Author

It might not be to just construct them. My guess is that people would use your idea even in a loop, so I'm not sure if they would generate the same string in each iteration. Ok, let's say the compiler is good and realizes it always returns the same string (or you generate it outside of the loop, I'm still not sure if enough as by generating it at runtime, I'm not sure he macros you usually use for regexes are effective.

The macros in Julia mean, I think, that the regex is made at parse time, and my recollection is it can be important/faster, similar to @printf.

@bramtayl
Copy link
Owner

bramtayl commented Aug 31, 2020

I do think that it is a good idea to do something similar to @printf to avoid allocations. It's not a priority for me; I think almost every time I've used this package I do it just once at the start of the file.

const VERY_COMPLICATED_REGEX = ...

But I'll probably get around to it eventually, and I'm also very happy to review a pull request. I haven't looked too closely but maybe @jkrumbiegel has implemented this for ReadableRegex.jl?

@PallHaraldsson
Copy link
Author

Yes, it has "@compile macro for lower runtime costs." I would link to his package, as they are at least overlapping, if his not package better (in all cases?).

@bramtayl
Copy link
Owner

I think there are more regex features supported here, at least last time I checked. I have an issue open in ReadableRegex for figuring out a way to merge the two packages.

@jkrumbiegel
Copy link

There are a lot of regex features, I did the most common ones but not the flags that change the behavior or recursion options because I hadn't used them so far.

@bramtayl
Copy link
Owner

bramtayl commented Aug 31, 2020

@jkrumbiegel I was working based on https://www.pcre.org/current/doc/html/pcre2pattern.html. I tried to implement everything it mentions, but honestly I have no idea if some of the stuff I did is correct (especially related to recursion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants