diff --git a/src/r7rs.ebnf b/src/r7rs.ebnf index c100772..d55a2e4 100644 --- a/src/r7rs.ebnf +++ b/src/r7rs.ebnf @@ -47,7 +47,46 @@ directive = #"#!(no-)?fold-case" (* library *) library-start = library -library = <"define-library"> - library-name +library = <"define-library"> + library-name + library-declaration* + library-name = library-name-part+ = symbol | uinteger-10 + + = export-declaration + | import-declaration + | begin-declaration + +export-declaration = + <'export'> export-spec* + + = symbol + +import-declaration = + <'import'> import-set+ + + + = library-name + | import-only + | import-except + | import-prefix + | import-rename + +import-only = + <'only'> import-set symbol+ +import-except = + <'except'> import-set symbol+ +import-prefix = + <'prefix'> import-set symbol+ +import-rename = + <'rename'> + import-set + ( symbol symbol )+ + + +begin-declaration = + + <'begin'> + datum* + diff --git a/src/scm.clj b/src/scm.clj index 4d69096..140a70a 100644 --- a/src/scm.clj +++ b/src/scm.clj @@ -141,6 +141,9 @@ :datum-start identity :library-start identity :library-name list + :import-declaration #(vec (cons :import %&)) + :export-declaration #(vec (cons :export %&)) + :begin-declaration #(vec (cons :begin %&)) :library (fn [lib-name & decls] #:library {:name lib-name :declarations decls}) diff --git a/test/scm_test.clj b/test/scm_test.clj index 178d690..336d7db 100644 --- a/test/scm_test.clj +++ b/test/scm_test.clj @@ -25,7 +25,20 @@ (sut/read s :throw? true :library? true)) "" "()" - "(define-library ())"))) + "(define-library ())" + ;; broken + #_"(define-library (blah -123))") + (t/is (= '#:library + {:name (my cool lib) + :declarations + ([:import (scheme base)] + [:export square] + [:begin (define (square n) (* n n))])} + (sut/read "(define-library (my cool lib) + (import (scheme base)) + (export square) + (begin (define (square n) (* n n))))" + :library? true))))) (t/deftest read-syntax-test (t/is (sut/unresolved? (sut/read-syntax "123")))