From 9dc71445eb2bd470279ab135b0678aa2c2b815b5 Mon Sep 17 00:00:00 2001 From: kusumotonorio <47816570+kusumotonorio@users.noreply.github.com> Date: Sat, 15 Feb 2020 22:04:08 +0900 Subject: [PATCH] Supports dotted pair notation --- basis/lists/lists.factor | 21 ++++++++++++++++++++- basis/prettyprint/backend/backend.factor | 7 ++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/basis/lists/lists.factor b/basis/lists/lists.factor index 206752f7ca..fe7fa2f608 100644 --- a/basis/lists/lists.factor +++ b/basis/lists/lists.factor @@ -105,4 +105,23 @@ M: list >list ; M: sequence >list sequence>list ; -SYNTAX: L{ \ } [ sequence>list ] parse-literal ; \ No newline at end of file +: items>list ( seq -- cons-pair ) + dup empty? [ drop +nil+ ] [ + reverse unclip swap [ swap cons ] each + ] if ; + +:: (parse-list-literal) ( accum right-of-dot? -- accum ) + accum scan-token { + { "}" [ +nil+ , ] } + { "rest:" [ t (parse-list-literal) ] } + [ + parse-datum dup parsing-word? [ + V{ } clone swap execute-parsing first + ] when + , right-of-dot? [ "}" expect ] [ f (parse-list-literal) ] if ] + } case ; + +: parse-list-literal ( accum -- accum object ) + [ f (parse-list-literal) ] { } make items>list ; + +SYNTAX: L{ parse-list-literal suffix! ; diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index cd3d388205..28d4d96b8c 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -277,7 +277,12 @@ M: cons-state pprint* '[ dup cons-state? _ length _ < and ] [ uncons swap , ] while ] { } make - [ pprint* ] each nil? [ "~more~" text ] unless + [ pprint* ] each + dup list? [ + nil? [ "~more~" text ] unless + ] [ + "." text pprint* + ] if block> ] dip pprint-word block> ] check-recursion ;