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

[REBOL] Re: TupleSpace Dialect

From: al:bri:xtra at: 17-Jun-2002 21:52

After some work, I've got this function which can interpret the schema and data in succeeding rows/block, checking that the data matches the schema. make object! [ Row: make block! 100 Stack: make block! 100 Push_Row: does [ push/only Stack Row Row: make block! 10 ] Type: none Column: [ word! opt string! [ [ 'logic! opt ['false | 'true] ( append/only Row ['false | 'true] ) ] | set Type [ 'string! opt string! | 'issue! opt issue! | 'integer! opt integer! | 'decimal! opt decimal! | 'money! opt money! | 'date! opt date! | 'time! opt time! | 'url! opt url! | 'file! opt file! ] ( append Row Type ) ] ] Name_Block: [ word! (Push_Row) into Header ( Row: compose/deep [(pop Stack) into [(Row)]] ) ] Header: [ some [ [ 'some (Push_Row) [Column | Name_Block] ( Row: compose/deep [(pop Stack) some [(Row)]] ) ] | Column | Name_Block ] end ] set 'Tree func [Data [block!]] [ parse Data [ into Header any [into Row] end ] ] ] Which can understand this block of Schema and Data: Sample: [ ; Schema [ Street string! City string! State string! ZipCode "Zip Code" issue! some Apartment [ AptNumber "Apartment Number" integer! Rented logic! false Lease [ Begin date! End date! ] some Person [ First string! Middle string! Last string! ID integer! PrimaryRenter "Primary Renter" logic! true ] some Comments string! ] Url url! http://www.rebol.com Money money! $100.00 Time time! 12:00 Decimal decimal! 123.45 File file! %/C/Rebol/Core/Rebol.exe ] ; Data [ "65 Milton Road" "Napier" "NZ" #4001 [ 123 true [12/March/2002 23/April/2003] ["Andrew" "John" "Martin" 1001 true] "He's me!" "Are you sure?" "Yes!" "Banana" ] http://valley.150m.com $123 12:34:56 12.345 %/C/Rebol/View/Rebol.exe ] ] And these stack functions are needed as well: Pop: function [ "Returns the first value in a series and removes it from the series." Stack [series! port! bitset!] "Series at point to pop from." ][ Value ][ Value: pick Stack 1 remove Stack :Value ] Push: func [ "Inserts a value into a series and returns the series head." Stack [series! port! bitset!] "Series at point to insert." Value [any-type!] /Only "The value to insert." ][ head either Only [ insert/only Stack :Value ][ insert Stack :Value ] ] This is some test code for the above: do %Tree.r probe Tree Sample The 'Tree function works by 'parse-ing the schema, and generating appropriate 'parse rules for the subsequent data blocks. Comments, suggestions, improvements etc all welcome. Andrew Martin ICQ: 26227169 http://valley.150m.com/