World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
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 [1704x3] | More off topic...I wept a little bit when I heard of Dr. Ralph Griswold passing, back in October. Never met him, much respect. |
Final off topic; Now I'm slowly replacing all my computer heroes...Names like Kernighan, Pike, Moore, Griswold, Lovelace... are now Sassenrath, DocKimbel, Anton, Cyphre, Graham, Maxim, Ladislav, Henrik, Oldes...et al. Thanks guys. You are making my world a better place. | |
Final final...Gregg, Gabriele, Sunanda...I'm missing too many. :) And the big hook drags me off the stage. | |
Ladislav 13-Apr-2007 [1707x4] | Max: ...symbol | end skip | ... does not have much sense, since it is equivalent to just ...symbol | ... |
Max: "it would be nice if the result from the expression could be used to determine if the rule is a match or not" - that is of course possible as follows: | |
rule: [(next-rule: unless result-of-expression [[end skip]]) next-rule] | |
see this: >> rule: [(next-rule: unless result-of-expression [[end skip]]) next-rule] == [(next-rule: unless result-of-expression [[end skip]]) next-rule] >> result-of-expression: false == false >> parse "" rule == false >> result-of-expression: true == true >> parse "" rule == true | |
Maxim 13-Apr-2007 [1711x2] | yes... see the supplied fixed parser rules... I had not submitted the right one... I saw that after posting it :-) |
ladislav, what you demonstrate is that you can evaluate an expression within parse rules... parse itself does not handle the return value OF the expression. | |
Ladislav 13-Apr-2007 [1713x2] | right, but the value of the expression *can be used* to determine if a rule is a match |
otherwise, I am for addition of a rule which would take the result of the paren! expression directly into account without us having to resort to this (more complicated) way | |
Maxim 13-Apr-2007 [1715x2] | that is what I meant... I'd like parse to do it for us . |
obviously, using many tricks we can let parse do anything (including become an event parser as I discussed above ;-) | |
Ladislav 13-Apr-2007 [1717] | anyway, when you have got the RULE above, you can now always write: parse "" [(result-of-expression: compute-something) rule] |
Maxim 13-Apr-2007 [1718] | got to go *now* ;-) female in the house ;-) |
Ladislav 13-Apr-2007 [1719] | if you use a more appropriate rule name like check-result, you have got a more readable: |
older newer | first last |