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

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Maxim
3-May-2009
[2029x3]
some will loop over and over until ALL rules fail. if that happens 
then IT fails too.
'SOME  will loop ....
so why did it only print the string once?  simple question... but 
not so obvious to answer for a newbie  :-)
[unknown: 5]
3-May-2009
[2032]
Here is a crude way to do what we did earlier that doesn't use parse 
but matches any part to any first occurence of the letter

>> chars: charset "by"
== make bitset! #{
0000000000000000000000000400000200000000000000000000000000000000
}
>> copy/part z: find {aabbyyc} chars next find z "c"
== "bbyyc"
mhinson
3-May-2009
[2033]
because the match only occured once?
Maxim
3-May-2009
[2034x2]
yep... it only was able to match the first rule when got AT that 
point in the data
every other time (including after it matched the tag) the second, 
alternative, rule matched, and we where able to hit the end of the 
string.
mhinson
3-May-2009
[2036]
<TAG>
 here:

here only gets the remaining part of the string assigned to it if 
the previous key parse returns true
Maxim
3-May-2009
[2037]
set words within parse rules are set to the point in the series that 
the parser IS , AT that exact moment.
mhinson
3-May-2009
[2038]
I read about that & how [index? here] will return that position
Maxim
3-May-2009
[2039x2]
so if you had put the HERE: like so:
[here: "<TAG>" ...  

then the tag itself would be part of the printed string.
but note that at that point, it has not matched the "<TAG>"  yet 
 !
mhinson
3-May-2009
[2041x2]
so is the first position in the parse expression special in that 
it is always evaluated?
I see it is     
parse {123} [(print "hello")]
Maxim
3-May-2009
[2043]
it evaluates until it finds a given character that it cannot match
mhinson
3-May-2009
[2044]
Maxim, I fear my 10 mins are more than up, please dont let me keep 
you from your tasks. You have been more than kind.
[unknown: 5]
3-May-2009
[2045]
the thing to know about parse mhinson is that you want to set forth 
the righ  matching conditions to get to the end of the string that 
your parsing because if something doesn't match it will abort at 
that point and return false.
Maxim
3-May-2009
[2046]
ok, I'll be back later for lesson two  :-)  but I'll give you a simple 
lesson 1.5 assignment  ;-)

edit the above so it matches either "<TAG>"  OR  "[TAG]"   :-)
mhinson
3-May-2009
[2047]
ok thanks Maxim.
Maxim
3-May-2009
[2048]
I'm keeping it baby steps, but these are the simple building block 
which really build up about 90% of all real dialects.
mhinson
3-May-2009
[2049]
Thanks Paul, I fear I have been ignoring the use of other things 
like find. I guess with more complex parse expressions find may be 
a shortcut to extract a substring from a predictable block of text..
[unknown: 5]
3-May-2009
[2050]
Yeah, I often resort to find over parse because it makes more mental 
sense to me.
Maxim
3-May-2009
[2051]
the "comprehension" of those simple things is essential, simply knowing 
about them is useless... cause in real life, you will have to "SEE" 
the whole recursive structure of the parse rules played in your head. 
 


if you don't fully grasp what is going on, you can't really create 
that essential mental map.   that is what kept me from understanding 
parse for 6 yess... SIX years :-(   and suddenly over the course 
of 2 days, I finally "GOT" it and a week later I was building a 700 
line parse rule for a real-time server doing signal convertion from 
one data format to another through two network ports.
mhinson
3-May-2009
[2052]
I think I partly got the feeling that anything other than parse was 
non-purist.
Sunanda
3-May-2009
[2053]
You might find Brett's parse visualiser useful:
http://www.rebol.org/documentation.r?script=parse-analysis-view.r
mhinson
3-May-2009
[2054]
Sounds like a chalange.   I have wrote quite extensive data conversion 
routines in Pascal, but that was in the 80s.
[unknown: 5]
3-May-2009
[2055]
Well problem is that parse is not always most convient.
Maxim
3-May-2009
[2056x2]
its funny cause once you "get" parse... just about every data manipulation 
is really easy using it.  remark, used find and copy and shit like 
that before... it was a horrendous 100 lines of code.


it was replaced by 10 lines of parse code and now runs 20-50 times 
faster and can do much more funky stuff on top of it.  :-)
paul... that's cause you probably don't get it as much as you could 
 :-)
[unknown: 5]
3-May-2009
[2058x2]
For example, I rather do this:

parse/all {zzabyybc} [to charset copy result thru "c"]
Yeah Maxim, my mind trys to believe something should be possible 
with parse and I always hit that roadblock when it isn't.
mhinson
3-May-2009
[2060]
isnt Paul's example a "propper" parse?
[unknown: 5]
3-May-2009
[2061]
Hehe - that is my point.
Maxim
3-May-2009
[2062]
that was my situation before too... hell I had trouble doing just 
about anything in parse... for sooo long... now I can argue with 
the parse gurus... hehe I admit I'm a wee bit proud of that  ;-)
[unknown: 5]
3-May-2009
[2063]
hehe
mhinson
3-May-2009
[2064]
so how could the data extracted be used without the "copy"?
Maxim
3-May-2009
[2065]
mhison its a valid, but not really appropriate use of parse
[unknown: 5]
3-May-2009
[2066]
my example doesn't work mhinson.
Maxim
3-May-2009
[2067]
its not the copy aspect of it, its how he traverses the data.
[unknown: 5]
3-May-2009
[2068]
In my mind it should but that functionality doesn't exist as far 
as I know.
Maxim
3-May-2009
[2069x2]
when you start to add a single other rule, that will start to fall 
appart.
paul, it is part of possible R3 improvements
mhinson
3-May-2009
[2071]
Ah, so Paul wants to create in effect a "regular expression" and 
use it in the parse.
[unknown: 5]
3-May-2009
[2072]
Good, that will be very welcome.
Maxim
3-May-2009
[2073x3]
yep :-)
the problem is that the above can be extremely slow... just like 
regexp   :-)
be back later ... dont forget the assignment  ;-)
mhinson
3-May-2009
[2076x3]
Thanks again Maxim
Sunanda, I had a look at the parse visualiser yesterday, it looks 
a bit advanced for me yet. A simple version would be good for newbies. 
 I got it to work on his examples, but my examples produced no output. 
 I expect I was doing something foolish.  I will return to it when 
my basic skills are a bit better.
Maxim.  Here is my first attempt at the homework you set me. This 
builds on what you showed me & also relates to the example given 
to me by Pekr.


data: "before first tag <TAG> after 1st pointy tag [TAG] after square 
tag <TAG> after pointy tag 2"

tag-square: "[TAG]"
tag-pointy: "<TAG>"

output: func [tag here] [
	print rejoin ["we are passed the " tag " : '" here "'"]
]

parse/all data [
	some [ 
		[tag-pointy here: (output tag-pointy here) ] 
		| [tag-square here: (output tag-square here) ] 
		| skip
	]
]


I thought it would make the action clearer if the output was in a 
function & the keys used variables.