modern: working on compound tokens

modern-harvey2
Doug Coleman 2017-09-04 11:04:55 -05:00
parent 2773cbf889
commit d3497b9f6b
3 changed files with 40 additions and 6 deletions

View File

@ -139,3 +139,28 @@ IN: modern.tests
{
{ { "\"" "google.com" "\"" } }
} [ [[ "google.com" ]] string>literals >strings ] unit-test
! Concatenated syntax
{
{
{ "(" { "a" "b" } ")" }
{ "[" { "a" "b" "+" } "]" }
{ "(" { "c" } ")" }
}
} [ "( a b )[ a b + ]( c )" string>literals >strings ] unit-test
{
{
{ "(" { "a" "b" } ")" }
{ "[" { "a" "b" "+" } "]" }
{ "(" { "c" } ")" }
}
} [ "( a b ) [ a b + ] ( c )" string>literals >strings ] unit-test
{
{
{ "\"" "abc" "\"" }
{ "[" { "0" } "]" }
}
} [ "\"abc\"[ 0 ]" string>literals >strings ] unit-test

View File

@ -267,6 +267,9 @@ ERROR: mismatched-terminator n string slice ;
{ char: \[ [ read-bracket ] }
{ char: \{ [ read-brace ] }
{ char: \( [ read-paren ] }
{ char: \] [ ] }
{ char: \} [ ] }
{ char: \) [ ] }
{ char: \s [ read-token-or-whitespace ] }
{ char: \r [ read-token-or-whitespace ] }
{ char: \n [ read-token-or-whitespace ] }
@ -275,9 +278,11 @@ ERROR: mismatched-terminator n string slice ;
: lex-factor ( n/f string -- n'/f string literal )
over [
skip-whitespace "\"\\!:[{(<>\s\r\n" slice-til-either
! skip-whitespace
"\"\\!:[{(]})<>\s\r\n" slice-til-either
! \foo foo\bar \foo{
dup char: \\ = [
dup char: \\ = [
drop
! foo\ so far, could be foo\bar{
! remove the \ and continue til delimiter/eof

View File

@ -1,11 +1,15 @@
! Copyright (C) 2017 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs constructors continuations fry io
io.encodings.utf8 io.files io.streams.string kernel modern
modern.paths modern.slices multiline namespaces prettyprint
sequences sequences.extras splitting strings ;
USING: accessors arrays assocs combinators.short-circuit
constructors continuations fry io io.encodings.utf8 io.files
io.streams.string kernel modern modern.paths modern.slices
multiline namespaces prettyprint sequences sequences.extras
splitting strings ;
IN: modern.out
: token? ( obj -- ? )
{ [ slice? ] [ seq>> string? ] } 1&& ;
TUPLE: renamed slice string ;
CONSTRUCTOR: <renamed> renamed ( slice string -- obj ) ;