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

World: r3wp

[Parse] Discussion of PARSE dialect

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.
[unknown: 5]
5-Mar-2008
[2440]
Henrik that was the problem I almost had to resort to.  But hopefully 
you see the problem.  We should come up with ANOTHER method for handling 
this problem that is more seemless.
Henrik
5-Mar-2008
[2441]
you can also simply parse each single word like that. you can be 
as exact as you want in the parser.
[unknown: 5]
5-Mar-2008
[2442]
Yes, I understand that but it defeats Carl's famous philosophy which 
is that simple things should be simple to do.
Henrik
5-Mar-2008
[2443]
parse data ['string! (do-this) | 'integer (do-that)]
[unknown: 5]
5-Mar-2008
[2444x4]
I currently have resorted to a different approach.
Currently, I do something similiar to this:

user passes dynamic data captures in a block:
data: ["fname" string! "age" integer!]

Then I do the following:
        data: next data

        forskip data 2 [poke data 1 load mold/all attempt [to-datatype data/1]]
then this:

        data: head data

        unless parse data [some [string! datatype!]][return "Syntax Error!"]
Uses the mold/all method you provided yesterday.
Henrik
5-Mar-2008
[2448]
well, if that's all you do, you don't even have to convert it to 
a datatype, IMHO. it's enough to collect a list of rebol's datatypes 
as words, so they be used to trigger on the input word which looks 
like a datatype. I can see you are going for correctness, i.e. wanting 
the input to be a real datatype, but if you only use that input as 
a trigger to do something, you don't need to convert it to a real 
datatype. just operate using words.
[unknown: 5]
5-Mar-2008
[2449]
Yeah I even looked into going thru system/words and collecting all 
the datatype but the method I deployed was smaller and more effective.
Henrik
5-Mar-2008
[2450]
put weight in that dialects are words and if you take advantage of 
that, your dialect will become simpler