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

World: r3wp

[Parse] Discussion of PARSE dialect

Anton
7-Mar-2007
[1655]
do you remember the author ?
Steeve
7-Mar-2007
[1656x4]
no sorry
i'ts verry old
rebol.org was not created yet
i mean
Anton
7-Mar-2007
[1660]
But you were not around at this time, were you ?
Steeve
7-Mar-2007
[1661x3]
i was
i'm using Rebol since 6 years at least
i made pauses
Anton
7-Mar-2007
[1664]
aha ok
Steeve
7-Mar-2007
[1665x2]
I made a pause during which I raised sheep in the French Alps
and other ecological activities
Maxim
7-Mar-2007
[1667]
and reality kicked in?
Steeve
7-Mar-2007
[1668x2]
the reality ?, i'm just a nerd, i must admit this weakness, i can't 
leave without technology
*can't live
Maxim
7-Mar-2007
[1670]
hehe not enough buttons on a sheep I guess  ;-)
Steeve
7-Mar-2007
[1671]
I tested sincerely, but to live without technology it is like living 
with the Middle Ages, one passes the three quarters of his time to 
produce his food and to make provisions for the winter .
Graham
8-Mar-2007
[1672]
that's why the stoneage was not known for it's artistic achievements
Sunanda
8-Mar-2007
[1673]
I've never heard of such a script, Steeve.

It does not seem to be on REBOLtech (a forerunner to REBOL.org). 
You could try some more detailed searches than I did if you want 
to look further
http://www.reboltech.com/library/scripts/
****

Sadly, a lot of good stuff gets published on personal websites, and 
when the enthusiasm for REBOL wanes, or the site is taken offline 
for some reason, the scripts are lost to the wider community.
sqlab
8-Mar-2007
[1674]
Steeve, you can have a look at the scripts archive

http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlYCHQ
Henrik
9-Apr-2007
[1675]
I forget whether it's possible to move backwards in the block I'm 
parsing?
Oldes
9-Apr-2007
[1676]
yes, it is
Henrik
9-Apr-2007
[1677]
... how? :-)
Oldes
9-Apr-2007
[1678]
>> firsttime?: true parse [1 2 3 4 5][any [set v integer! p: (prin 
v if all [firsttime? v = 4][p: skip p -2 firsttime?: false]) :p]]
1234345== true
Henrik
9-Apr-2007
[1679]
I'm not sure I get it. how does parse know how to deal with 'p?
Oldes
9-Apr-2007
[1680x2]
p:  gets current parse position
:p  sets new position
but it must be in documentation somewhere
Henrik
9-Apr-2007
[1682]
it does, but I still don't see it. does parse read the block at the 
end of the 'any block?
Oldes
9-Apr-2007
[1683x3]
You can use it not just inside any block
but don't know any example why to use it without some rule like 'any
>> parse [1 2 3 4 5] [any [p: (probe p) skip]]
[1 2 3 4 5]
[2 3 4 5]
[3 4 5]
[4 5]
[5]
[]
Henrik
9-Apr-2007
[1686]
gave up. two-pass is easier :-)
Anton
10-Apr-2007
[1687x2]
Here is Oldes example padded with comments:
firsttime?: true 
parse [1 2 3 4 5][
	any [
		set v integer! 
		p:   ; <-- set P to the current parse position.

       ; (This is the input series with the series index at the current 
       position.)
		
		(
			; Here inside the paren is normal rebol code 
			
			prin v 
			if all [firsttime? v = 4][

    p: skip p -2   ; <-- move the index of the series referred to by 
    P
				firsttime?: false
			]
		) 
		
		:p   ; <-- set the current parse position to P
	]
]
Maxim
13-Apr-2007
[1689x5]
I am having a hard time with using REMOVE on a parsed string.
symbol: charset [#"a" - #"z" #"A" - #"Z" #"0" #"9" "_-?!*+~"]
nstr: "...aa.....a.....a.....h." 

parse/all nstr [
	some [
		symbol | end skip | 
		[

   here: ( probe here either none? here/1 [print nstr print "!!"  ][print 
   here/1 print nstr remove here here: back here]) ; :here skip
		]
		;:here
	]
] probe nstr
this just does an infinite loop... this is one of MANY twists I've 
put on the rules... (notice commented out :here)
and nothing works... if I set here to be the previous letter and 
then use skip in the rules... the first dot from nstr will not get 
removed... since we cannot go past the begining.
doh.... was about to give a better example... then I realise the 
error... there is nothing to match in the last rule, just an expression, 
so a no match is always matching nothing !
btiffin
13-Apr-2007
[1694]
It's nice just thinking out loud once in a while...we're here for 
you Maxim.  Cerebration.  :)
Maxim
13-Apr-2007
[1695x5]
it like saying the last rule matches the tail of the string.


Thus parse never gets "passed" the end cause my last rule matches 
the end, and thus prevents the parser from ever reaching it.
well, I was trying to say that I had not realized this was possible... 
and its quite cool... we can actually use that in some ways  ...


 make rules which make parse become an event handler for example ! 
  the moment you feed a string some value, parse will start treating 
 it...
and then fall back to silence... (just inserting a little wait in 
the loop will take care of cpu load)
it would be nice if the result from the expression could be used 
to determine if the rule is a match or not...
thus having (whatever expression TRUE)  would have allowed my previous 
last rule to match "everything else"
btiffin
13-Apr-2007
[1700x2]
Off topic but...that was what intrigued me with SNOBOL and Icon...succeed, 
fail and a result.
If you haven't, take a read through Icon pattern matching...mondo 
powerful.  Off topic...sorry.
Maxim
13-Apr-2007
[1702x2]
here is the solution... complement the valid symbols and match them 
explicitely.

rebol []

symbol: charset [#"a" - #"z" #"A" - #"Z" #"0" #"9" "_-?!*+~"]
invalid: complement symbol
nstr: "...aa.....a.....a.....h." 

end-rule: []

parse/all nstr [
	some [
		symbol | [here: invalid (remove here) ] :here
	]
]
reading? what is that? .... oh yeah... I remember ...  something 
people with time can do ... ;-)
btiffin
13-Apr-2007
[1704]
More off topic...I wept a little bit when I heard of Dr. Ralph Griswold 
passing, back in October.  Never met him, much respect.