softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
507 stars 31 forks source link

Regex options take 2 #402

Closed ratmice closed 1 year ago

ratmice commented 1 year ago

I've been a bit slow in getting this finished, but this is basically the finished patch of the second attempt at regex options, Overall exporting the constructor was simple, I didn't modify the trait from_str function at all, just added a new concrete function for LRNonStreamingLexerDef.

I note that from_str does not take self, so there appear to be no issues involving things like new_with_options(s,opts).from_str(s) returning a lexer with default options.

While testing this, I noted some cleanups and bugs in lrpar/cttests/build.rs, when I added the lex_flags previously it was flipped, there was a duplicate call strip_prefix, and some if statements could be simplified. These are within the last patch adding tests.

Edit: By setting the octal flag to '!octal', you can induce a regex/build error here.

ltratt commented 1 year ago

This looks promising! Silly question: I think this is 100% backwards compatible?

ratmice commented 1 year ago

The only incompatibility should be the additional parameter to Rule::new which is documented as an unstable API which should only be called by the crates builders.

ltratt commented 1 year ago

Aha, I see! Yep, I'm fine with adding that argument to the unstable interface. OK to merge?

ratmice commented 1 year ago

I should probably squash the first two commits, and rewrite the first commit message to something such as: "Add CTLexerBuilder options for configuring regex behavior.", but am otherwise happy with it.

ltratt commented 1 year ago

Please squash.

ratmice commented 1 year ago

Squashed.

ltratt commented 1 year ago

bors r+

bors[bot] commented 1 year ago

Build succeeded: