Skip to content

Commit

Permalink
imported peg-0.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
gpakosz committed Jul 1, 2013
1 parent 0fe23be commit 2a21444
Show file tree
Hide file tree
Showing 35 changed files with 3,949 additions and 2,319 deletions.
58 changes: 40 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS)
CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS) -Isrc
OFLAGS = -O3 -DNDEBUG
#OFLAGS = -pg

Expand All @@ -17,47 +17,69 @@ leg : leg.o $(OBJS)
ROOT =
PREFIX = /usr/local
BINDIR = $(ROOT)$(PREFIX)/bin
MANDIR = $(ROOT)$(PREFIX)/man/man1

install : $(BINDIR)/peg $(BINDIR)/leg
install : $(BINDIR) $(BINDIR)/peg $(BINDIR)/leg $(MANDIR) $(MANDIR)/peg.1

$(BINDIR) :
mkdir -p $(BINDIR)

$(BINDIR)/% : %
cp -p $< $@
strip $@

$(MANDIR) :
mkdir -p $(MANDIR)

$(MANDIR)/% : src/%
cp -p $< $@

uninstall : .FORCE
rm -f $(BINDIR)/peg
rm -f $(BINDIR)/leg
rm -f $(MANDIR)/peg.1

peg.o : peg.c peg.peg-c
%.o : src/%.c
$(CC) $(CFLAGS) -c -o $@ $<

%.peg-c : %.peg compile.c
./peg -o $@ $<
peg.o : src/peg.c src/peg.peg-c

leg.o : src/leg.c

leg.o : leg.c
check : check-peg check-leg

check-peg : peg.peg-c .FORCE
diff src/peg.peg-c peg.peg-c

check-leg : leg.c .FORCE
diff src/leg.c leg.c

leg.c : leg.leg compile.c
peg.peg-c : src/peg.peg peg
./peg -o $@ $<

leg.c : src/leg.leg leg
./leg -o $@ $<

check : check-peg check-leg
new : newpeg newleg

check-peg : peg .FORCE
./peg < peg.peg > peg.out
diff peg.peg-c peg.out
rm peg.out
newpeg : peg.peg-c
mv src/peg.peg-c src/peg.peg-c-
mv peg.peg-c src/.

check-leg : leg .FORCE
./leg < leg.leg > leg.out
diff leg.c leg.out
rm leg.out
newleg : leg.c
mv src/leg.c src/leg.c-
mv leg.c src/.

test examples : .FORCE
test examples : peg leg .FORCE
$(SHELL) -ec '(cd examples; $(MAKE))'

