File:  [gforth] / gforth / doc / makedoc.fs
Revision 1.7: download - view: text, annotated - select for diffs
Sat Mar 22 10:04:08 2003 UTC (20 years, 8 months ago) by anton
Branches: MAIN
CVS tags: HEAD
added LATEST, replaced uses of LAST @ with uses of LATEST
renamed LASTXT to LATESTXT, and changed the uses
made >NAME the primary name for >HEAD
documentation changes

\ create a documentation file

\ Copyright (C) 1995,1999,2000 Free Software Foundation, Inc.

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation; either version 2
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
\ along with this program; if not, write to the Free Software
\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.

\ the stack effect of loading this file is: ( addr u -- )
\ it takes the name of the doc-file to be generated.

\ the forth source must have the following format:
\  .... name ( stack-effect ) \ [prefix-] wordset [pronounciation]
\ \G description ...

\ The output is a file of entries that look like this:
\ make-doc [--prefix]-entry name stack-effect ) wordset [pronounciation]
\ description
\ (i.e., the entry is terminated by an empty line or the end-of-file)

\ this stuff uses the same mechanism as etags.fs, i.e., the
\ documentation is generated during compilation using a deferred
\ HEADER. It should be possible to use this togeter with etags.fs.

\ This is not very general. Input should come from stream files,
\ otherwise the results are unpredictable. It also does not detect
\ errors in the input (e.g., if there is something else on the
\ definition line) and reacts strangely to them.

\ possible improvements: we could analyse the defining word and guess
\ the stack effect. This would be handy for variables. Unfortunately,
\ we have to look back in the input buffer; we cannot use the cfa
\ because it does not exist when header is called.

\ This is ANS Forth with the following serious environmental
\ dependences: the variable LAST must contain a pointer to the last
\ header, NAME>STRING must convert that pointer to a string, and
\ HEADER must be a deferred word that is called to create the name.

r/w create-file throw value doc-file-id
\ contains the file-id of the documentation file

s" \ automatically generated by makedoc.fs" doc-file-id write-line throw

: >fileCR ( c-addr u -- )
    doc-file-id write-line throw ;
: >file    ( c-addr u -- )
    doc-file-id write-file throw ;

: \G ( -- )
    source >in @ /string >fileCR
    source >in ! drop ; immediate

: put-doc-entry ( -- )
    locals-list @ 0=	\ not in a colon def, i.e., not a local name
    latest 0<> and	\ not an anonymous (i.e. noname) header
	s" " >fileCR
	s" make-doc " >file
	>in @ >r
	[char] ( parse 2drop
	[char] ) parse
	[char] \ parse 2drop
	>in @
	bl word  dup c@
	    dup count 1- chars + c@ [char] - =
		s" --" >file
		count >file drop
		drop >in !
	    drop >in !
	latest name>string >file
	s"  )" >file
	r> >in !
    endif ;

: (doc-header) ( -- )
    defers header
    put-doc-entry ;

' (doc-header) IS header

FreeBSD-CVSweb <>