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

Add a regular expression engine #222

Merged
merged 26 commits into from
Aug 1, 2021
Merged

Add a regular expression engine #222

merged 26 commits into from
Aug 1, 2021

Conversation

vinc
Copy link
Owner

@vinc vinc commented Jul 29, 2021

Add a very basic regular expression engine based on https://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html

  • Support . char
  • Support * char
  • Support + char
  • Support ? char
  • Support \ char
  • Support | char
  • Support \d chars
  • Support \D chars
  • Support \s chars
  • Support \S chars
  • Support \w chars
  • Support \W chars
  • Support {a,b} range
  • Support lazy ? char

Also add a find --line command that works like grep on Unix to test it on files.

@vinc
Copy link
Owner Author

vinc commented Jul 31, 2021

The first command using the regex engine will be find used to find files with a given name or lines in files with a given pattern:

> find /tmp --name ".*txt" --line "exa\w+ple"

Or with the shortcut form:

> f /tmp -n "*.txt" -l "exa\w+ple"

The first parameter --name is like the find command in Unix and the second parameter --line is like grep.

@vinc
Copy link
Owner Author

vinc commented Jul 31, 2021

Finding Alice and cat in the example text:
find

Now we probably need to add greedy matching to find cats?

@vinc
Copy link
Owner Author

vinc commented Aug 1, 2021

The find --name part of the find command will be added in another PR with the Wildcard struct.

@vinc vinc marked this pull request as ready for review August 1, 2021 09:23
@vinc
Copy link
Owner Author

vinc commented Aug 1, 2021

Recursive line matching:
find

@vinc vinc merged commit de48c87 into master Aug 1, 2021
@vinc vinc deleted the feature/regex branch August 1, 2021 09:35
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.

1 participant