|
From: Todd N. <osx...@ya...> - 2005-02-17 18:23:23
|
# Thu Jan 20 07:25:44 CST 2005 - Copyright (c) 2005,
Todd Nathan. All Rights Reserved
# This is a library to parse out like args does for
shell the parameters passed
# to the script, making into lists the values. Using
a rule based system
# you can make things work pretty much how you want it
to...
#
# (a:3b:c) # means a requires at least 1, and no more
than 3 optiosn
# # means b requires 1 or more options
# # means c is just a toggle
#
# Test invocation:
# st ./paramParser -a 1 2 3 -b 2 -c 3 -Dash Boulder
-Super man -c 10 11
#
# Current (bogus) output:
# (a:("1","2","3"), b:("2"), c:("3"),
Dash:("Boulder"), Super:("man"))
#
# Should be:
# (a:("1","2","3"), b:("2"), c:("3","10","11"),
Dash:("Boulder"), Super:("man"))
# or
# (a:("1","2","3"), b:("2"), c:("10","11"),
Dash:("Boulder"), Super:("man"))
#
# depending on how the default behaviour of the plus
properties functionality is
# to be considered. Personally I think replacement
should be default, and then
# merging as an option.
#
# Proposed syntax:
# put obj plus properties ((key):(vals)) into obj
[by merging|replacing [collisions]]
# put obj plus properties ((key):(vals)) into obj
[with collisions merged|replaced]
put parseParms(the params, "(a:3b:c)")
to parseParms params, rules -- 'rules' support is
coming real soon now :)
put a new object into obj
delete word 1 of params -- toss the handler name
set the itemDelimiter to "-"
delete item 1 of params -- assume params starts with
'-', all filenames at end of CLI
repeat with each item option of params
set the itemDelimiter to ","
put deQuote(item 1 of option) into key -- the key
put () into vals
repeat with n = 2 to number of items in option
get deQuote(item n of option) -- the value
if it is empty then next repeat -- likely end of
option list
insert it after vals
end repeat
put obj plus properties ((key):(vals)) into obj --
why doesn't merge|replace existing values of key?
end repeat
return obj
end parseParms
to deQuote string -- Removes all leading space
and quotes of a string, returns that string
repeat length of string times -- do leading junk and
...
if first char of string is not in quote & space then
exit repeat
delete first char of string
end repeat
repeat length of string times -- ... do junk in
trunk
if last char of string is not in quote & space then
exit repeat
delete last char of string
end repeat
return string
end deQuote
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
|