clean : .FORCE
rm -f *~ *.o *.peg.[cd] *.leg.[cd]
rm -f src/*~ *~ *.o *.peg.[cd] *.leg.[cd] peg.peg-c leg.c
$(SHELL) -ec '(cd examples; $(MAKE) $@)'

spotless : clean .FORCE
rm -f src/*-
rm -rf build
rm -f peg
rm -f leg
$(SHELL) -ec '(cd examples; $(MAKE) $@)'
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,36 @@ distribute them any way you like.

## Version history

* **0.1.9** ([zip](peg/zipball/0.1.9), [tar.gz](peg/tarball/0.1.9)) &mdash; 2012-04-29
* **0.1.11** ([zip](../../archive/0.1.11.zip), [tar.gz](../../archive/0.1.11.tar.gz)) &mdash; 2013-06-03
Add error actions via `"~"` operator.
Support declaration of local variables at the top level of semantic actions.
Dynamically grow data structures to remove artificial limits on rule recursion (thanks to Alex Klinkhamer).
Many small changes to better support C++.
Add build files for Win32 and MacOS (thanks to Fyodor Sheremetyev).
Update manual page to describe new features.
* **0.1.10** &mdash; missing in upstream
* **0.1.9** ([zip](../../archive/0.1.9.zip), [tar.gz](../../archive/0.1.9.tar.gz)) &mdash; 2012-04-29
Move global state into a structure to facilitate reentrant and thread-safe parsers (thanks to Dmitry Lipovoi).
* **0.1.8** ([zip](peg/zipball/0.1.8), [tar.gz](peg/tarball/0.1.8)) &mdash; 2012-03-29
* **0.1.8** ([zip](../../archive/0.1.8.zip), [tar.gz](../../archive/0.1.8.tar.gz)) &mdash; 2012-03-29
Allow nested, matched braces within actions.
* **0.1.7** ([zip](peg/zipball/0.1.7), [tar.gz](peg/tarball/0.1.7)) &mdash; 2011-11-25
* **0.1.7** ([zip](../../archive/0.1.7.zip), [tar.gz](../../archive/0.1.7.tar.gz)) &mdash; 2011-11-25
Fix matching of 8-bit chars to allow utf-8 sequences in matching expressions (thanks to Grégory Pakosz).
* **0.1.6** ([zip](peg/zipball/0.1.6), [tar.gz](peg/tarball/0.1.6)) &mdash; 2011-11-24
* **0.1.6** ([zip](../../archive/0.1.6.zip), [tar.gz](../../archive/0.1.6.tar.gz)) &mdash; 2011-11-24
Allow octal escapes in character classes.
* **0.1.5** ([zip](peg/zipball/0.1.5), [tar.gz](peg/tarball/0.1.5)) &mdash; 2011-11-24
* **0.1.5** ([zip](../../archive/0.1.5.zip), [tar.gz](../../archive/0.1.5.tar.gz)) &mdash; 2011-11-24
Remove dwarf sym dirs when cleaning.
Fix size calculation when resizing text buffers.
Backslash can be escaped.
* **0.1.4** ([zip](peg/zipball/0.1.4), [tar.gz](peg/tarball/0.1.4)) &mdash; 2009-08-26
* **0.1.4** ([zip](../../archive/0.1.4.zip), [tar.gz](../../archive/0.1.4.tar.gz)) &mdash; 2009-08-26
Fix match of a single single quote character.
Rename `getline` -> `nextline` to avoid C namespace conflict.
* **0.1.3** ([zip](peg/zipball/0.1.3), [tar.gz](peg/tarball/0.1.3)) &mdash; 2007-09-13
* **0.1.3** ([zip](../../archive/0.1.3.zip), [tar.gz](../../archive/0.1.3.tar.gz)) &mdash; 2007-09-13
Allow matched braces inside `leg` actions.
Handle empty rules.
Handle empty grammars.
* **0.1.2** ([zip](peg/zipball/0.1.2), [tar.gz](peg/tarball/0.1.2)) &mdash; 2007-08-31
* **0.1.2** ([zip](../../archive/0.1.2.zip), [tar.gz](../../archive/0.1.2.tar.gz)) &mdash; 2007-08-31
Grow buffers while (not if) they are too small.
Remove dependencies on grammar files.
Add more basic examples.
* **0.1.1** ([zip](peg/zipball/0.1.1), [tar.gz](peg/tarball/0.1.1)) &mdash; 2007-05-15
* **0.1.1** ([zip](../../archive/0.1.1.zip), [tar.gz](../../archive/0.1.1.tar.gz)) &mdash; 2007-05-15
First public release.
42 changes: 42 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Building on a Unix-like system
------------------------------

Type 'make' or 'make test'.

The latter builds all the examples and runs them, comparing their
output with the expected output.

Type 'make install' to install the binaries and manual page under
/usr/local. (Type 'make uninstall' to remove them.) You may have to
do this using 'sudo' or while logged in as root.

Edit 'Makefile' to change the way things are built and/or the places
where things are installed.


Building on MacOS X
-------------------

Run the 'build-mac.sh' script from a terminal or by double-clicking on
it in the Finder.

You will need Xcode. The provided project is known to work with Xcode
versions 3.2.6 and 4.3.2.

Modify build-mac.sh and/or peg.xcodeproj to change the way things are
built.


Building on Windows
-------------------

Run the 'build-win.cmd' script.

You will need Visual Studio 2010 Express.

Modify build-win.cmd, leg.vcxproj, leg.vcxproj.filters, peg.gyp,
peg.sln, peg.vcxproj and/or peg.vcxproj.filters to change the way
things are built.

Local implementations of getopt() and basename() are provided in the
'win' directory.
6 changes: 6 additions & 0 deletions build-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

xcodebuild -project peg.xcodeproj -configuration Release

cp build/Release/peg ./
cp build/Release/leg ./
5 changes: 5 additions & 0 deletions build-win.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
call "%VS100COMNTOOLS%vsvars32.bat"
msbuild peg.sln /p:Configuration=Release

xcopy /Y /D Release\*.exe .\
22 changes: 19 additions & 3 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXAMPLES = test rule accept wc dc dcv calc basic localctx
EXAMPLES = test rule accept wc dc dcv calc basic localpeg localleg erract

CFLAGS = -g -O3

Expand Down Expand Up @@ -71,14 +71,30 @@ basic : .FORCE
rm -f $@.out
@echo

localctx : .FORCE
localpeg : .FORCE
../peg -o test.peg.c test.peg
$(CC) $(CFLAGS) -o localctx localctx.c
$(CC) $(CFLAGS) -o localpeg localpeg.c
echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | ./$@ | $(TEE) $@.out
$(DIFF) $@.ref $@.out
rm -f $@.out
@echo

localleg : .FORCE
../leg -o localleg.leg.c localleg.leg
$(CC) $(CFLAGS) -o localleg localleg.leg.c
./$@ < localleg.leg | $(TEE) $@.out
$(DIFF) $@.ref $@.out
rm -f $@.out
@echo

erract : .FORCE
../leg -o erract.leg.c erract.leg
$(CC) $(CFLAGS) -o erract erract.leg.c
echo '6*9' | ./$@ | $(TEE) $@.out
$(DIFF) $@.ref $@.out
rm -f $@.out
@echo

clean : .FORCE
rm -f *~ *.o *.[pl]eg.[cd] $(EXAMPLES)
rm -rf *.dSYM
Expand Down
27 changes: 27 additions & 0 deletions examples/erract.leg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%{
#include <stdio.h>
%}

Expr = a:NUMBER PLUS ~{ printf("fail at PLUS\n") } b:NUMBER { printf("got addition\n"); }
| ( a:NUMBER MINUS b:NUMBER { printf("got subtraction\n"); } ) ~{ printf("fail at subtraction\n") }
| a:NUMBER TIMES b:NUMBER { printf("got multiplication\n"); }
| a:NUMBER DIVIDE b:NUMBER { printf("got division\n"); }

NUMBER = < [0-9]+ > - { $$= atoi(yytext); }
PLUS = '+' -
MINUS = '-' -
TIMES = '*' -
DIVIDE = '/' -

- = (SPACE | EOL)*
SPACE = [ \t]
EOL = '\n' | '\r\n' | '\r' | ';'

%%

int main()
{
while (yyparse());

return 0;
}
4 changes: 4 additions & 0 deletions examples/erract.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fail at PLUS
fail at subtraction
got multiplication
fail at subtraction
24 changes: 24 additions & 0 deletions examples/localleg.leg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%{
#define YY_CTX_LOCAL 1
#define YY_CTX_MEMBERS \
int count;
%}

Char = ('\n' | '\r\n' | '\r') { yy->count++ }
| .

%%

#include <stdio.h>
#include <string.h>

int main()
{
yycontext yy;
memset(&yy, 0, sizeof(yy));
while (yyparse(&yy))
;
printf("%d newlines\n", yy.count);
yyrelease(&yy);
return 0;
}
1 change: 1 addition & 0 deletions examples/localleg.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24 newlines
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2a21444

Please sign in to comment.