Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

Commit

Permalink
Refactor array of tables code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Hendershott committed Jun 26, 2014
1 parent 788cc92 commit 928614e
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,27 @@
(x <- (group keys))
(return x))))

(define (array-of-tables key-parser)
(try (pdo $sp
(keys <- (lookAhead (between (string "[[")
(string "]]")
key-parser)))
(xs <- (many1 (array-of-table-item keys)))
(return (hash-sets (make-immutable-hasheq)
keys
(list->vector xs))))))

(define $array-of-tables
(<?> (try (pdo $sp
(keys <- (lookAhead (between (string "[[") (string "]]")
$table-keys)))
(xs <- (many1 (array-of-table-item keys)))
(return (hash-sets (make-immutable-hasheq)
keys
(list->vector xs)))))
"array of tables"))
(<?> (array-of-tables $table-keys)
"any array of tables"))

(define (array-of-tables/under parent-keys)
(<?> (try (pdo $sp
(keys <-
(lookAhead
(between (string "[[") (string "]]")
(pdo (string (string-join (map symbol->string parent-keys) "."))
(char #\.)
(keys <- $table-keys)
(return (append parent-keys keys))))))
(xs <- (many1 (array-of-table-item keys)))
(return (hash-sets (make-immutable-hasheq)
keys
(list->vector xs)))))
"array of tables"))
(<?> (array-of-tables
(pdo (string (string-join (map symbol->string parent-keys) "."))
(char #\.)
(keys <- $table-keys)
(return (append parent-keys keys))))
(format "array of tables under keys ~a" parent-keys)))

(define $toml-document
(pdo (many $blank-or-comment-line)
Expand Down

0 comments on commit 928614e

Please sign in to comment.