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

Peek regex #779

Merged
merged 26 commits into from Dec 3, 2020
Merged

Peek regex #779

merged 26 commits into from Dec 3, 2020

Conversation

blefloch
Copy link
Member

This branch (which branches out of the peek-analysis branch) implements ways to peek ahead into the input stream. The code should be ok, but I am not sure if the interface I chose is ok.

I implemented \peek_regex:nTF, \peek_regex_remove_once:nTF, and \peek_regex_replace_once:nnTF, and the same with first argument being a regex variable instead of an n-type regex. I provided \peek_regex_replace_once:nn, but not the other "no TF" versions of the other functions because they don't seem really sensible. In fact, \peek_regex:nTF and \peek_regex_remove_once:nTF could be implemented as

\cs_new_protected:Npn \peek_regex:nTF #1
  { \peek_regex_replace_once:nnTF {#1} { \0 } }
\cs_new_protected:Npn \peek_regex_remove_once:nTF #1 
  { \peek_regex_replace_once:nnTF {#1} { } }

so maybe the remove_once functions could be omitted. We could also reasonably provide \peek_regex_replace_all:nnTF which would repeatedly search for the pattern.

Perhaps tests I put in m3regex011 are not thorough enough.

Copy link
Member

@josephwright josephwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me. I think the names \peek_regex:n(TF), etc., are good. I guess \peek_analysis_map_inline:n is slightly awkward, but I don't see a better one - iot's quite specialised anyway.

Overall I think we go for this then can move to extending xparse.

Bruno Le Floch and others added 26 commits December 3, 2020 15:02
This is just code reorganisation, aiming to be able to peek ahead
in the input stream, for which it is more convenient to look at
tokens one at a time.
The eventual aim is to let users run code while the regex is being
matched. For this we need to remove all abuses of TeX registers.
The only one left is toks used for storing states of the nfa.
The aim is to remove uses of max_pos, because that will not be available
when peeking for a regex
These functions check what follows in the input stream, but they
do not give access to it in the T and F branches.  I'll also add
\peek_regex_replace:nnTF that also performs a replacement on the
tokens found.  It might be nice to store the tokens found into
some token list, but unfortunately they can very well have
unbalanced braces.
@josephwright josephwright merged commit b7c4993 into master Dec 3, 2020
@josephwright josephwright deleted the peek-regex branch December 3, 2020 16:27
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.

None yet

2 participants