]> gitweb.factorcode.org Git - factor.git/commitdiff
CFactor documentation comments
authorSlava Pestov <slava@factorcode.org>
Sun, 29 Aug 2004 05:50:34 +0000 (05:50 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 29 Aug 2004 05:50:34 +0000 (05:50 +0000)
TODO.FACTOR.txt
library/platform/jvm/prettyprint.factor
library/platform/native/parse-syntax.factor
library/platform/native/prettyprint.factor
library/platform/native/words.factor
library/prettyprint.factor

index 07d4f8d7d38b29672d1519dfc1281dcb814ed500..2d7180aa60f89700bda0566358d442d8462dca29 100644 (file)
@@ -5,7 +5,6 @@
   - directory listings\r
   - index.html\r
   - if a directory is requested and URL does not end with /, redirect\r
-- doc strings with native factor\r
 \r
 + bignums:\r
 \r
@@ -47,6 +46,7 @@
 \r
 + listener/plugin:\r
 \r
+- inferior hangs\r
 - plugin should not exit jEdit on fatal errors\r
 - auto insert USE:\r
 - balance needs USE:\r
index 1545e242f7ddb66096c19b1e1d9021e5b6f0f0ad..082f407934e6938a26b7b8fcbb31191fa7276d73 100644 (file)
@@ -35,6 +35,13 @@ USE: stdio
 USE: unparser
 USE: words
 
+: prettyprint-:; ( indent word list -- indent )
+    over >r >r dup
+    >r dupd prettyprint-IN: prettyprint-: r>
+    prettyprint-word prettyprint-space
+    r>
+    prettyprint-list prettyprint-; r> prettyprint-plist ;
+
 : prettyprint-~<< ( indent -- indent )
     "~<<" write prettyprint-space
     tab-size + ;
index 8ab770adf721a25e953b1b1361f596533787f7d1..325738811e119de2827eda7b728f4860ab28af19 100644 (file)
@@ -25,8 +25,6 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-! Parsing words. 'builtins' is a stupid vocabulary name now
-! that it does not contain Java words anymore!
 IN: syntax
 
 USE: combinators
@@ -44,6 +42,10 @@ USE: words
 USE: vectors
 USE: unparser
 
+! The variable "in-definition" is set inside a : ... ;.
+! ( and #! then add "stack-effect" and "documentation"
+! properties to the current word if it is set.
+
 ! Constants
 : t t parsed ; parsing
 : f f parsed ; parsing
@@ -65,7 +67,9 @@ USE: unparser
 : POSTPONE: ( -- ) scan parse-word parsed ; parsing
 
 ! Colon defs
-: CREATE scan "in" get create ;
+: CREATE
+    scan "in" get create dup set-word
+    f "documentation" pick set-word-property ;
 
 : remember-where ( word -- )
     "line-number" get "line" pick set-word-property
@@ -75,13 +79,15 @@ USE: unparser
 
 : :
     #! Begin a word definition. Word name follows.
-    CREATE dup remember-where [ ] ; parsing
+    CREATE dup remember-where [ ]
+    "in-definition" on ; parsing
 
 : ;-hook ( -- quot )
     ";-hook" get [ [ define-compound ] ] unless* ;
 
 : ;
     #! End a word definition.
+    "in-definition" off
     nreverse
     ;-hook call ; parsing
 
@@ -146,9 +152,30 @@ USE: unparser
     scan str>number scan str>number rect> parsed "}" expect ;
 
 ! Comments
-: ( ")" until drop ; parsing
+: doc-comment-here? ( parsed -- ? )
+    not "in-definition" get and ;
+
+: parsed-stack-effect ( parsed str -- parsed )
+    over doc-comment-here? [
+        "stack-effect" word set-word-property
+    ] [
+        drop
+    ] ifte ;
+
+: ( ")" until parsed-stack-effect ; parsing
+
 : ! until-eol drop ; parsing
-: #! until-eol drop ; parsing
+
+: parsed-documentation ( parsed str -- parsed )
+    over doc-comment-here? [
+        "documentation" word word-property [
+            swap "\n" swap cat3
+        ] when* "documentation" word set-word-property
+    ] [
+        drop
+    ] ifte ;
+
+: #! until-eol parsed-documentation ; parsing
 
 ! Reading numbers in other bases
 
index 2502437605dbe3080142be6ddc4afc2f711268e9..42b8d831b6b2f7b4fc628492e2c949bb0e58c2c1 100644 (file)
 
 IN: prettyprint
 USE: combinators
+USE: lists
 USE: parser
 USE: prettyprint
 USE: stack
 USE: stdio
+USE: strings
 USE: unparser
 USE: words
 
+: prettyprint-docs ( indent word -- indent )
+    [
+        stack-effect [
+            <% CHAR: ( % % CHAR: ) % %> prettyprint-comment
+            dup prettyprint-newline
+        ] when*
+    ] keep
+
+    documentation [
+        "\n" split [
+            "#!" swap cat2 prettyprint-comment
+            dup prettyprint-newline
+        ] each
+    ] when* ;
+
 : see-compound ( word -- )
-    0 swap dup word-parameter prettyprint-:;
-    prettyprint-newline ;
+    0 swap
+    [ dupd prettyprint-IN: prettyprint-: ] keep
+    [ prettyprint-word prettyprint-space ] keep
+    [ prettyprint-docs ] keep
+    [ word-parameter prettyprint-list prettyprint-; ] keep
+    prettyprint-plist prettyprint-newline ;
 
 : see-primitive ( word -- )
     "PRIMITIVE: " write unparse print ;
@@ -45,6 +66,7 @@ USE: words
     drop "Not defined" print ;
 
 : see ( name -- )
+    #! Show a word definition.
     intern
     [
         [ compound? ] [ see-compound ]
index 47e6c954f22aa2db69c5e9fb3121b21e867f44fd..f2a62c326a50387332adf324ee76512776cac9c1 100644 (file)
@@ -59,6 +59,11 @@ USE: stack
 
 : define-compound ( word def -- )
     #! Define a compound word at runtime.
-    over set-word
     over set-word-parameter
     1 swap set-word-primitive ;
+
+: stack-effect ( word -- str )
+    "stack-effect" swap word-property ;
+
+: documentation ( word -- str )
+    "documentation" swap word-property ;
index 709b4d4473f4c05c9eacc11952541a7f2ad460c0..a69c7fde61399829160d8e9d6c49ee609d2dc166 100644 (file)
@@ -186,10 +186,9 @@ DEFER: prettyprint*
 : prettyprint-vocab ( vocab -- )
     dup vocab-attrs write-attr ;
 
-: prettyprint-IN: ( indent word -- indent )
+: prettyprint-IN: ( indent word -- )
     "IN:" write prettyprint-space
-    word-vocabulary prettyprint-vocab
-    dup prettyprint-newline ;
+    word-vocabulary prettyprint-vocab prettyprint-newline ;
 
 : prettyprint-: ( indent -- indent )
     ":" write prettyprint-space
@@ -204,14 +203,6 @@ DEFER: prettyprint*
     "inline" over word-property [ " inline" write ] when
     drop ;
 
-: prettyprint-:; ( indent word list -- indent )
-    over >r >r dup
-    >r prettyprint-IN: prettyprint-: r>
-    prettyprint-word
-    native? [ dup prettyprint-newline ] [ prettyprint-space ] ifte
-    r>
-    prettyprint-list prettyprint-; r> prettyprint-plist ;
-
 : . ( obj -- )
     [
         "prettyprint-single-line" on