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

[REBOL] Re: Conditional Parsing

From: ammon::johnson::gmail::com at: 6-May-2005 10:18

What are you trying to do with the output, create a block of Key, Value pairs? Create an Object!? That's going to change the way you want to parse it alot. Do you need to be able to capture unkown fields in the text or do you want to ignore those fields? You said you need to be able capture different formats. Well if you want to capture different formats then you'll need to define every format that the file could come in within a single parse rule, and yes this is possible but I don't have enough information to really be of much help. I can give you a few pointers though... I would the SOME [ rule1 | rule2 ] notation to be able to capture multiple "fields" in an unspecified order. Also with SOME you can capture multiple formats very easily as it simply checks the separate rules until none of them match. If you want to capture "fields" whose name you are not aware of and ":" is the seperating value between the field name and the value then a rule something like: SOME [ rule1 | .... | copy field to ":" copy value to newline ] Would allow you to capture every field as long as the character that denotes the end of the value is a newline character. HTH!! ~~Ammon ;~> On 5/6/05, Arie van Wingerden <[apwing--zonnet--nl]> wrote:
> Hi Giuseppe, > > does the following script help you a bit? > > Kind regards, > Arie > > =========================
=========== script follows
> =========================
================
> rebol [] > > example1: { > Name: John > Surname: Doe > Book: Private America > 1stPubblication: 1950 > Brief description: oo xx oo xx oo xx > } > > example2: { > Name: Jane > Surname: Doe > Height: 1.75m > Eyes: Brown > Hair: Blonde > Hobbies: Play Tennis, Swim, Music > Book: Private Women of America > 1stPubblication: 1950 > Brief description: oo xx oo xx oo xx Woman > } > > rule: [ > > thru "Name: " > copy name > to "^/" > (print ["Name: " name]) > thru "^/" > > thru "Surname: " > copy surname > to "^/" > (print ["Surname: " surname]) > thru "^/" > > 0 1 [ > thru "Height: " > copy height > to "^/" > (print ["Height: " height]) > thru "^/"] > > 0 1 [ > thru "Eyes: " > copy Eyes > to "^/" > (print ["Eyes: " Eyes]) > thru "^/"] > > 0 1 [ > thru "Hair: " > copy Hair > to "^/" > (print ["Hair: " hair]) > thru "^/"] > > 0 1 [ > thru "Hobbies: " > copy Hobbies > to "^/" > (print ["Hobbies: " Hobbies]) > thru "^/"] > > thru "Book: " > copy book > to "^/" > (print ["Book: " book]) > thru "^/" > > thru "1stPubblication: " > copy first_publ > to "^/" > (print ["1stPubblication: " first_publ]) > thru "^/" > > thru "Brief description: " > copy brief_descr > to "^/" > (print ["Brief description: " brief_descr]) > thru "^/" > ] > > print "" > print "Parsing example1" > print "================" > print parse/all example1 rule > > print "" > print "Parsing example2" > print "================" > print parse/all example2 rule > > halt > > =========================
=================== end of script