branch: master commit 452ec1efd958c44c18932e126dac14a18c8e1748 Author: Junpeng Qiu <qjpchm...@gmail.com> Commit: Junpeng Qiu <qjpchm...@gmail.com>
Update scheme parser --- examples/scheme-tests.el | 88 ++++++++++++++++++++++++++++++++++++++++++++++ examples/scheme.el | 12 +------ 2 files changed, 89 insertions(+), 11 deletions(-) diff --git a/examples/scheme-tests.el b/examples/scheme-tests.el new file mode 100644 index 0000000..0e7e402 --- /dev/null +++ b/examples/scheme-tests.el @@ -0,0 +1,88 @@ +;;; scheme-tests.el --- Tests for scheme parser -*- lexical-binding: t; -*- + +;; Copyright (C) 2016 Junpeng Qiu + +;; Author: Junpeng Qiu <qjpchm...@gmail.com> +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program 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 General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'ert) +(require 'scheme) + +(ert-deftest test-scheme-number () + (should + (equal (scheme-read "25") + (scheme-number 25)))) + +(ert-deftest test-scheme-string () + (should + (equal + (scheme-read "\"This is a string\"") + "This is a string"))) + +(ert-deftest test-scheme-list () + (should + (equal + (scheme-read "(symbol)") + '(List + (Atom . "symbol")))) + (should + (equal + (scheme-read "(a test)") + '(List + (Atom . "a") + (Atom . "test"))))) + +(ert-deftest test-scheme-dotted-list () + (should + (equal + (scheme-read "(a . test)") + '(DottedList + ((Atom . "a")) + Atom . "test")))) + +(ert-deftest test-scheme-nested () + (should + (equal + (scheme-read "(a (nested) test)") + '(List + (Atom . "a") + (List + (Atom . "nested")) + (Atom . "test"))))) + +(ert-deftest test-scheme-quoted () + (should + (equal + (scheme-read "(a '(quoted (dotted . list)) test)") + '(List + (Atom . "a") + (List + (Atom . "quote") + (List + (Atom . "quoted") + (DottedList + ((Atom . "dotted")) + Atom . "list"))) + (Atom . "test"))))) + +(provide 'scheme-tests) +;;; scheme-tests.el ends here diff --git a/examples/scheme.el b/examples/scheme.el index 3127b59..d750c54 100644 --- a/examples/scheme.el +++ b/examples/scheme.el @@ -53,7 +53,7 @@ (defun scheme-parse-string () (parsec-and (parsec-ch ?\") - (parsec-return (parsec-many-as-string (parsec-re "[^\"]")) + (parsec-return (parsec-many-as-string (parsec-none-of ?\")) (parsec-ch ?\")))) (defun scheme-parse-atom () @@ -104,15 +104,5 @@ (parsec-with-input expr (scheme-parse-expr))) -(scheme-read "25") -(scheme-read "\"This is a string\"") -(scheme-read "(symbol)") -(scheme-read "(a test)") -(scheme-read "(a . test)") -(parsec-with-input "a . test" - (parsec-sepby (scheme-parse-expr) (scheme-spaces))) -(scheme-read "(a (nested) test)") -(scheme-read "(a '(quoted (dotted . list)) test)") - (provide 'scheme) ;;; scheme.el ends here