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

#break/return not working inside #regexp #37

Closed
Lanbosudo opened this issue Mar 8, 2021 · 2 comments
Closed

#break/return not working inside #regexp #37

Lanbosudo opened this issue Mar 8, 2021 · 2 comments

Comments

@Lanbosudo
Copy link

Like title says, I found that #break/#return doesn't work as intended when used inside #regexp.
Example:

#foreach {{1}{2}{3}{4}{5}{6}} tmp {
    #regexp {"$tmp"} {"5"} {
        #break;
    } {
        #echo $tmp
    }
}

Output is 1 2 3 4 6 instead of 1 2 3 4.

Is this the way #regexp should be working?

Env: Debian in WSL Windows 10
Tintin: 2.02.05

@scandum
Copy link
Owner

scandum commented Mar 8, 2021

As per #help break

The break command can be used inside the #foreach, #loop, #parse,
#while and #switch statements.

#regex has its own scope so #break and #return won't work within it.

I'll have to rewrite the scripting engine to handle #regex, which probably won't be anytime soon. You can however use:

#foreach {{1}{2}{3}{4}{5}{6}} tmp {
    #regexp {"$tmp"} {"{[^5]}"} {
        #echo $tmp
    };
    #else 
    {
        #break;
    }
}

@Lanbosudo
Copy link
Author

As per #help break

The break command can be used inside the #foreach, #loop, #parse,
#while and #switch statements.

#regex has its own scope so #break and #return won't work within it.

I'll have to rewrite the scripting engine to handle #regex, which probably won't be anytime soon. You can however use:

#foreach {{1}{2}{3}{4}{5}{6}} tmp {
    #regexp {"$tmp"} {"{[^5]}"} {
        #echo $tmp
    };
    #else 
    {
        #break;
    }
}

Yeah, sure, that's what i'm doing now. Thanks for the prompt reply~

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