commit fdd617fa2f7486f8593f93f3875f4a87dcc404b7 Author: Zander Thannhauser Date: Fri Sep 20 09:29:29 2024 -0500 first commit! diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..0bc2a51 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ + + + +# 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 + + + + +## 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([+-]m)*+:a'` +- `$ pregrep -e 'ws: *,p:[0-9]+|\(\),m:

([*/]

)*,a:([+-])*'` + +### (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:\[((,)*)?],k:\:,o:{((,)*)?},j:|||'` +- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[,\,)>],o:{\:,\,)>},j:|||'` + +- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",csv():(<1>(<2><1>)*)?,l:\[)>],o:{:)>},j:|||'` + +### "csv" and "sv" are both defined in .pregrep.yaml +- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[)>],o:{:)>},j:|||'` +- `$ pregrep -W 'N:[0-9]+,S:"[^"]*",l:\[)>],o:{:)>},j:|||' --replace "(j (N @a) (N @b)) -> (j @b @a))"` + +### cvs of numbers: +- `$ pregrep -e '(\n)*'` +- `$ pregrep -e '(\n)*'` +- `$ pregrep -W -e '(\n)*'` +- `$ pregrep -e 'ws:[ \n]*,(*)>\n)*'` +- `$ pregrep -e 'ws:[ \n]*,C:[^,\n]*,(\n)*'` +- `$ pregrep -W -e 'C:[^,\n]*,()>\n)*'` + + + + + diff --git a/buildtypes/release.txt b/buildtypes/release.txt new file mode 100644 index 0000000..78111ab --- /dev/null +++ b/buildtypes/release.txt @@ -0,0 +1,5 @@ + +-Wall +-Werror +-Wfatal-errors + diff --git a/main.c b/main.c new file mode 100644 index 0000000..0453448 --- /dev/null +++ b/main.c @@ -0,0 +1,10 @@ + +#include + +int main() +{ + puts("hello, world!"); + + return 0; +} + diff --git a/makefile b/makefile new file mode 100644 index 0000000..ff2bd29 --- /dev/null +++ b/makefile @@ -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)) + + + + + + + + + + + + + + + diff --git a/srclist.mk b/srclist.mk new file mode 100644 index 0000000..1b7cecc --- /dev/null +++ b/srclist.mk @@ -0,0 +1 @@ +srcs += ./main.c