ColorizeScript challenge
Richard Gaskin
ambassador at fourthworld.com
Thu Apr 27 10:31:12 CDT 2006
Geoff Canyon wrote:
>
> On Apr 27, 2006, at 6:28 AM, Dave Cragg wrote:
>
>> On 27 Apr 2006, at 12:31, Geoff Canyon wrote:
>>>
>>> Attempting to take back the beer (I don't drink, so I'm not sure why
>>> I'm bothering...)
>>
>> And I don't colorize my scripts. How pathetic are we? Make sure
>> Richard buys you a nice meal.
>
> I don't colorize either. What a couple of saps.
That makes three of us. :)
But folks seem to like it so it seems worth doing.
>>> put ("oh no, #this will be a comment")
>>>
>>> Everything after the # would be colored as a comment. I didn't know
>>> until now that the above breaks the "quoted text is one word" rule.
>>> There are eight words in that line according to Revolution.
>>
>> I'm not sure I want to know that. One more things to worry about.
>
> I think if I really want the beer (maybe tonight) I'd rewrite my code to
> simply loop through the characters of the script and keep my own state
> variables: inBlockComment, inQuotedString. Assemble words, put them into
> the HTML, etc. <sigh>
>
> What's the use of lines, words, etc. for a task like this? Not much, I'm
> afraid.
Here's a tough one: Your script works great in MC (I've had to modify
it to use it there, and changed some color assignments while I was at it
-- see below), but it doesn't set the color of function names when the
function is used in the traditional parenthetic form rather than with
"the", e.g.:
put the length of "Hello" -- colorizes "length"
put length("Hello") -- doesn't colorize "length"
I began exploring ways to use token instead of work, but I couldn't do
it without changing the actual text. Maybe with a little more
dilligence token might be the magic key we're looking for....
--
Richard Gaskin
Managing Editor, revJournal
_______________________________________________________
Rev tips, tutorials and more: http://www.revJournal.com
on colorizeScript -- GC
global gREVScriptHTMLColors
--
if the optionKey is "down" then
colorizeScript_D
exit colorizeScript
end if
--
if gREVScriptHTMLColors["if"] is empty then SetupHTMLColors
SetupHTMLColors
put the scroll of fld "Editor Field" into tSaveScroll
put fld "Editor Field" into tScript
------
replace "&" with "&" in tScript
replace "<" with "<" in tScript
replace ">" with ">" in tScript
repeat for each line L in tScript
put 0 into i
repeat for each word W in L
add 1 to i
if gREVScriptHTMLColors[W] is not empty then
put gREVScriptHTMLColors[W] into word i of L
add 1 to i
else if char 1 of W is "#" or char 1 to 2 of W is "--" then
put "<font color=gray60>" before word i of L
put "</font>" after L
exit repeat
end if
end repeat
put "<p>" & L & "</p>" & cr after tReturn
end repeat
--
set the htmlText of fld "Editor Field" to tReturn
set the scroll of fld "Editor Field" to tSaveScroll
unlock screen
end colorizeScript
on SetupHTMLColors -- initializes gREVScriptHTMLColors global
global gREVScriptHTMLColors
if gREVScriptHTMLColors["if"] is empty then setupColors
setupColors
delete variable gREVScriptHTMLColors
put tokencolors into tColors
combine tColors with cr and tab
set the itemdelimiter to tab
repeat for each line L in tColors
-- watch out for text wrap with this line:
put format("%s\t<font color=\"%s\">%s</font>\n",item 1 of L,item 2
of L,item 1 of L) after gREVScriptHTMLColors
end repeat
split gREVScriptHTMLColors with cr and tab
end SetupHTMLColors
on setupcolors
repeat for each word w in the commandNames
put "blue" into tokencolors[w]
end repeat
repeat for each word w in "if then else repeat for with while on end
switch case getprop setprop"
--! put "Brown" into tokencolors[w]
put "Green3" into tokencolors[w]
end repeat
repeat for each word w in the functionNames
put "DarkOrange" into tokencolors[w]
end repeat
repeat for each word w in the propertyNames
put "red" into tokencolors[w]
end repeat
end setupcolors
More information about the metacard
mailing list