retroforth/wip/words.forth

116 lines
3.1 KiB
Text
Raw Normal View History

#!/usr/bin/env rre
This is an application for looking up documentation in the words.tsv
data set.
It's intended to be used like:
./words.forth describe s:filter
Or:
./words.forth export glossary
First, exit if the required number of argumenta are not passed.
~~~
sys:argc #2 -eq? [ #0 unix:exit ] if
~~~
If we made it this far, at least two arguments were passed. This
assumes the first argument is the type of search and the second
is name of a word, class, or other detail to search for. Grab them
and save as `QUERY` and `TARGET`.
~~~
#0 sys:argv 'QUERY s:const
#1 sys:argv 'TARGET s:const
~~~
The *words.tsv* has the following fields:
| name | 0
| data stack | 1
| address stack | 2
| float stack | 3
| general description | 4
| interpret time description | 5
| compile time description | 6
| class handler | 7
| example 1 | 8
| example 2 | 9
| namespace | 10
| interface | 11
So 11 fields. These are stored, one line per entry, with the fields as
tab separated data.
~~~
'SourceLine var
:skip (n-) [ ASCII:HT s:split drop n:inc ] times ;
:field:name (-s) @SourceLine
ASCII:HT s:split nip ;
:field:dstack (-s) @SourceLine #1 skip
ASCII:HT s:split nip ;
:field:astack (-s) @SourceLine #2 skip
ASCII:HT s:split nip ;
:field:fstack (-s) @SourceLine #3 skip
ASCII:HT s:split nip ;
:field:descr (-s) @SourceLine #4 skip
ASCII:HT s:split nip s:with-format ;
:field:itime (-s) @SourceLine #5 skip
ASCII:HT s:split nip s:with-format ;
:field:ctime (-s) @SourceLine #6 skip
ASCII:HT s:split nip s:with-format ;
:field:class (-s) @SourceLine #7 skip
ASCII:HT s:split nip ;
:field:ex1 (-s) @SourceLine #8 skip
ASCII:HT s:split nip s:with-format ;
:field:ex2 (-s) @SourceLine #9 skip
ASCII:HT s:split nip s:with-format ;
:field:namespace (-s) @SourceLine #10 skip
ASCII:HT s:split nip ;
:field:interface (-s) @SourceLine #11 skip
ASCII:HT s:split nip ;
~~~
~~~
:display-result
field:name puts nl nl
field:dstack '__Data:__%s\n s:with-format puts
field:astack '__Addr:__%s\n s:with-format puts
field:fstack '__Float:_%s\n s:with-format puts nl
field:descr puts nl nl
field:interface field:namespace field:class
'Class_Handler:_%s_|_Namespace:_%s_|_Interface_Layer:_%s\n\n
s:with-format puts
field:ex1 '{n/a} s:eq? [ 'Example_#1: puts nl field:ex1 puts nl nl ] -if
field:ex2 '{n/a} s:eq? [ 'Example_#2: puts nl field:ex2 puts nl nl ] -if ;
~~~
~~~
QUERY 'describe s:eq?
[ 'words.tsv
[ s:keep !SourceLine field:name TARGET s:eq? [ display-result ] if ] file:for-each-line
] if
QUERY 'export s:eq? 'glossary TARGET s:eq? and
[ 'words.tsv
[ s:keep !SourceLine display-result #64 [ $- putc ] times nl nl ] file:for-each-line
] if
~~~