Skip to content

Onepass DFA always has empty captures (user error) #1174

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

Closed
Crypto-Spartan opened this issue Mar 12, 2024 · 2 comments
Closed

Onepass DFA always has empty captures (user error) #1174

Crypto-Spartan opened this issue Mar 12, 2024 · 2 comments

Comments

@Crypto-Spartan
Copy link

What version of regex are you using?

regex-automata = "0.4.6"

Describe the bug:

With the following code:

use regex_automata::{
    dfa::{onepass, Automaton},
    nfa::thompson,
    util::syntax,
    Anchored, HalfMatch, Input, Match, MatchKind
};

fn main() {
    let test_nfa_conf = thompson::NFA::config()
        .which_captures(thompson::WhichCaptures::None)
        .utf8(false)
        .shrink(true)
        .reverse(false);
    let test_dfa = onepass::DFA::builder()
        .syntax(syntax::Config::new().unicode(false).utf8(false))
        .thompson(test_nfa_conf)
        .build(r"^dead(beef)$")
        .unwrap();
    
    let haystack = "deadbeef";
    let input = Input::new(haystack).anchored(Anchored::Yes);
    
    let (mut cache, mut caps) = (test_dfa.create_cache(), test_dfa.create_captures());
    test_dfa.try_search(&mut cache, &input, &mut caps).unwrap();
    
    dbg!(&cache);
    dbg!(&caps);
    dbg!(&caps.get_match());
}

I get the following output:

image

I would expect to see a capture on beef, but the captures are empty. If I'm doing something wrong, I'm terribly sorry for wasting your time. However, I've played around with this for almost 2 hours in various formats and I still can't get it to work.

Based on the docs for onepass::DFA, this code seemed correct, but I'm not sure what's going on.

@BurntSushi
Copy link
Member

You're explicitly disabling captures in the NFA with thompson::WhichCaptures::None.

@Crypto-Spartan
Copy link
Author

🤦

I'm so sorry. This is what happens when messing with stuff too late into the night. Next time I'll try to remember to just go to bed.

@Crypto-Spartan Crypto-Spartan changed the title Onepass DFA always has empty captures Onepass DFA always has empty captures (user error) Mar 12, 2024
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

2 participants