Moritz Heidkamp avatar Moritz Heidkamp committed ff63758

Use collection-parser for maps, too

Comments (0)

Files changed (2)

             edn-keyword
             edn-symbol))))
 
-(define (collection-parser result-parser-name open close)
+(define (collection-parser result-parser-name open close #!optional items-parser)
   (sequence* ((_ (is open))
-              (items (zero-or-more (edn-element)))
+              (items (or items-parser (zero-or-more (edn-element))))
               (closed? (maybe (preceded-by whitespace (is close)))))
     (if closed?
         (result-parser result-parser-name items)
   (collection-parser 'vector #\[ #\]))
 
 (define edn-map
-  (bind (enclosed-by
-         (is #\{)
-         (zero-or-more
-          (any-of
-           (sequence* ((key (edn-element))
-                       (val (edn-element)))
-             (result (cons key val)))
-           (bind (edn-element)
-                 (lambda (key)
-                   (error "Missing value for key" key)))))
-         (preceded-by whitespace (is #\})))
-        (lambda (coll)
-          (result-parser 'map coll))))
+  (collection-parser 'map #\{ #\}
+                     (zero-or-more
+                      (any-of
+                       (sequence* ((key (edn-element))
+                                   (val (edn-element)))
+                         (result (cons key val)))
+                       (bind (edn-element)
+                             (lambda (key)
+                               (error "Missing value for key" key)))))))
 
 (define edn-set
   (preceded-by
                  ((vector 99) . (map))))
   (test-read-error "{123}")
   (test-read-error "{:foo 123 :bar}")
-  (test-read-fail "{]"))
+  (test-read-error "{]"))
 
 (define (set-equal? a b)
   (lset= (lambda (a b)
   (test-read "#nice/string \"edn\"" "edn is nice!"))
 
 (test-end)
+
+(test-exit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.