modern: Allow :foo: and handle :> correctly. Add unit tests.

modern-harvey2
Doug Coleman 2017-08-26 11:21:09 -05:00
parent 6c5bc17c58
commit bb6ffbd9e2
2 changed files with 26 additions and 12 deletions

View File

@ -3,6 +3,7 @@
USING: modern modern.slices tools.test ;
IN: modern.tests
! Comment
{
{ { "!" "" } }
} [ "!" string>literals >strings ] unit-test
@ -18,3 +19,21 @@ IN: modern.tests
{
{ { "!" "lol" } }
} [ "!lol" string>literals >strings ] unit-test
! Colon
{
{ ":asdf:" }
} [ ":asdf:" string>literals >strings ] unit-test
{
{ { "one:" "1" } }
} [ "one: 1" string>literals >strings ] unit-test
{
{ "1" ":>" "one" }
} [ "1 :> one" string>literals >strings ] unit-test
! Acute
{
{ { "<A" { } "A>" } }
} [ "<A A>" string>literals >strings ] unit-test

View File

@ -186,18 +186,12 @@ ERROR: unexpected-terminator n string slice ;
ERROR: colon-word-must-be-all-uppercase-or-lowercase n string word ;
: read-colon ( n string slice -- n' string colon )
dup length 1 = [
dup prev-char-from-slice { CHAR: \s CHAR: \r CHAR: \n f } member? [
read-til-semicolon
] [
read-lowercase-colon
] if
] [
{
{ [ dup strict-upper? ] [ strict-upper on read-til-semicolon strict-upper off ] }
[ read-lowercase-colon ]
} cond
] if ;
{
{ [ dup strict-upper? ] [ strict-upper on read-til-semicolon strict-upper off ] }
{ [ dup ":" tail? ] [ dup ":" head? [ read-lowercase-colon ] unless ] } ! :foo: vs foo:
[ ]
} cond ;
: read-acute ( n string slice -- n' string acute )
[ matching-section-delimiter 1array lex-until ] keep swap unclip-last 3array ;
@ -234,6 +228,7 @@ ERROR: mismatched-terminator n string slice ;
{ CHAR: \\ [ read-backslash ] }
{ CHAR: \! [ read-exclamation ] }
{ CHAR: \: [
merge-slice-til-whitespace
dup strict-upper? strict-upper get and [
length swap [ - ] dip f
strict-upper off