modern: basis works with vocabs>identifiers

basis-vocabs [ dup . flush vocab>identifiers ] map
modern-harvey2
Doug Coleman 2017-12-24 19:16:13 -08:00
parent b865681a39
commit a35dd209c3
6 changed files with 45 additions and 12 deletions

View File

@ -74,7 +74,7 @@ C: <cocoa-protocol> cocoa-protocol
SYNTAX: \COCOA-PROTOCOL: SYNTAX: \COCOA-PROTOCOL:
scan-token <cocoa-protocol> suffix! ; scan-token <cocoa-protocol> suffix! ;
SYMBOL: ;CLASS> SYMBOL: \;CLASS>
SYNTAX: \<CLASS: SYNTAX: \<CLASS:
scan-token scan-token

View File

@ -139,7 +139,7 @@ SYNTAX: DEFINES-PRIVATE [ begin-private create-word-in end-private ] (INTERPOLAT
SYNTAX: DEFINES-CLASS [ create-class-in ] (INTERPOLATE) ; SYNTAX: DEFINES-CLASS [ create-class-in ] (INTERPOLATE) ;
DEFER: ;FUNCTOR> delimiter DEFER: \;FUNCTOR> delimiter
<PRIVATE <PRIVATE

View File

@ -241,7 +241,7 @@ SYNTAX: \UNIT-TEST:
TUPLE: unit-test-failed-section quot ; TUPLE: unit-test-failed-section quot ;
CONSTRUCTOR: <unit-test-failed-section> unit-test-failed-section ( quot -- obj ) ; CONSTRUCTOR: <unit-test-failed-section> unit-test-failed-section ( quot -- obj ) ;
SYMBOL: UNIT-TEST-FAILED> SYMBOL: \UNIT-TEST-FAILED>
SYNTAX: \<UNIT-TEST-FAILED SYNTAX: \<UNIT-TEST-FAILED
\ UNIT-TEST-FAILED> parse-until <unit-test-failed-section> suffix! ; \ UNIT-TEST-FAILED> parse-until <unit-test-failed-section> suffix! ;

View File

@ -308,9 +308,6 @@ GENERIC: tuple>identifiers ( obj -- obj' )
M: comment tuple>identifiers drop f ; M: comment tuple>identifiers drop f ;
M: section tuple>identifiers
payload>> [ tuple>identifiers ] map sift ;
M: identifier tuple>identifiers drop f ; M: identifier tuple>identifiers drop f ;
M: lower-colon tuple>identifiers drop f ; M: lower-colon tuple>identifiers drop f ;
M: escaped-object tuple>identifiers drop f ; M: escaped-object tuple>identifiers drop f ;
@ -318,6 +315,15 @@ M: double-quote tuple>identifiers drop f ;
M: single-bracket tuple>identifiers drop f ; M: single-bracket tuple>identifiers drop f ;
M: single-brace tuple>identifiers drop f ; M: single-brace tuple>identifiers drop f ;
M: single-paren tuple>identifiers drop f ; M: single-paren tuple>identifiers drop f ;
M: double-bracket tuple>identifiers drop f ;
M: double-brace tuple>identifiers drop f ;
M: double-paren tuple>identifiers drop f ;
M: section tuple>identifiers
payload>> [ tuple>identifiers ] map sift ;
M: named-section tuple>identifiers
payload>> [ tuple>identifiers ] map sift ;
ERROR: upper-colon-identifer-expected obj ; ERROR: upper-colon-identifer-expected obj ;
ERROR: unknown-upper-colon upper-colon string ; ERROR: unknown-upper-colon upper-colon string ;
@ -331,7 +337,10 @@ M: upper-colon tuple>identifiers
{ "IN" [ drop f ] } { "IN" [ drop f ] }
{ "M" [ drop f ] } { "M" [ drop f ] }
{ "INSTANCE" [ drop f ] } { "INSTANCE" [ drop f ] }
{ "ARTICLE" [ drop f ] } ! TODO: Should be a word imo
{ "ABOUT" [ drop f ] } ! TODO: Should be a word imo
{ "ROMAN-OP" [ ?first name>> "roman" prepend ] } { "ROMAN-OP" [ ?first name>> "roman" prepend ] }
{ "TYPEDEF" [ ?second name>> ] }
[ drop ?first name>> ] [ drop ?first name>> ]
} case nip ; } case nip ;

View File

@ -3,6 +3,23 @@
USING: modern modern.slices multiline tools.test ; USING: modern modern.slices multiline tools.test ;
IN: modern.tests IN: modern.tests
{ f } [ "" upper-colon? ] unit-test
{ t } [ ":" upper-colon? ] unit-test
{ t } [ "::" upper-colon? ] unit-test
{ t } [ ":::" upper-colon? ] unit-test
{ t } [ "FOO:" upper-colon? ] unit-test
{ t } [ "FOO::" upper-colon? ] unit-test
{ t } [ "FOO:::" upper-colon? ] unit-test
{ f } [ "\\" upper-colon? ] unit-test
{ f } [ "\\:" upper-colon? ] unit-test
{ f } [ "\\::" upper-colon? ] unit-test
{ f } [ "\\:::" upper-colon? ] unit-test
{ f } [ "\\FOO:" upper-colon? ] unit-test
{ f } [ "\\FOO::" upper-colon? ] unit-test
{ f } [ "\\FOO:::" upper-colon? ] unit-test
! Comment ! Comment
{ {
{ { "!" "" } } { { "!" "" } }

View File

@ -181,15 +181,21 @@ ERROR: unexpected-terminator n string slice ;
} 1&& ; } 1&& ;
: upper-colon? ( string -- ? ) : upper-colon? ( string -- ? )
dup { [ length 0 > ] [ [ char: \: = ] all? ] } 1&& [
drop t
] [
{ {
[ length 2 >= ] [ length 2 >= ]
[ "\\" head? not ] ! XXX: good?
[ ":" tail? ] [ ":" tail? ]
[ dup [ char: \: = ] find drop head strict-upper? ] [ dup [ char: \: = ] find drop head strict-upper? ]
} 1&& ; } 1&&
] if ;
: section-close? ( string -- ? ) : section-close? ( string -- ? )
{ {
[ length 2 >= ] [ length 2 >= ]
[ "\\" head? not ] ! XXX: good?
[ ">" tail? ] [ ">" tail? ]
[ [
{ {
@ -296,7 +302,8 @@ DEFER: lex-factor-top*
! A: B: then interrupt the current parser ! A: B: then interrupt the current parser
! A: b: then keep going ! A: b: then keep going
merge-slice-til-whitespace merge-slice-til-whitespace
dup upper-colon? dup { [ upper-colon? ] [ ":" = ] } 1||
! dup upper-colon?
[ rewind-slice f ] [ rewind-slice f ]
[ read-colon ] if [ read-colon ] if
] } ] }