Stricter help.lint

db4
Slava Pestov 2009-01-27 04:11:43 -06:00
parent 9935c8f3c0
commit c93e56d893
4 changed files with 52 additions and 38 deletions

View File

@ -11,7 +11,7 @@ HELP: eval>string
{ $description "Evaluates the Factor code in " { $snippet "str" } " with " { $link output-stream } " rebound to a string output stream, then outputs the resulting string." } ; { $description "Evaluates the Factor code in " { $snippet "str" } " with " { $link output-stream } " rebound to a string output stream, then outputs the resulting string." } ;
ARTICLE: "eval" "Evaluating strings at runtime" ARTICLE: "eval" "Evaluating strings at runtime"
"Evaluating strings at runtime:" "The " { $vocab-link "eval" } " vocabulary implements support for evaluating strings at runtime."
{ $subsection eval } { $subsection eval }
{ $subsection eval>string } ; { $subsection eval>string } ;

View File

@ -0,0 +1,4 @@
IN: eval.tests
USING: eval tools.test ;
[ "4\n" ] [ "USING: math prettyprint ; 2 2 + ." eval>string ] unit-testv

View File

@ -1,14 +1,24 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: splitting parser compiler.units kernel namespaces USING: splitting parser compiler.units kernel namespaces
debugger io.streams.string ; debugger io.streams.string fry ;
IN: eval IN: eval
: parse-string ( str -- )
[ string-lines parse-lines ] with-compilation-unit ;
: (eval) ( str -- )
parse-string call ;
: eval ( str -- ) : eval ( str -- )
[ string-lines parse-fresh ] with-compilation-unit call ; [ (eval) ] with-file-vocabs ;
: (eval>string) ( str -- output )
[
"quiet" on
parser-notes off
'[ _ (eval) ] try
] with-string-writer ;
: eval>string ( str -- output ) : eval>string ( str -- output )
[ [ (eval>string) ] with-file-vocabs ;
parser-notes off
[ [ eval ] keep ] try drop
] with-string-writer ;

View File

@ -9,15 +9,17 @@ continuations classes.predicate macros math sets eval
vocabs.parser words.symbol values ; vocabs.parser words.symbol values ;
IN: help.lint IN: help.lint
SYMBOL: vocabs-quot
: check-example ( element -- ) : check-example ( element -- )
rest [ [
but-last "\n" join 1vector rest [
[ but-last "\n" join 1vector
use [ clone ] change [ (eval>string) ] with-datastack
[ eval>string ] with-datastack peek "\n" ?tail drop
] with-scope peek "\n" ?tail drop ] keep
] keep peek assert=
peek assert= ; ] vocabs-quot get call ;
: check-examples ( element -- ) : check-examples ( element -- )
\ $example swap elements [ check-example ] each ; \ $example swap elements [ check-example ] each ;
@ -79,46 +81,44 @@ IN: help.lint
] each ; ] each ;
: check-rendering ( element -- ) : check-rendering ( element -- )
[ print-topic ] with-string-writer drop ; [ print-content ] with-string-writer drop ;
: check-markup ( element -- )
[ check-rendering ]
[ check-examples ]
[ check-modules ]
tri ;
: all-word-help ( words -- seq ) : all-word-help ( words -- seq )
[ word-help ] filter ; [ word-help ] filter ;
TUPLE: help-error topic error ; TUPLE: help-error error topic ;
C: <help-error> help-error C: <help-error> help-error
M: help-error error. M: help-error error.
"In " write dup topic>> pprint nl [ "In " write topic>> pprint nl ]
error>> error. ; [ error>> error. ]
bi ;
: check-something ( obj quot -- ) : check-something ( obj quot -- )
flush [ <help-error> , ] recover ; inline flush '[ _ assert-depth ] swap '[ _ <help-error> , ] recover ; inline
: check-word ( word -- ) : check-word ( word -- )
[ with-file-vocabs ] vocabs-quot set
dup word-help [ dup word-help [
[ dup '[
dup word-help '[ _ dup word-help
_ _ { [ check-values ]
[ check-values ] [ nip [ check-see-also ] [ check-markup ] bi ] 2bi
[ nip [ check-examples ] [ check-see-also ] bi ]
[ [ check-rendering ] [ check-modules ] bi* ]
} 2cleave
] assert-depth
] check-something ] check-something
] [ drop ] if ; ] [ drop ] if ;
: check-words ( words -- ) [ check-word ] each ; : check-words ( words -- ) [ check-word ] each ;
: check-article ( article -- ) : check-article ( article -- )
[ [ with-interactive-vocabs ] vocabs-quot set
dup article-content dup '[ _ article-content check-markup ] check-something ;
'[
_ check-rendering
_ [ check-modules ] [ check-examples ] bi
]
assert-depth
] check-something ;
: files>vocabs ( -- assoc ) : files>vocabs ( -- assoc )
vocabs vocabs
@ -137,7 +137,7 @@ M: help-error error.
] keep ; ] keep ;
: check-about ( vocab -- ) : check-about ( vocab -- )
[ vocab-help [ article drop ] when* ] check-something ; dup '[ _ vocab-help [ article drop ] when* ] check-something ;
: check-vocab ( vocab -- seq ) : check-vocab ( vocab -- seq )
"Checking " write dup write "..." print "Checking " write dup write "..." print