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

_escape() in funs.py makes it impossible to match end of line? #16

Open
alix-tz opened this issue Mar 7, 2024 · 4 comments
Open

_escape() in funs.py makes it impossible to match end of line? #16

alix-tz opened this issue Mar 7, 2024 · 4 comments

Comments

@alix-tz
Copy link
Contributor

alix-tz commented Mar 7, 2024

I need to investigate this more to see if this is really the problem, but it seems that the static method _escape() in funcs.py causes a pattern such as #r#-$ to look for the literal string -$ instead of -<end-of-line>.

I am wondering what were the motivations of _escape(), and if we can have an alternative approach to be able to fully use regex' syntax.

@PonteIneptique
Copy link
Owner

(For ease of discussion, it's always good to link to functions by copying the uri for the given line. Press "Y" for the permanent commit identified URI, and select the line)

@staticmethod
def _escape(string: str):
""" Escapes or not a string that is present in the control table. Strings starting with #r# are not escaped
>>> Translator._escape("#r#(a|b)")
'(a|b)'
>>> Translator._escape("(a|b)") == r'\(a\|b\)'
True
"""
if string.startswith("#r#"):
return string[3:]
return re.escape(string)

@PonteIneptique
Copy link
Owner

Given the function, #r#\w$ should not be escaped. You sure about this ?

@alix-tz
Copy link
Contributor Author

alix-tz commented Mar 7, 2024

Ah my bad, I read too quickly!
Then I'll keep "dérouler la pelote" to understand where the problem is.

@PonteIneptique
Copy link
Owner

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