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

World: r3wp

[Parse] Discussion of PARSE dialect

[unknown: 5]
4-Mar-2008
[2390]
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
[2433x2]
They input a string followed by a datatype.  For example:    ["age" 
integer! "location" string!]
The datatype entered will vary.
Henrik
5-Mar-2008
[2435]
one way to deal with that would be to make your form so that it would 
not be possible to enter the data in a different way than the intended 
format, but that requires more form design of course.
btiffin
5-Mar-2008
[2436]
Henrik's original hint and any-type! should catch them.


parse ["age" integer! "loc" string!] [string!  set the-type #[datatype! 
any-type!] (print ["got an " the-type]) string! #[datatype! any-type!]]
[unknown: 5]
5-Mar-2008
[2437x2]
Henrik that is ugly way to approach it.  I feel were lacking a "better 
means" to handle this problem.
Brian here is a problem with your stradegy:

>> parse [1][set n #[datatype! any-type!]]
== true


Notice it returns true for the actual values that meet the datatype. 
 Which is what I don't want.  I need to know SPECIFICALLY if what 
was passed was integer! or string! or whatever.
Henrik
5-Mar-2008
[2439]
well, how do you want it to automatically recognize the input as 
datatypes? the only other way around it is to keep them as words 
and make a datatype rule to detect words that look like a datatype.