Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Parsing Data file

by zer (Deacon)
on Feb 07, 2008 at 17:42 UTC ( [id://666827]=perlquestion: print w/replies, xml ) Need Help??

zer has asked for the wisdom of the Perl Monks concerning the following question:

Good Evening

I am attempting to write a program which perform more complex diff's of a certain file type. The file holds a syntax which i would like to parse similar to XML::Parse's tree view.

This is the code im looking to parse. It is just a snippit but it should be enough
(object Attribute tool "VC++" name "default__Module-Spec" value (list Attribute_Set (object Attribute tool "VC++" name "InternalMap" value (value Text |*:AUTO:AUTO | )) (object Attribute tool "VC++" name "ExportMap" value (value Text |*:AUTO:AUTO | )) (object Attribute tool "VC++" name "InitialSourceIncludes" value (value Text |"stdafx.h" )) (object Attribute tool "VC++" name "InitialHeaderIncludes" value (value Text "")) (object Attribute tool "VC++" name "Copyright" value (value Text "Copyright (C) 1991 - 1999 Rati +onal Software Corporation")) (object Attribute tool "VC++" name "KindSet" value (list Attribute_Set (object Attribute tool "VC++" name "(none)" value 300) (object Attribute tool "VC++" name "DLL" value 301) (object Attribute tool "VC++" name "EXE" value 302) (object Attribute tool "VC++" name "MIDL" value 303))) (object Attribute tool "VC++" name "Kind" value ("KindSet" 300)) (object Attribute tool "VC++" name "BodyExtensions" value (value Text |.cpp |.cxx |.inl )) (object Attribute tool "VC++" name "HeaderExtensions" value (value Text |.h |.hpp |.hxx |inl )) (object Attribute tool "VC++" name "ProjectFolders" value (value Text |Source Files |Header Files )) (object Attribute tool "VC++" name "UsePathMap" value FALSE)))

Any help is appreciated. Esp if someone could identify what this pattern is called, or a module that will help me parse it. It looks lisp ish and even python esq but im not a pro in either of those languages so i may be totaly off.

Thank You

Replies are listed 'Best First'.
Re: Parsing Data file
by Fletch (Bishop) on Feb 07, 2008 at 17:50 UTC

    Yeah, I'm getting a very definite lisp-y "s-expression" vibe from it as well (although those (value Text...) sections that look like inline here-doc-y chunks are strange). Data::SExpression might be a place to start, but that shouldn't be too hard to whip up something custom with Parse::RecDescent (and I want to say I once saw a P::RD example that did s-exprs . . .).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Parsing Data file
by sundialsvc4 (Abbot) on Feb 07, 2008 at 18:42 UTC

    If it is an S-expression, then you're in luck because CPAN has a module Data::SExpression.

    Otherwise, I suggest you look at CPAN modules such as Parse::Yapp.

    The general concept behind these “parser generators” is that you solve your problem by constructing a grammar, which is a formal definition of the language you are dealing with. This definition also says “what to do when” a particular language-construct has been recognized. Then you invoke your parser, give the input, and wait for calls to be generated to the routines that you've defined.

    In this case, the odds are very good that someone else has already built a parser or recognizer for this file-type, whatever it is. Someone has probably solved this problem thoroughly, and submitted something useful somewhere in CPAN. So it becomes your chore merely to find it, not to (re-)build it. Look (in CPAN and in search-engines) for references to whatever product is known to have produced this file. See what the vendor calls files of this type.

      yes, its actually for Rational Rose .mdl files
Re: Parsing Data file
by moritz (Cardinal) on Feb 07, 2008 at 17:50 UTC
    This looks like an S-expression.

    But I'm not very familiar with them, so please double-check first.

Re: Parsing Data file
by pc88mxer (Vicar) on Feb 07, 2008 at 18:16 UTC
    Hey, at least it's not XML! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://666827]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found