modern: Fix case for "<PRIVATE FOO: foo PRIVATE>"
At the end of a file the length of the string is f, so this needs to be fixed up for calculations.modern-harvey2
parent
2ce052c981
commit
6fe38fde00
|
@ -164,3 +164,16 @@ IN: modern.tests
|
||||||
}
|
}
|
||||||
} [ "\"abc\"[ 0 ]" string>literals >strings ] unit-test
|
} [ "\"abc\"[ 0 ]" string>literals >strings ] unit-test
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "<FOO" { { "BAR:" { "bar" } } } "FOO>" }
|
||||||
|
}
|
||||||
|
} [ "<FOO BAR: bar FOO>" string>literals >strings ] unit-test
|
||||||
|
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{ "<FOO:" { "foo" { "BAR:" { "bar" } } } ";FOO>" }
|
||||||
|
}
|
||||||
|
} [ "<FOO: foo BAR: bar ;FOO>" string>literals >strings ] unit-test
|
||||||
|
|
|
@ -171,8 +171,13 @@ ERROR: unexpected-terminator n string slice ;
|
||||||
: section-close? ( string -- ? )
|
: section-close? ( string -- ? )
|
||||||
{
|
{
|
||||||
[ length 2 >= ]
|
[ length 2 >= ]
|
||||||
[ but-last strict-upper? ]
|
|
||||||
[ ">" tail? ]
|
[ ">" tail? ]
|
||||||
|
[
|
||||||
|
{
|
||||||
|
[ but-last strict-upper? ]
|
||||||
|
[ { [ ";" head? ] [ rest but-last strict-upper? ] } 1&& ]
|
||||||
|
} 1||
|
||||||
|
]
|
||||||
} 1&& ;
|
} 1&& ;
|
||||||
|
|
||||||
: read-til-semicolon ( n string slice -- n' string semi )
|
: read-til-semicolon ( n string slice -- n' string semi )
|
||||||
|
@ -219,6 +224,11 @@ ERROR: no-backslash-payload n string slice ;
|
||||||
ERROR: mismatched-terminator n string slice ;
|
ERROR: mismatched-terminator n string slice ;
|
||||||
: read-terminator ( n string slice -- n' string slice ) ;
|
: read-terminator ( n string slice -- n' string slice ) ;
|
||||||
|
|
||||||
|
! If we are at the end of the string, we need to be at position len instead of f
|
||||||
|
! after a read. Especially for "<FOO BAR: baz FOO>"
|
||||||
|
: ?length-and-string ( length/f string -- length string )
|
||||||
|
over [ nip [ length ] [ ] bi ] unless ; inline
|
||||||
|
|
||||||
: (lex-factor) ( n/f string slice/f ch/f -- n'/f string literal )
|
: (lex-factor) ( n/f string slice/f ch/f -- n'/f string literal )
|
||||||
{
|
{
|
||||||
{ char: \" [ read-string ] }
|
{ char: \" [ read-string ] }
|
||||||
|
@ -253,6 +263,7 @@ ERROR: mismatched-terminator n string slice ;
|
||||||
[ slice-til-whitespace drop ] dip span-slices
|
[ slice-til-whitespace drop ] dip span-slices
|
||||||
dup section-close? [
|
dup section-close? [
|
||||||
strict-upper get [
|
strict-upper get [
|
||||||
|
[ ?length-and-string ] dip
|
||||||
length swap [ - ] dip f strict-upper off
|
length swap [ - ] dip f strict-upper off
|
||||||
] when
|
] when
|
||||||
] when
|
] when
|
||||||
|
|
Loading…
Reference in New Issue