From ed53ab0a820a3b68cb8b765bba9c3fa532fec7c7 Mon Sep 17 00:00:00 2001 From: Utz-Uwe Haus Date: Wed, 1 Oct 2008 22:42:12 +0200 Subject: [PATCH] Add example files. Signed-off-by: Utz-Uwe Haus --- README | 4 ++++ example.lisp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ example.peg | 3 +++ 3 files changed, 55 insertions(+) create mode 100644 example.lisp create mode 100644 example.peg diff --git a/README b/README index 99c4c10..2f9ec7c 100644 --- a/README +++ b/README @@ -10,5 +10,9 @@ lexial and syntactic analysis. The code was inspired (and initially bootstrapped) by John Leuner's experimental metapeg library, but does not share significant code with it. +The file example.lisp (and example.peg) contains a simple example of +how you can use opossum to generate a parser for your favorite grammar +in your own lisp code. + $Id$ diff --git a/example.lisp b/example.lisp new file mode 100644 index 0000000..59a62da --- /dev/null +++ b/example.lisp @@ -0,0 +1,48 @@ +;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; -*- +;;; +;;; example.lisp --- Sample code showing use of cl-opossum. + +;; Copyright (C) 2008 Utz-Uwe Haus +;; $Id$ +;; This code is free software; you can redistribute it and/or modify +;; it under the terms of the version 3 of the GNU General +;; Public License as published by the Free Software Foundation, as +;; clarified by the prequel found in LICENSE.Lisp-GPL-Preface. +;; +;; This code is distributed in the hope that it will be useful, but +;; without any warranty; without even the implied warranty of +;; merchantability or fitness for a particular purpose. See the GNU +;; Lesser General Public License for more details. +;; +;; Version 3 of the GNU General Public License is in the file +;; LICENSE.GPL that was distributed with this file. If it is not +;; present, you can access it from +;; http://www.gnu.org/copyleft/gpl.txt (until superseded by a +;; newer version) or write to the Free Software Foundation, Inc., 59 +;; Temple Place, Suite 330, Boston, MA 02111-1307 USA +;; +;; Commentary: + +;; Load this file into your lisp to see how cl-opossum can be utilized +;; in your own programs. + +;;; Code: + + + +(in-package #:CL-USER) + +;; load the opossum package +(asdf:operate 'asdf:load-op :opossum) + +;; Create a parser for the grammar defined in example.peg, in a fresh package +(setq *p* (opossum:make-string-parser "example.peg")) +;; => ... + +;; use the parser to parse a string +(setq *t* (funcall *p* "14+7*(1+1)^2")) +;; => ... + +;; and try out the code generated by the grammar +(eval *t*) +;; => 42 diff --git a/example.peg b/example.peg new file mode 100644 index 0000000..38db164 --- /dev/null +++ b/example.peg @@ -0,0 +1,3 @@ +# Sample PEG file to demonstrate CL-Opossum use -*- mode:peg -*- +# $Id$ +# -- 2.11.4.GIT