Fix splitting nested words

* geesh/word.scm (split-fields): Move handling of list words into
'wedge-apart' so that they get handled in recursive calls.
* tests/word.scm: Add a test for this.
This commit is contained in:
Timothy Sample 2018-11-10 17:35:41 -05:00
parent 765e91eb88
commit 3e6d7830a9
2 changed files with 15 additions and 9 deletions

View File

@ -83,19 +83,21 @@ in the string @var{ifs}."
(((? string? h) . t)
(loop t (cons `(<sh-quote> ,h) acc))))))
(define (wedge-apart qword-part)
(match qword-part
(define (wedge-apart qword)
(match qword
(('<sh-quote> quote) (wedge-apart-quote quote))
(('<sh-at> vals) (apply append (infix '(wedge) (map wedge-apart vals))))
("" '())
(str (let ((str-parts (string-split str ifs?)))
(if (every string-null? str-parts)
'(wedge)
(filter (lambda (x)
(or (eq? x 'wedge) (not (string-null? x))))
(infix 'wedge str-parts)))))))
((? string? str)
(let ((str-parts (string-split str ifs?)))
(if (every string-null? str-parts)
'(wedge)
(filter (lambda (x)
(or (eq? x 'wedge) (not (string-null? x))))
(infix 'wedge str-parts)))))
(_ (append-map wedge-apart qword))))
(let ((wedged (append-map wedge-apart (normalize-word qword))))
(let ((wedged (wedge-apart qword)))
(filter pair? (list-split wedged 'wedge))))
(define (argument-separator ifs)

View File

@ -84,6 +84,10 @@ the `set' built-in for details on these options.)"
'("hi_how" "are_you")
(expand-word #f '("hi_" "how are" "_you")))
(test-equal "Handles nested lists"
'("foo")
(expand-word #f '("f" ("oo"))))
;;; Quotes.