From 28ffd303cbfc247adfac5aa096abf55456a231a8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 26 Aug 2017 15:34:23 -0500 Subject: [PATCH] factor: random syntax update --- basis/memoize/syntax/syntax-docs.factor | 2 +- basis/memoize/syntax/syntax.factor | 2 +- extra/forestdb/lib/lib.factor | 10 ++-- extra/literate/literate.factor | 2 +- extra/metar/metar.factor | 72 ++++++++++++------------- extra/morse/morse-tests.factor | 16 +++--- extra/morse/morse.factor | 2 +- 7 files changed, 52 insertions(+), 54 deletions(-) diff --git a/basis/memoize/syntax/syntax-docs.factor b/basis/memoize/syntax/syntax-docs.factor index d4eba04bb0..6349247a54 100644 --- a/basis/memoize/syntax/syntax-docs.factor +++ b/basis/memoize/syntax/syntax-docs.factor @@ -1,6 +1,6 @@ USING: help.markup help.syntax memoize.syntax ; -HELP: MEMO[ +HELP: \MEMO[ { $syntax "MEMO[ elements... ]" } { $description "Defines the given literal quotation as one which memoizes its outputs given a particular input." } ; diff --git a/basis/memoize/syntax/syntax.factor b/basis/memoize/syntax/syntax.factor index d95a2f79c7..0982659881 100644 --- a/basis/memoize/syntax/syntax.factor +++ b/basis/memoize/syntax/syntax.factor @@ -2,4 +2,4 @@ USING: kernel memoize parser sequences stack-checker ; IN: memoize.syntax -SYNTAX: MEMO[ parse-quotation dup infer memoize-quot suffix! ; +SYNTAX: \MEMO[ parse-quotation dup infer memoize-quot suffix! ; diff --git a/extra/forestdb/lib/lib.factor b/extra/forestdb/lib/lib.factor index 50e7144170..6d576d1828 100644 --- a/extra/forestdb/lib/lib.factor +++ b/extra/forestdb/lib/lib.factor @@ -8,10 +8,8 @@ sequences strings ; QUALIFIED: sets IN: forestdb.lib -/* ! Issues ! Get byseq ignores seqnum and uses key instead if key is set -*/ ERROR: fdb-error error ; @@ -221,7 +219,7 @@ CONSTRUCTOR: fdb-doc ( seqnum keylen key metalen meta bodylen body del TUPLE: fdb-info filename new-filename doc-count space-used file-size ; CONSTRUCTOR: fdb-info ( filename new-filename doc-count space-used file-size -- obj ) ; -/* +![[ ! Example fdb_doc and converted doc S{ fdb_doc { keylen 4 } { metalen 0 } { bodylen 4 } { size_ondisk 0 } @@ -234,7 +232,7 @@ T{ doc { metalen 0 } { bodylen 4 } { offset 4256 } { size-ondisk 0 } } -*/ +]] : alien/length>string ( alien n -- string/f ) [ drop f ] [ @@ -395,7 +393,7 @@ PRIVATE> _ _ with-kvs-name ] with-forestdb-file-handle ; inline -/* +![[ ! Do not try to commit here, as it will fail with FDB_RESULT_RONLY_VIOLATION ! fdb-current is weird, it gets replaced if you call fdb-rollback ! Therefore, only clean up fdb-current once, and clean it up at the end @@ -443,4 +441,4 @@ PRIVATE> : with-forestdb-path ( path quot -- ) [ absolute-path fdb-open-default-config ] dip with-forestdb-handles-commit-wal ; inline ! [ absolute-path fdb-open-default-config ] dip with-forestdb-handle-commit-normal ; inline -*/ +]] diff --git a/extra/literate/literate.factor b/extra/literate/literate.factor index e3ad04fadc..70d2a30708 100644 --- a/extra/literate/literate.factor +++ b/extra/literate/literate.factor @@ -19,7 +19,7 @@ M: literate-lexer skip-blank ] [ drop ] if* ] [ call-next-method ] if ; -SYNTAX: " parse-multiline-string string-lines [ (parse-lines) append! ] with-nested-compilation-unit ; diff --git a/extra/metar/metar.factor b/extra/metar/metar.factor index b4ad42ba36..736a538643 100644 --- a/extra/metar/metar.factor +++ b/extra/metar/metar.factor @@ -26,14 +26,14 @@ ERROR: bad-location str ; } case ; : string>longitude ( str -- lon/f ) - dup R/ \d+-\d+(-\d+(\.\d+)?)?[WE]/ matches? [ + dup R{{ \d+-\d+(-\d+(\.\d+)?)?[WE]}} matches? [ unclip-last [ parse-location ] [ char: W = [ neg ] when ] bi* ] [ drop f ] if ; : string>latitude ( str -- lat/f ) - dup R/ \d+-\d+(-\d+(\.\d+)?)?[NS]/ matches? [ + dup R{{ \d+-\d+(-\d+(\.\d+)?)?[NS]}} matches? [ unclip-last [ parse-location ] [ char: S = [ neg ] when ] bi* @@ -277,16 +277,16 @@ CONSTANT: sky H{ unclip [ string>number ] [ char: A = ] bi* [ 100 /f "%.2f Hg" sprintf ] [ "%s hPa" sprintf ] if ; -CONSTANT: re-timestamp R/ \d{6}Z/ -CONSTANT: re-station R/ \w{4}/ -CONSTANT: re-temperature R/ [M]?\d{2}\\/([M]?\d{2})?/ -CONSTANT: re-wind R/ (VRB|\d{3})\d{2,3}(G\d{2,3})?KT/ -CONSTANT: re-wind-variable R/ \d{3}V\d{3}/ -CONSTANT: re-visibility R/ [MP]?\d+(\\/\d+)?SM/ -CONSTANT: re-rvr R/ R\d{2}[RLC]?\\/\d{4}(V\d{4})?FT/ -CONSTANT: re-weather R/ [+-]?(VC)?(\w{2}|\w{4})/ -CONSTANT: re-sky-condition R/ (\w{2,3}\d{3}(\w+)?|\w{3}|CAVOK)/ -CONSTANT: re-altimeter R/ [AQ]\d{4}/ +CONSTANT: re-timestamp R[[ \d{6}Z]] +CONSTANT: re-station R[[ \w{4}]] +CONSTANT: re-temperature R[[ [M]?\d{2}\\/([M]?\d{2})?]] +CONSTANT: re-wind R[[ (VRB|\d{3})\d{2,3}(G\d{2,3})?KT]] +CONSTANT: re-wind-variable R[[ \d{3}V\d{3}]] +CONSTANT: re-visibility R[[ [MP]?\d+(\\/\d+)?SM]] +CONSTANT: re-rvr R[[ R\d{2}[RLC]?\\/\d{4}(V\d{4})?FT]] +CONSTANT: re-weather R[[ [+-]?(VC)?(\w{2}|\w{4})]] +CONSTANT: re-sky-condition R[[ (\w{2,3}\d{3}(\w+)?|\w{3}|CAVOK)]] +CONSTANT: re-altimeter R[[ [AQ]\d{4}]] : find-one ( seq quot: ( elt -- ? ) -- seq elt/f ) dupd find drop [ tail unclip ] [ f ] if* ; inline @@ -462,7 +462,7 @@ CONSTANT: high-clouds H{ : parse-lightning ( str -- str' ) "LTG" ?head drop 2 group [ lightning at ] map " " join ; -CONSTANT: re-recent-weather R/ ((\w{2})?[BE]\d{2,4}((\w{2})?[BE]\d{2,4})?)+/ +CONSTANT: re-recent-weather R[[ ((\w{2})?[BE]\d{2,4}((\w{2})?[BE]\d{2,4})?)+]] : parse-began/ended ( str -- str' ) unclip swap @@ -512,27 +512,27 @@ CONSTANT: re-recent-weather R/ ((\w{2})?[BE]\d{2,4}((\w{2})?[BE]\d{2,4})?)+/ : parse-remark ( str -- str' ) { { [ dup glossary key? ] [ glossary at ] } - { [ dup R/ 1\d{4}/ matches? ] [ parse-6hr-max-temp ] } - { [ dup R/ 2\d{4}/ matches? ] [ parse-6hr-min-temp ] } - { [ dup R/ 4\d{8}/ matches? ] [ parse-24hr-temp ] } - { [ dup R/ 4\\/\d{3}/ matches? ] [ parse-snow-depth ] } - { [ dup R/ 5\d{4}/ matches? ] [ parse-1hr-pressure ] } - { [ dup R/ 6[\d\\/]{4}/ matches? ] [ parse-6hr-precipitation ] } - { [ dup R/ 7\d{4}/ matches? ] [ parse-24hr-precipitation ] } - { [ dup R/ 8\\/\d{3}/ matches? ] [ parse-cloud-cover ] } - { [ dup R/ 931\d{3}/ matches? ] [ parse-6hr-snowfall ] } - { [ dup R/ 933\d{3}/ matches? ] [ parse-water-equivalent-snow ] } - { [ dup R/ 98\d{3}/ matches? ] [ parse-duration-of-sunshine ] } - { [ dup R/ T\d{4,8}/ matches? ] [ parse-1hr-temp ] } - { [ dup R/ \d{3}\d{2,3}\\/\d{2,4}/ matches? ] [ parse-peak-wind ] } - { [ dup R/ P\d{4}/ matches? ] [ parse-1hr-precipitation ] } - { [ dup R/ SLP\d{3}/ matches? ] [ parse-sea-level-pressure ] } - { [ dup R/ LTG\w+/ matches? ] [ parse-lightning ] } - { [ dup R/ PROB\d+/ matches? ] [ parse-probability ] } - { [ dup R/ \d{3}V\d{3}/ matches? ] [ parse-varying ] } - { [ dup R/ [^-]+(-[^-]+)+/ matches? ] [ parse-from-to ] } - { [ dup R/ [^\\/]+(\\/[^\\/]+)+/ matches? ] [ ] } - { [ dup R/ \d+.\d+/ matches? ] [ ] } + { [ dup R[[ 1\d{4}]] matches? ] [ parse-6hr-max-temp ] } + { [ dup R[[ 2\d{4}]] matches? ] [ parse-6hr-min-temp ] } + { [ dup R[[ 4\d{8}]] matches? ] [ parse-24hr-temp ] } + { [ dup R[[ 4\\/\d{3}]] matches? ] [ parse-snow-depth ] } + { [ dup R[[ 5\d{4}]] matches? ] [ parse-1hr-pressure ] } + { [ dup R[[ 6[\d\\/]{4}]] matches? ] [ parse-6hr-precipitation ] } + { [ dup R[[ 7\d{4}]] matches? ] [ parse-24hr-precipitation ] } + { [ dup R[[ 8\\/\d{3}]] matches? ] [ parse-cloud-cover ] } + { [ dup R[[ 931\d{3}]] matches? ] [ parse-6hr-snowfall ] } + { [ dup R[[ 933\d{3}]] matches? ] [ parse-water-equivalent-snow ] } + { [ dup R[[ 98\d{3}]] matches? ] [ parse-duration-of-sunshine ] } + { [ dup R[[ T\d{4,8}]] matches? ] [ parse-1hr-temp ] } + { [ dup R[[ \d{3}\d{2,3}\\/\d{2,4}]] matches? ] [ parse-peak-wind ] } + { [ dup R[[ P\d{4}]] matches? ] [ parse-1hr-precipitation ] } + { [ dup R[[ SLP\d{3}]] matches? ] [ parse-sea-level-pressure ] } + { [ dup R[[ LTG\w+]] matches? ] [ parse-lightning ] } + { [ dup R[[ PROB\d+]] matches? ] [ parse-probability ] } + { [ dup R[[ \d{3}V\d{3}]] matches? ] [ parse-varying ] } + { [ dup R[[ [^-]+(-[^-]+)+]] matches? ] [ parse-from-to ] } + { [ dup R[[ [^\\/]+(\\/[^\\/]+)+]] matches? ] [ ] } + { [ dup R[[ \d+.\d+]] matches? ] [ ] } { [ dup re-recent-weather matches? ] [ parse-recent-weather ] } { [ dup re-weather matches? ] [ parse-weather ] } { [ dup re-sky-condition matches? ] [ parse-sky-condition ] } @@ -596,12 +596,12 @@ M: string metar. [ parse-altitude ] [ parse-wind ] bi* prepend "wind shear " prepend ; -CONSTANT: re-from-timestamp R/ FM\d{6}/ +CONSTANT: re-from-timestamp R[[ FM\d{6}]] : parse-from-timestamp ( str -- str' ) "FM" ?head drop parse-timestamp ; -CONSTANT: re-valid-timestamp R/ \d{4}\/\d{4}/ +CONSTANT: re-valid-timestamp R[[ \d{4}\/\d{4}]] : parse-valid-timestamp ( str -- str' ) "/" split1 [ "00" append parse-timestamp ] bi@ " to " glue ; diff --git a/extra/morse/morse-tests.factor b/extra/morse/morse-tests.factor index 9efcee1c48..e50f4a9414 100644 --- a/extra/morse/morse-tests.factor +++ b/extra/morse/morse-tests.factor @@ -15,30 +15,30 @@ IN: morse.tests { "abc" } [ ".- -... -.-." morse> ] unit-test { "morse code" } [ - [MORSE + MORSE[[ -- --- .-. ... . / -.-. --- -.. . - MORSE] >morse morse> ] unit-test + ]] >morse morse> ] unit-test { "morse code 123" } [ - [MORSE + MORSE[[ __ ___ ._. ... . / _._. ___ _.. . / .____ ..___ ...__ - MORSE] ] unit-test + ]] ] unit-test -{ [MORSE +{ MORSE[[ -- --- .-. ... . / -.-. --- -.. . - MORSE] } [ + ]] } [ "morse code" >morse morse> ] unit-test { "factor rocks!" } [ - [MORSE + MORSE[[ ..-. .- -.-. - --- .-. / .-. --- -.-. -.- ... -.-.-- - MORSE] ] unit-test + ]] ] unit-test ! [ ] [ "sos" 0.075 play-as-morse* ] unit-test ! [ ] [ "Factor rocks!" play-as-morse ] unit-test ! [ ] [ "\n" play-as-morse ] unit-test diff --git a/extra/morse/morse.factor b/extra/morse/morse.factor index 422b2baf6e..8459233d89 100755 --- a/extra/morse/morse.factor +++ b/extra/morse/morse.factor @@ -112,7 +112,7 @@ PRIVATE> : morse> ( morse -- plain ) replace-underscores morse>sentence ; -SYNTAX: [MORSE "MORSE]" parse-multiline-string morse> suffix! ; +SYNTAX: \MORSE[[ "]]" parse-multiline-string morse> suffix! ;