• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 'Pretty printing' nested records and lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'Pretty printing' nested records and lists


  • Subject: Re: 'Pretty printing' nested records and lists
  • From: Deivy Petrescu <email@hidden>
  • Date: Thu, 6 Mar 2003 17:18:09 -0500

On Thursday, Mar 6, 2003, at 15:46 US/Eastern, Brennan wrote:

> Hi folks,
>
> I'm in a situation where I am getting an object to dump a nested
> structure of
> lists and records as a string. I read this string in later using 'run
> script',
> but I'm also interested that it should be human-readable. (Even
> editable by
> trained users).
>
> Right now, the code I have is geared to a given structure, but the
> structure
> keeps changing, so I'm thinking abstraction ... abstraction ...
> abstraction.
>
> I feel quite able to do the job, but before I get my teeth into a
> general
> purpose recursive prettyprinting routine for lists/records of arbitrary
> complexity I'd like to ask if anyone has already done this.
>
> I'm looking for:
>
> Gracefully handled linebreaks (using the linebreak character)
> Escaped double-quote characters
> Outline style Nesting
>
> Something like
>
> ",
> {,
> {,
> \"a\",,
> \"b\",
> },,
> \"c\",
> }"
>
> Which is just {{"a", "b"}, "c"} Simple example, I know, but I'm
> thinking
> bigger than this of course.
>
> I'm not interested in weird 'innermost' datatypes with chevrons and
> what not,
> just standard Applescript strings and numbers. The wrapper objects
> will all be
> lists and records (nothing higher level than that).
>
> None of this should compromise the possibility of reading the string
> in again
> (i.e. converting back to a list or record) using 'run script' or 'load
> script'
>
> As you can see, with all the escaped strings and linebreaks, the thing
> is not
> particularly pretty. Can anyone suggest a rapid way of making it
> prettier,
> that can easily be reverted to machine readable form? (Using TIDs
> perhaps?)
> Right now, all I can think of is adding loads more white space.
>
> Thanks in advance
>
> Brennan
>

This is based on Richard23's very nice idea ...
<script>

set l to {nome:"deivy", team:"Santos"}
set k to {"a", "b", "c", {1, 2, {3}}}
{get nome of l, get team of l}
try
display dialog k
on error errmsg
set kem to characters 12 thru -16 of errmsg as text
--->{"a", "b", "c", {1, 2, {3}}}
end try
try
display dialog l
on error errmsg
set lem to characters 12 thru -16 of errmsg as text
-->{nome:"deivy", team:"Santos"}
end try
{kem, lem}

run script lem

</script>

lem contains your record in a human readable (and editable) form.
kem contains the list in the same form.


Deivy Petrescu
http://www.dicas.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Acrobat script
  • Next by Date: Re: Cocoa Loco
  • Previous by thread: Re: Persistant Properties??
  • Next by thread: System Events oddities
  • Index(es):
    • Date
    • Thread