Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] %Touch.r and Touch Dialect

From: Al:Bri:xtra at: 10-Jun-2003 21:30

Here's my %Touch.r along with an example of it's Touch dialect: Note that it's set for my prefered method of indenting blocks (it doesn't work well on Rebol HQ headers). Just call me prejudiced. :) If people want to, feel free to make this user adjustable and better. And feel free to expland the dialect as well. [ Rebol [ Name: 'Touch Title: "Touch" File: %Touch.r Author: "A J Martin" Owner: "Aztecnology" Rights: "Copyright 2003 A J Martin, Aztecnology." eMail: [Al--Bri--xtra--co--nz] Web: http://www.valley.it/Valley/ Tabs: 4 Purpose: "Implements a Rebol script specific Touch program." Language: 'English Date: 10/June/2003 Version: 1.0.4 Example: { foreach File recursive-read Folder: %/C/Rebol/ [ Touch Folder/:File compose [ [ Name Title File Author Owner Rights eMail Web ] Version + 0.0.1 Author: "A J Martin" eMail: (Rebol/script/header/eMail) Web: (Rebol/script/header/Web) Owner: "Aztecnology" Tabs: 4 Rights: "Copyright 2003 A J Martin, Aztecnology." Language: 'English Date: (now/date) Language: 'English [ Date Version ] ] ] } ] Touch: function [ File [file!] Dialect [block!] ] [Script Header Firsts Word Value Increment Lasts New_Header Header_Value] [ if all [ %.r = extension? File attempt [ Script: load/header File ] Header: first Script object? Header ] [ Header: make Rebol/script/header Header if word? Header/Name [ Header/Name: to lit-word! Header/Name ] parse Dialect [ opt [set Firsts into [any word!]] any [ [ set Word set-word! set Value any-type! ( Word: to word! :Word either found? find first Header Word [ set in Header Word :Value ] [ Header: make Header compose [ (to set-word! Word) (:Value) ] ] ) ] | [ 'Version '+ set Increment tuple! ( Header/Version: Increment + any [Header/Version 1.0.0] ) ] ] opt [set Lasts into [any word!]] end ] Script: read File New_Header: make string! 1000 Header_Value: [ if Value: get in Header Word [ switch/default type?/word Value [ string! [ Value: mold Value replace/all Value "^^-" tab ] word! [ Value: mold :Value ] date! [ Value: rejoin [ Value/3 #"/" pick Rebol/Locale/Months Value/2 #"/" Value/1 ] ] ] [ Value: mold :Value ] insert tail New_Header rejoin [ tab mold to set-word! Word #" " Value newline ] ] ] foreach Word Firsts Header_Value foreach Word exclude exclude next first Header Firsts Lasts Header_Value foreach Word Lasts Header_Value change/part find/tail Script "Rebol [^/" New_Header next find Script ^/^-]^/ write File Script ] ] ] Note that %Touch.r uses a common block value for the three 'foreach near the end. It's a cheaper way of doing Map! :) This took three hours to write, including this email! :) Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/