first commit!

This commit is contained in:
Zander Thannhauser 2024-09-20 09:29:29 -05:00
commit fdd617fa2f
6 changed files with 140 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
bin/

62
README.md Normal file
View file

@ -0,0 +1,62 @@
<!-- vim: set wrap: -->
# Pregrep (C edition)
Pregrep 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 pregrep.
With pregrep, users can search for text in files that follows a more complex pattern than one could articulate in grep. The standout feature of pregrep 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:
- `$ pregrep -w ' ' -e 'N:[0-9]+,p:N|\(a\),m:p([*/]p)*,a:m([+-])+:a'`
- `$ pregrep --whitespace ' ' -e 'N:[0-9]+,p:N|\(a\),m:p([*/]p)*,a:m([+-])+:a'`
- `$ pregrep -e 'ws: *,p:[0-9]+ws|\(wsa\)ws,m:p([*/]wsp)*,a:m([+-]<ws>m)*+:a'`
- `$ pregrep -e 'ws: *,p:[0-9]+<ws>|\(<ws><a>\)<ws>,m:<p>([*/]<ws><p>)*,a:<m>([+-]<ws><m>)*'`
### (Simple) JSON:
- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[(j(,j)*)?],k:S\:j,o:{(k(,k)*)?},j:N|S|l|o'`
- `$ pregrep -W 'N:[0-9]+,S:\"[^"]*\",l:\[(j(\,j)*)?],k:S\:j,o:\{(k(\,k)*)?},j:N|S|l|o'`
- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[(j(,j)*)?],o:{(S\:j(,S\:j)*)?},j:N|S|l|o'`
- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[(<j>(,<j>)*)?],k:<S>\:<j>,o:{(<k>(,<k>)*)?},j:<N>|<S>|<l>|<o>'`
- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[<sv(<j>,\,)>],o:{<sv(<S>\:<j>,\,)>},j:<N>|<S>|<l>|<o>'`
- `$ pregrep -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 .pregrep.yaml
- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[<csv(<j>)>],o:{<csv(<S>:<j>)>},j:<N>|<S>|<l>|<o>'`
- `$ pregrep -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:
- `$ pregrep -e '(<sv([^,\n]*,\,)>\n)*'`
- `$ pregrep -e '(<csv([^,\n]*)>\n)*'`
- `$ pregrep -W -e '(<csv([^,\n]*)>\n)*'`
- `$ pregrep -e 'ws:[ \n]*,(<csv([^,\n]<ws>*<ws>)>\n<ws>)*'`
- `$ pregrep -e 'ws:[ \n]*,C:[^,\n]*,(<csv(C)>\n<ws>)*'`
- `$ pregrep -W -e 'C:[^,\n]*,(<csv(<C>)>\n)*'`

5
buildtypes/release.txt Normal file
View file

@ -0,0 +1,5 @@
-Wall
-Werror
-Wfatal-errors

10
main.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdio.h>
int main()
{
puts("hello, world!");
return 0;
}

61
makefile Normal file
View file

@ -0,0 +1,61 @@
# vim: noexpandtab tabstop=4 :
buildtype ?= release
buildtype_options = buildtypes/${buildtype}.txt
prefix = bin/${buildtype}-buildtype
objs = $(patsubst %.c,${prefix}/%.o,$(srcs))
default: ${prefix}/pregrep
srclist.mk:
find -name '*.c' -! -path '*/junk/*' | sed 's/^/srcs += /' | sort -V > $@
include srclist.mk
.PRECIOUS: %/
%/:
@mkdir -p $@
${prefix}/pregrep: ${buildtype_options} ${objs} | ${prefix}/
@echo "${buildtype}: linking ${@} ..."
@gcc @${buildtype_options} ${objs} -o $@ -lm
${prefix}/%.o ${prefix}/%.d: %.c ${buildtype_options} | ${prefix}/%/
@echo "${buildtype}: compiling ${*}.c ..."
@gcc -c @${buildtype_options} $< -MD -MF ${prefix}/${*}.d -o ${prefix}/${*}.o # || (${EDITOR} $<; false)
# env += UBSAN_OPTIONS='halt_on_error=1,print_stacktrace=1'
run: ${prefix}/pregrep
${env} $< ${args}
gdbrun: ${prefix}/pregrep
gdb --args $< ${args}
valrun: ${prefix}/pregrep
valgrind --gen-suppressions=yes -- $< ${args}
valrun-leak: ${prefix}/pregrep
valgrind --leak-check=full --gen-suppressions=yes -- $< ${args}
include $(patsubst %.c,${prefix}/%.d,$(srcs))

1
srclist.mk Normal file
View file

@ -0,0 +1 @@
srcs += ./main.c