Added a zipcode parser
authorD Herring <dherring@at.tentpost.dot.com>
Tue, 3 Apr 2007 03:56:11 +0000 (23:56 -0400)
committerD Herring <dherring@at.tentpost.dot.com>
Tue, 3 Apr 2007 03:56:11 +0000 (23:56 -0400)
examples/zipcode.lisp [new file with mode: 0644]

diff --git a/examples/zipcode.lisp b/examples/zipcode.lisp
new file mode 100644 (file)
index 0000000..370351f
--- /dev/null
@@ -0,0 +1,14 @@
+(defpackage :zipcode
+  (:documentation "Parse a USPS zipcode.")
+  (:use :common-lisp :ebnf)
+  (:export :zipcode))
+
+(in-package :zipcode)
+
+(defgrammar "
+ digit='0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9';
+ zipcode= 5*digit, '-', 4*digit-5*digit
+        | 5*digit - (5*digit, ('-' | digit));"
+
+  (zipcode (lambda (x) (declare (ignore x))
+                   (subseq ebnf:string start end))))
\ No newline at end of file