modern: Reduce a lot of error words.

modern-harvey3
Doug Coleman 2019-10-16 17:56:28 -05:00
parent 1e4723ad2d
commit 1c4bdd74a6
3 changed files with 19 additions and 31 deletions

View File

@ -7,13 +7,8 @@ sequences.generalizations sets shuffle splitting strings
syntax.modern unicode vocabs.loader ; syntax.modern unicode vocabs.loader ;
IN: modern IN: modern
ERROR: unexpected-eof string n ;
ERROR: long-opening-mismatch tag open string n ch ; ERROR: long-opening-mismatch tag open string n ch ;
ERROR: lex-expected-but-got-eof string n expected ; ERROR: unexpected-terminator string n slice ; ! ] } ) ;
ERROR: expected-length-tokens string n length seq ;
ERROR: token-expected string n obj ;
ERROR: unexpected-terminator string n slice ;
ERROR: no-backslash-payload string n slice ;
ERROR: compound-syntax-disallowed seq n obj ; ERROR: compound-syntax-disallowed seq n obj ;
! (( )) [[ ]] {{ }} ! (( )) [[ ]] {{ }}
@ -62,7 +57,7 @@ DEFER: lex-factor
drop t ! loop again? drop t ! loop again?
] if ] if
] [ ] [
_ _ _ lex-expected-but-got-eof _ _ _ unexpected-eof
] if* ] if*
] loop ] loop
] { } make ; ] { } make ;
@ -123,14 +118,14 @@ MACRO:: read-matched ( ch -- quot: ( string n tag -- string n' slice' ) )
{ char: \\ [ drop next-char-from drop read-string-payload ] } { char: \\ [ drop next-char-from drop read-string-payload ] }
} case } case
] [ ] [
unexpected-eof f unexpected-eof
] if ; ] if ;
:: read-string ( string n tag -- string n' seq ) :: read-string ( string n tag -- string n' seq )
string n read-string-payload nip :> n' string n read-string-payload nip :> n'
string string
n' n'
n' [ string n unexpected-eof ] unless n' [ string n f unexpected-eof ] unless
n n' 1 - string <slice> n n' 1 - string <slice>
n' 1 - n' string <slice> n' 1 - n' string <slice>
tag -rot 3array ; tag -rot 3array ;
@ -150,19 +145,18 @@ MACRO:: read-matched ( ch -- quot: ( string n tag -- string n' slice' ) )
[ ")" sequence= ] [ ")" sequence= ]
} 1|| ; } 1|| ;
: ensure-no-false ( string n seq -- string n seq ) : ensure-tokens ( string n seq -- string n seq )
dup [ length 0 > ] all? dup [ terminator? ] any? [ unexpected-terminator ] when ;
[ [ length ] keep expected-length-tokens ] unless ;
: read-lowercase-colon ( string n slice -- string n' lowercase-colon ) : read-lowercase-colon ( string n slice -- string n' lowercase-colon )
dup [ char: \: = ] count-tail dup [ char: \: = ] count-tail
'[ '[
_ [ _ [
slice-til-not-whitespace drop ! XXX: whitespace here slice-til-not-whitespace drop ! XXX: whitespace here
[ dup [ unexpected-eof ] unless ] dip [ dup [ f unexpected-eof ] unless ] dip
[ lex-factor ] dip swap 2array [ lex-factor ] dip swap 2array
] replicate ] replicate
dup terminator? [ unexpected-terminator ] when ensure-tokens
] dip swap 2array ; ] dip swap 2array ;
: (strict-upper?) ( string -- ? ) : (strict-upper?) ( string -- ? )
@ -340,9 +334,12 @@ MACRO:: read-matched ( ch -- quot: ( string n tag -- string n' slice' ) )
! \ foo, M\ foo ! \ foo, M\ foo
dup [ char: \\ = ] count-tail dup [ char: \\ = ] count-tail
'[ '[
_ [ slice-til-not-whitespace drop [ slice-til-whitespace drop ] dip swap 2array ] replicate _ [
ensure-no-false slice-til-not-whitespace drop
dup [ no-backslash-payload ] unless [ slice-til-whitespace drop ] dip
swap 2array
] replicate
ensure-tokens
] dip swap 2array ] dip swap 2array
] when ; ] when ;

View File

@ -27,20 +27,10 @@ IN: modern.slices.tests
"foo:" 3 slice-til-whitespace "foo:" 3 slice-til-whitespace
] unit-test ] unit-test
{ { "foo " f T{ slice f 0 4 "foo " } f } [
"foo "
f
T{ slice f 0 4 "foo " }
f
} [
"foo " 0 [ blank? ] slice-until-include "foo " 0 [ blank? ] slice-until-include
] unit-test ] unit-test
{ { "foo " 3 T{ slice f 0 3 "foo " } 32 } [
"foo "
3
T{ slice f 0 3 "foo " }
32
} [
"foo " 0 [ blank? ] slice-until-exclude "foo " 0 [ blank? ] slice-until-exclude
] unit-test ] unit-test

View File

@ -4,6 +4,8 @@ USING: accessors assocs fry kernel locals math sequences
sequences.deep sequences.extras strings unicode sequences.private ; sequences.deep sequences.extras strings unicode sequences.private ;
IN: modern.slices IN: modern.slices
ERROR: unexpected-eof string n expected ;
: ?1- ( n/f -- n'/f ) dup [ 1 - ] when ; : ?1- ( n/f -- n'/f ) dup [ 1 - ] when ;
: ?1+ ( n/f -- n'/f ) dup [ 1 + ] when ; : ?1+ ( n/f -- n'/f ) dup [ 1 + ] when ;
@ -33,9 +35,8 @@ IN: modern.slices
: slice-before ( slice -- slice' ) : slice-before ( slice -- slice' )
[ drop 0 ] [ from>> ] [ seq>> ] tri <slice> ; [ drop 0 ] [ from>> ] [ seq>> ] tri <slice> ;
ERROR: unexpected-end string n ;
: nth-check-eof ( string n -- nth ) : nth-check-eof ( string n -- nth )
2dup ?nth-of [ 2nip ] [ unexpected-end ] if* ; 2dup ?nth-of [ 2nip ] [ f unexpected-eof ] if* ;
! Allow eof ! Allow eof
: next-char-from ( string n/f -- string n'/f ch/f ) : next-char-from ( string n/f -- string n'/f ch/f )