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

[REBOL] Re: Parse to Object Mapping question.

From: ingo:2b1 at: 3-Jul-2001 12:31

Hi Steve, this is a little hack that does a little of what you want ... Once upon a time Steve Shireman spoketh thus: <...>
> I want to parse a message, and stuff it into an object if the parsing is > valid. > > Ideally, the structure of the object could be used to create the parsing > rule.
<...> -- Attached file included as plaintext by Listar -- REBOL [ Title: "Object parse-setter" Author: "Ingo Hohmann" Date: 2001-07-03 EMail: [ingo--2b1--de] purpose: { Demonstrate an awful hack, to create an object setting parse rule ... just try to do it, and you'll see ... } ] template-object: make object! [ length: integer! unit: word! ] data-string: "1 cm" parse-object-rule: func [ data [string!] template [object!] /local rule object-info new-obj ][ rule: copy [] object-info: next head third template forskip object-info 2 [ append rule compose [ set tmp (first object-info) ] append/only rule to-paren compose [ change at object-info (index? object-info) tmp] ] object-info: head object-info parse load data rule object-info: next head object-info forskip object-info 2 [ if word? first object-info [ change object-info to-lit-word first object-info ] ] make object! object-info ] print "^/My string is:" probe data-string print "^/My template looks like this:" probe template-object print "^/ ... and I get" probe parse-object-rule data-string template-object