From 5e1295f89eddbca2a61172b31ac029f33c5d4c61 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 12 Oct 2017 19:26:07 -0500 Subject: [PATCH] modern: Add error checking for enough tokens. modern.slices had a bug in find-from* where it was taking the length of a quotation instead of the original string. --- extra/modern/modern.factor | 7 ++++++- extra/modern/slices/slices.factor | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/extra/modern/modern.factor b/extra/modern/modern.factor index 4518bbfcf7..1f3dfc1280 100644 --- a/extra/modern/modern.factor +++ b/extra/modern/modern.factor @@ -138,12 +138,16 @@ MACRO:: read-matched ( ch -- quot: ( n string tag -- n' string slice' ) ) [ ")" sequence= ] } 1|| ; +ERROR: expected-length-tokens n string length seq ; +: ensure-no-false ( n string seq -- n string seq ) + dup [ length 0 > ] all? [ [ length ] keep expected-length-tokens ] unless ; + ERROR: token-expected n string obj ; ERROR: unexpected-terminator n string slice ; : read-lowercase-colon ( n string slice -- n' string lowercase-colon ) dup [ char: \: = ] count-tail '[ - _ [ lex-factor ] replicate dup [ token-expected ] unless + _ [ lex-factor ] replicate ensure-no-false dup [ token-expected ] unless dup terminator? [ unexpected-terminator ] when ] dip swap 2array ; @@ -214,6 +218,7 @@ ERROR: no-backslash-payload n string slice ; dup [ char: \\ = ] count-tail '[ _ [ skip-blank-from slice-til-whitespace drop ] replicate + ensure-no-false dup [ no-backslash-payload ] unless ] dip swap 2array ] when ; diff --git a/extra/modern/slices/slices.factor b/extra/modern/slices/slices.factor index 6d02be73fa..d52e4ca14e 100644 --- a/extra/modern/slices/slices.factor +++ b/extra/modern/slices/slices.factor @@ -63,7 +63,7 @@ ERROR: unexpected-end n string ; next-char-from 2nip ; : find-from* ( ... n seq quot: ( ... elt -- ... ? ) -- ... i elt ? ) - [ find-from ] keep + [ find-from ] 2keep drop pick [ drop t ] [ length -rot nip f ] if ; inline : skip-blank-from ( n string -- n' string )