r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

Graham
2-Mar-2008
[2384]
do you need an 'end ?
JohanAR
2-Mar-2008
[2385x2]
just found out that this seems to work, but I don't really see why 
I have to include end. As I've understood "into" is supposed to fail 
and continue if the next item isn't a block!


parse data ['table some into [ end | some [ set n integer! (print 
n) ] (print "-") ]  ]
Ahh, another block around the into statement did the trick :P Thanks 
for the help though


parse data ['table some [ into [ some [ set n integer! (print n) 
] (print "-") ] ]  ]
[unknown: 5]
4-Mar-2008
[2387x4]
shouldn't datatype! be included in rule block parsing?
how do you do this:

blk: ["somestring" string!]

We can't do:

parse blk [string! datatype!]

and get a match.
I see I can do a reduce on the blk when passed to parse and get it 
true but not sure that is safe for my situation.
be nice if there was a lit-type!
Henrik
4-Mar-2008
[2391x2]
string! is considered a word here. you must provide the datatype 
in its serialized state:

parse ["something" #[datatype string!]] [string! datatype!]
same if you use none or other things that would be considered words 
in an unreduced block.
[unknown: 5]
4-Mar-2008
[2393x2]
I don't get what you mean by serialized state
>> parse ["something" #[datatype string!]] [string! datatype!]
** Syntax Error: Invalid construct -- #[

** Near: (line 1) parse ["something" #[datatype string!]] [string! 
datatype!]
Henrik
4-Mar-2008
[2395]
>> blk: ["something" string!]
== ["something" string!]
>> type? second blk
== word!
>> type? second reduce blk
== datatype!
 ; this you know, right? OK...
[unknown: 5]
4-Mar-2008
[2396x5]
I guess you mean datatype! with the "!"
yes Henrik
What I'm trying to avoid is any reducing
I dont' want any execution of code as I don't know what might be 
passed by the user
But I still need to validate the passed block
Henrik
4-Mar-2008
[2401]
>> mold/all string!
== "#[datatype! string!]"
>> blk: ["something" #[datatype! string!]]
== ["something" string!]
>> type? second blk
== datatype! ; voila :-)
[unknown: 5]
4-Mar-2008
[2402x3]
didn't know mold/all did that for string!
cool Henrik
I think that could work
Henrik
4-Mar-2008
[2405]
your "lit-datatype" is actually serialization. it exists for everything 
that otherwise would lose its datatype inside a block
[unknown: 5]
4-Mar-2008
[2406]
nice.
Henrik
4-Mar-2008
[2407]
mold/all will display how to serialize something so you don't need 
to reduce a block to get the right datatype in there.
[unknown: 5]
4-Mar-2008
[2408]
yeah I see which is exactly what I'm looking for.
Henrik
4-Mar-2008
[2409x2]
>> type? first [none]
== word!
>> type? first [#[none]]
== none!
a great and valuable tool (also speeds some things up)
[unknown: 5]
4-Mar-2008
[2411x3]
yeah I knew that one but didn't think about that for datatypes.
Yes greatly
It's gonna help me for what I'm doing.
Henrik
4-Mar-2008
[2414]
I'm sure it will :-)
[unknown: 5]
4-Mar-2008
[2415x2]
:)
Hmmm this still might be a problem though.  Because serialization 
is good if you know to put that into the block yourself but how to 
you take dynamic data that is user inputed and serialize the datatype 
that is in it?
Henrik
4-Mar-2008
[2417x2]
if you insert the right datatype in the string with code, the datatype 
should be recognized automatically. the other syntax is for manual 
entry.
>> type? first head insert [] string!
== datatype!
[unknown: 5]
4-Mar-2008
[2419]
what if they just enter a field and that field is translated as a 
block as [string!]
Henrik
4-Mar-2008
[2420]
that depends entirely on how you build the block
[unknown: 5]
4-Mar-2008
[2421x5]
Remember you don't know what is in the block as it might not be string!.
I'm gonna have to work on this a bit - still seems like a cumbersome 
way
But it helps to know that as it gives me more options
I think I have a way around that.
Thanks Henrik.
Henrik
4-Mar-2008
[2426]
no problem
BrianH
4-Mar-2008
[2427]
Keep in mind that you can parse for 'string! (the lit-word version 
of the word string!) and that will match without reducing.
[unknown: 5]
4-Mar-2008
[2428x3]
Yes, thanks Brian.
In my situation the lit-word and the mold/all methods are not ideal.
I can see where we need to add this capability to REBOL.
Henrik
5-Mar-2008
[2431x2]
Pail, what exactly does the user input in the field?
Paul :-)
[unknown: 5]
5-Mar-2008
[2433]
They input a string followed by a datatype.  For example:    ["age" 
integer! "location" string!]