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

Separate option --multiline-dotall and --multiline #123

Merged
merged 1 commit into from
Sep 11, 2021
Merged

Separate option --multiline-dotall and --multiline #123

merged 1 commit into from
Sep 11, 2021

Conversation

feng-qi
Copy link
Contributor

@feng-qi feng-qi commented Sep 9, 2021

Using option --multiline doesn't necessarily mean the user also wants
--multiline-dotall. The user may be certain about the number of new lines
involved. For example, with this code snippet:

    if (level == 2U) {
        parent_irq = irq_parent_level_2(irq);
        table_idx = parent_offset + irq_from_level_2(irq);
    }
#ifdef CONFIG_3RD_LEVEL_INTERRUPTS
    else if (level == 3U) {
        parent_irq = irq_parent_level_3(irq);
        table_idx = parent_offset + irq_from_level_3(irq);
    }

If I want to search all the #ifdef followed by a else statement, I can use regex
#ifdef.*\n.*else. If --multiline-dotall is used, this regex will match more
lines than I expected.

Using option `--multiline` doesn't necessarily mean the user also wants
`--multiline-dotall`. The user may be certain about the number of new lines
involved. For example, with this code snippet:

    ```c
        if (level == 2U) {
            parent_irq = irq_parent_level_2(irq);
            table_idx = parent_offset + irq_from_level_2(irq);
        }
    #ifdef CONFIG_3RD_LEVEL_INTERRUPTS
        else if (level == 3U) {
            parent_irq = irq_parent_level_3(irq);
            table_idx = parent_offset + irq_from_level_3(irq);
        }
    ```

If I want to search all the #ifdef followed by a else statement, I can use regex
'#ifdef.*\n.*else'. If `--multiline-dotall` is used, this regex will match more
lines than I expected.
@feng-qi
Copy link
Contributor Author

feng-qi commented Sep 9, 2021

Besides, one can use the dot all modifier, which looks like (?s), to change the dot's behavior if --multiline-dotall is not available. https://til.hashrocket.com/posts/9zneks2cbv-multiline-matches-with-ripgrep-rg

@coveralls
Copy link

Coverage Status

Coverage remained the same at 80.775% when pulling e3af9b3 on feng-qi:master into 0fa6d33 on dajva:master.

@dajva dajva merged commit 3e9cada into dajva:master Sep 11, 2021
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

Successfully merging this pull request may close these issues.

3 participants