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

%clean-script.r works now!!

 [1/1] from: agem::crosswinds::net at: 8-Apr-2001 17:01


[REBOL [ Patcher: "Volker Nitsch" Why-posted: [ {%clean-script.r works now!!} {it failed before with longer scripts} {a little patch makes script more reliable} {simpy changed a 'some to an 'any} {don't know why it works :) } {poorly testet, please help!!} ] Title: "REBOL Script Cleaner" Author: "Carl Sassenrath" File: %clean-script.r Date: 8-Apr-2001 Patch: [ {original} [ parse script blk-rule: [ some [ str: ...]]] {changed to} [ parse script blk-rule: [ any [ str: ...]]] ] Email: [carl--rebol--com] Purpose: { Cleans REBOL scripts by parsing the REBOL code and supplying standard indentation and spacing. } Note: { This script produces STANDARD script indentation and spacing. No doubt you will want to modify it to use your own rules. Send your enhancements and I will consider adding them to the distribution... but keep this header intact and keep the code clean. No hacks. } Category: [script util text 3] History: [ "Carl Sassenrath" 1.0.0 27-May-2000 "Original program." ] ] script-cleaner: make object! [ out: none ; output text spaced: off ; add extra bracket spacing indent: "" ; holds indentation tabs emit-line: func [] [append out newline] emit-space: func [pos] [ append out either newline = last out [indent] [ pick [#" " ""] found? any [ spaced not any [find "[(" last out find ")]" first pos] ] ] ] emit: func [from to] [emit-space from append out copy/part from to] set 'clean-script func [ "Returns new script text with standard spacing." script "Original Script text" /spacey "Optional spaces near brackets and parens" /local str new ] [ spaced: found? spacey out: append clear copy script newline parse script blk-rule: [ any [ str: newline (emit-line) | #";" [thru newline | to end] new: (emit str new) | [#"[" | #"("] (emit str 1 append indent tab) blk-rule | [#"]" | #")"] (remove indent emit str 1) | skip (set [value new] load/next str emit str new) :new ] ] remove out ; remove first char ] ] ;example: print clean-script read %clean-script.r ]