Add M\ syntax for method literals
							parent
							
								
									42f3b0e16e
								
							
						
					
					
						commit
						3752c706da
					
				| 
						 | 
				
			
			@ -41,18 +41,18 @@ M: effect pprint* effect>string "(" ")" surround text ;
 | 
			
		|||
: pprint-prefix ( word quot -- )
 | 
			
		||||
    <block swap pprint-word call block> ; inline
 | 
			
		||||
 | 
			
		||||
M: parsing-word pprint*
 | 
			
		||||
    \ POSTPONE: [ pprint-word ] pprint-prefix ;
 | 
			
		||||
 | 
			
		||||
M: word pprint*
 | 
			
		||||
    dup parsing-word? [
 | 
			
		||||
        \ POSTPONE: [ pprint-word ] pprint-prefix
 | 
			
		||||
    ] [
 | 
			
		||||
        {
 | 
			
		||||
            [ "break-before" word-prop line-break ]
 | 
			
		||||
            [ pprint-word ]
 | 
			
		||||
            [ ?start-group ]
 | 
			
		||||
            [ ?end-group ]
 | 
			
		||||
            [ "break-after" word-prop line-break ]
 | 
			
		||||
        } cleave
 | 
			
		||||
    ] if ;
 | 
			
		||||
    [ pprint-word ] [ ?start-group ] [ ?end-group ] tri ;
 | 
			
		||||
 | 
			
		||||
M: method-body pprint*
 | 
			
		||||
    <block
 | 
			
		||||
    \ M\ pprint-word
 | 
			
		||||
    [ "method-class" word-prop pprint-word ]
 | 
			
		||||
    [ "method-generic" word-prop pprint-word ] bi
 | 
			
		||||
    block> ;
 | 
			
		||||
 | 
			
		||||
M: real pprint* number>string text ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -206,8 +206,8 @@ M: curry pprint* pprint-object ;
 | 
			
		|||
M: compose pprint* pprint-object ;
 | 
			
		||||
 | 
			
		||||
M: wrapper pprint*
 | 
			
		||||
    dup wrapped>> word? [
 | 
			
		||||
        <block \ \ pprint-word wrapped>> pprint-word block>
 | 
			
		||||
    ] [
 | 
			
		||||
        pprint-object
 | 
			
		||||
    ] if ;
 | 
			
		||||
    {
 | 
			
		||||
        { [ dup wrapped>> method-body? ] [ wrapped>> pprint* ] }
 | 
			
		||||
        { [ dup wrapped>> word? ] [ <block \ \ pprint-word wrapped>> pprint-word block> ] }
 | 
			
		||||
        [ pprint-object ]
 | 
			
		||||
    } cond ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -180,28 +180,6 @@ DEFER: parse-error-file
 | 
			
		|||
    "string-layout-test" string-layout check-see
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
! Define dummy words for the below...
 | 
			
		||||
: <NSRect> ( a b c d -- e ) ;
 | 
			
		||||
: <PixelFormat> ( -- fmt ) ;
 | 
			
		||||
: send ( obj -- ) ;
 | 
			
		||||
 | 
			
		||||
\ send soft "break-after" set-word-prop
 | 
			
		||||
 | 
			
		||||
: final-soft-break-test ( -- str )
 | 
			
		||||
    {
 | 
			
		||||
        "USING: kernel sequences ;"
 | 
			
		||||
        "IN: prettyprint.tests"
 | 
			
		||||
        ": final-soft-break-layout ( class dim -- view )"
 | 
			
		||||
        "    [ \"alloc\" send 0 0 ] dip first2 <NSRect>"
 | 
			
		||||
        "    <PixelFormat> \"initWithFrame:pixelFormat:\" send"
 | 
			
		||||
        "    dup 1 \"setPostsBoundsChangedNotifications:\" send"
 | 
			
		||||
        "    dup 1 \"setPostsFrameChangedNotifications:\" send ;"
 | 
			
		||||
    } ;
 | 
			
		||||
 | 
			
		||||
[ t ] [
 | 
			
		||||
    "final-soft-break-layout" final-soft-break-test check-see
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
: narrow-test ( -- str )
 | 
			
		||||
    {
 | 
			
		||||
        "USING: arrays combinators continuations kernel sequences ;"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,6 +62,7 @@ IN: bootstrap.syntax
 | 
			
		|||
    "W{"
 | 
			
		||||
    "["
 | 
			
		||||
    "\\"
 | 
			
		||||
    "M\\"
 | 
			
		||||
    "]"
 | 
			
		||||
    "delimiter"
 | 
			
		||||
    "f"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -167,6 +167,8 @@ $nl
 | 
			
		|||
ARTICLE: "syntax" "Syntax"
 | 
			
		||||
"Factor has two main forms of syntax: " { $emphasis "definition" } " syntax and " { $emphasis "literal" } " syntax. Code is data, so the syntax for code is a special case of object literal syntax. This section documents literal syntax. Definition syntax is covered in " { $link "words" } ". Extending the parser is the main topic of " { $link "parser" } "."
 | 
			
		||||
{ $subsection "parser-algorithm" }
 | 
			
		||||
{ $subsection "vocabulary-search" }
 | 
			
		||||
{ $subsection "top-level-forms" }
 | 
			
		||||
{ $subsection "syntax-comments" }
 | 
			
		||||
{ $subsection "syntax-literals" }
 | 
			
		||||
{ $subsection "syntax-immediate" } ;
 | 
			
		||||
| 
						 | 
				
			
			@ -762,7 +764,9 @@ HELP: >>
 | 
			
		|||
{ $description "Marks the end of a parse time code block." } ;
 | 
			
		||||
 | 
			
		||||
HELP: call-next-method
 | 
			
		||||
{ $syntax "call-next-method" }
 | 
			
		||||
{ $description "Calls the next applicable method. Only valid inside a method definition. The values at the top of the stack are passed on to the next method, and they must be compatible with that method's class specializer." }
 | 
			
		||||
{ $notes "This word looks like an ordinary word but it is a parsing word. It cannot be factored out of a method definition, since the code expansion references the current method object directly." }
 | 
			
		||||
{ $errors
 | 
			
		||||
    "Throws a " { $link no-next-method } " error if this is the least specific method, and throws an " { $link inconsistent-next-method } " error if the values at the top of the stack are not compatible with the current method's specializer."
 | 
			
		||||
} ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -104,6 +104,7 @@ IN: bootstrap.syntax
 | 
			
		|||
 | 
			
		||||
    "POSTPONE:" [ scan-word parsed ] define-core-syntax
 | 
			
		||||
    "\\" [ scan-word <wrapper> parsed ] define-core-syntax
 | 
			
		||||
    "M\\" [ scan-word scan-word method <wrapper> parsed ] define-core-syntax
 | 
			
		||||
    "inline" [ word make-inline ] define-core-syntax
 | 
			
		||||
    "recursive" [ word make-recursive ] define-core-syntax
 | 
			
		||||
    "foldable" [ word make-foldable ] define-core-syntax
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue