62 lines
2.3 KiB
Markdown
62 lines
2.3 KiB
Markdown
|
|
<!-- vim: set wrap: -->
|
|
|
|
# Pegrep (C edition)
|
|
|
|
Pegrep is a portmanteau of "peg" and "grep". That is, this program fills a similar niche as grep (GNU's regular expression processor), but with "peg" parsing rather that typical regular expression processing (LR parser vs. DFA).
|
|
|
|
This repository stores the C implementation of Pegrep.
|
|
|
|
With Pegrep, users can search for text in files that follows a more complex pattern than one could articulate in grep. The standout feature of Pegrep is that patterns can be *recursive*.
|
|
|
|
For instance:
|
|
|
|
...
|
|
|
|
## Usage:
|
|
|
|
- `-W` | `--standard-whitespace`
|
|
- which would mean [ \t\n\r]* inserted after all characters or character sets in lower case rules.
|
|
|
|
## Pattern Language
|
|
|
|
<!--# rules and macros can be predefined in a config file.-->
|
|
<!--# macros can also be defined on the command-line:-->
|
|
|
|
## Configuration File
|
|
|
|
## Examples:
|
|
|
|
### arithmetic:
|
|
|
|
- `$ pegrep -w ' ' -e 'N:[0-9]+,p:N|\(a\),m:p([*/]p)*,a:m([+-])+:a'`
|
|
- `$ pegrep --whitespace ' ' -e 'N:[0-9]+,p:N|\(a\),m:p([*/]p)*,a:m([+-])+:a'`
|
|
- `$ pegrep -e 'ws: *,p:[0-9]+ws|\(wsa\)ws,m:p([*/]wsp)*,a:m([+-]<ws>m)*+:a'`
|
|
- `$ pegrep -e 'ws: *,p:[0-9]+<ws>|\(<ws><a>\)<ws>,m:<p>([*/]<ws><p>)*,a:<m>([+-]<ws><m>)*'`
|
|
|
|
### (Simple) JSON:
|
|
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",l:\[(j(,j)*)?],k:S\:j,o:{(k(,k)*)?},j:N|S|l|o'`
|
|
- `$ pegrep -W 'N:[0-9]+,S:\"[^"]*\",l:\[(j(\,j)*)?],k:S\:j,o:\{(k(\,k)*)?},j:N|S|l|o'`
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",l:\[(j(,j)*)?],o:{(S\:j(,S\:j)*)?},j:N|S|l|o'`
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",l:\[(<j>(,<j>)*)?],k:<S>\:<j>,o:{(<k>(,<k>)*)?},j:<N>|<S>|<l>|<o>'`
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",l:\[<sv(<j>,\,)>],o:{<sv(<S>\:<j>,\,)>},j:<N>|<S>|<l>|<o>'`
|
|
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",csv():(<1>(<2><1>)*)?,l:\[<csv(<j>)>],o:{<csv(<S>:<j>)>},j:<N>|<S>|<l>|<o>'`
|
|
|
|
### "csv" and "sv" are both defined in .pegrep.yaml
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",l:\[<csv(<j>)>],o:{<csv(<S>:<j>)>},j:<N>|<S>|<l>|<o>'`
|
|
- `$ pegrep -W 'N:[0-9]+,S:"[^"]*",l:\[<csv(<j>)>],o:{<csv(<S>:<j>)>},j:<N>|<S>|<l>|<o>' --replace "(j (N @a) (N @b)) -> (j @b @a))"`
|
|
|
|
### cvs of numbers:
|
|
- `$ pegrep -e '(<sv([^,\n]*,\,)>\n)*'`
|
|
- `$ pegrep -e '(<csv([^,\n]*)>\n)*'`
|
|
- `$ pegrep -W -e '(<csv([^,\n]*)>\n)*'`
|
|
- `$ pegrep -e 'ws:[ \n]*,(<csv([^,\n]<ws>*<ws>)>\n<ws>)*'`
|
|
- `$ pegrep -e 'ws:[ \n]*,C:[^,\n]*,(<csv(C)>\n<ws>)*'`
|
|
- `$ pegrep -W -e 'C:[^,\n]*,(<csv(<C>)>\n)*'`
|
|
|
|
|
|
|
|
|
|
|