From 8dc6346c58cfdf5ea1f6cf4d36b23c73a4dfa231 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 8 Oct 2018 20:53:53 +0100 Subject: [PATCH] Special cases for label[...] and label{...} --- implementations/racket/preserves/main.rkt | 18 ++++++++++-------- preserves.md | 6 ++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/implementations/racket/preserves/main.rkt b/implementations/racket/preserves/main.rkt index 5bd01b4..bdaa1c2 100644 --- a/implementations/racket/preserves/main.rkt +++ b/implementations/racket/preserves/main.rkt @@ -283,8 +283,8 @@ (define (read-sequence terminator) (sequence-fold '() (lambda (acc) (cons (read-value) acc)) reverse terminator)) - (define (read-dictionary-or-set) - (sequence-fold #f + (define (read-dictionary-or-set seed) + (sequence-fold seed (lambda (acc) (define k (read-value)) (skip-whitespace) @@ -447,18 +447,20 @@ (define (collect-fields head) (match (peek-char i) - [#\( - (read-char i) - (collect-fields (build-record head (read-sequence #\))))] - [_ - head])) + [#\( (read-char i) + (collect-fields (build-record head (read-sequence #\))))] + [#\[ (read-char i) + (collect-fields (build-record head (list (read-sequence #\]))))] + [#\{ (read-char i) + (collect-fields (build-record head (list (read-dictionary-or-set (hash)))))] + [_ head])) (define (read-value) (skip-whitespace) (collect-fields (match (peek-char i) [(? eof-object? o) o] - [#\{ (read-char i) (read-dictionary-or-set)] + [#\{ (read-char i) (read-dictionary-or-set #f)] [#\[ (read-char i) (read-sequence #\])] [(or #\- #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) (read-number)] [#\" (read-char i) (read-string #\")] diff --git a/preserves.md b/preserves.md index f2431ed..d4fe242 100644 --- a/preserves.md +++ b/preserves.md @@ -317,6 +317,12 @@ tokens `#set{` and `}`.[^printing-collections] commas separating, and commas terminating elements or key/value pairs within a collection. +The special cases of records with a single field, which is in turn a +sequence or dictionary, may be written omitting the parentheses. + + Record =/ Value Sequence + Record =/ Value Dictionary + `Boolean`s are the simple literal strings `#true` and `#false`. Boolean = %s"#true" / %s"#false"