World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Henrik 1-Dec-2005 [783] | geomol, out of curiosity, have you tried those incidents where parse will lock up and you need to quit REBOL? Have you tried to keep it running for a few minutes and see what happens? |
Geomol 1-Dec-2005 [784] | nope |
Henrik 1-Dec-2005 [785] | just wondering if that is a known behaviour. it returns to the console on its own |
Geomol 1-Dec-2005 [786] | Strange and funny. Like it has it's own personality. ;-) |
Henrik 1-Dec-2005 [787x2] | after about 5-7 minutes or so... |
it's in one of the examples in the wikibook group | |
Geomol 1-Dec-2005 [789x2] | It an almost infinite loop then. Takes all the cpu. |
Yes, it reply == false after some time here too. | |
Henrik 1-Dec-2005 [791x2] | good, then I'm not crazy :-) |
wondering if there is some sanity limit on a billion loops or something | |
Geomol 1-Dec-2005 [793] | :-) Maybe integer overflow? |
Henrik 1-Dec-2005 [794] | possibly if there is something that needs counting... |
Geomol 1-Dec-2005 [795x3] | Anyway, parse works in a certain (and you could say special) way, when dealing with strings: >> parse "a" [char!] == false >> parse "a" [string!] == false >> parse "a" [#"a"] == true >> parse "a" ["a"] == true |
So parsing a string for [any string!] maybe doesn't make much sense. | |
And parsing strings and chars within blocks give more meaning, when looking for datatypes: >> parse ["a"] [char!] == false >> parse ["a"] [string!] == true >> parse [#"a"] [string!] == false >> parse [#"a"] [char!] == true | |
Henrik 1-Dec-2005 [798] | using datatypes as rules, I think only work with blocks, not strings, which is why it returns false in the first two cases with "a" |
Chris 1-Dec-2005 [799x2] | Sadly, in string mode you can't use -- to charset! |
Be great if you could: >> chars: charset "ab" == make bitset! 64#{AAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAA=} >> parse "1234ab" [to chars] ** Script Error: Invalid argument: make bitset! 64#{AAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAA=} ** Near: parse "1234ab" [to chars] | |
Geomol 1-Dec-2005 [801] | You can with a little trick: >> no-chars: complement charset "ab" == make bitset! #{ FFFFFFFFFFFFFFFFFFFFFFFFF9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF } >> parse "1234ab" [some no-chars mk: (print mk) to end] ab == true |
Chris 1-Dec-2005 [802] | Yep, that's the workaround I use, but it can get complex... |
Anton 2-Dec-2005 [803] | I seem to remember Carl S. saying something about adding a safety check to parse to jump out of infinite loops... |
Joe 2-Jan-2006 [804x3] | Hi, I am checking the example in the parse chapter, section 7.3 copying the output , but I don't get it !! |
parse {<h1>title</h1>} [copy heading ["H" [ "1" | "2" | "3" ]] (print heading)] | |
the text seems to imply that heading should contain the "title" string, but it doesn't work for me. any ideas ? | |
Geomol 2-Jan-2006 [807] | It's not a good example. You could do something like: >> parse {<H1>A heading</H1>} [copy heading ["<H" ["1" | "2" | "3"] ">" to "</"]] == false >> heading == "<H1>A heading" |
Joe 2-Jan-2006 [808x2] | yes, this makes sense but it doesn't handle opening and closing tags as the example seems to imply. I'll report to rambo so the docs get updated |
thanks | |
Ammon 8-Jan-2006 [810x2] | Something I will never understand about parse: digit: charset [#"0" - #"9"] parse "123" [ any [ digit | end ] ] I hit the end of the damn string, SO QUIT! *&(%@$(*&($#*% |
NM... I got it. Parse is tricksy. | |
Henrik 8-Jan-2006 [812] | solution? |
Ammon 8-Jan-2006 [813] | parse "123" [ any [ digit | thru end ] ] |
Henrik 8-Jan-2006 [814x2] | yeah, each rule stop at a position, not going past it. that way you wouldn't be able to reach the tail of the series. THRU will get you to the tale |
tail | |
Ammon 8-Jan-2006 [816] | The problem wasn't really that I wasn't so much not hitting the end as it was figuring out how to keep all of my data. I'm breaking up some text using a semi-dynamic set of recursive rules and I kept loosing my last bit of data or hanging the interpreter... |
Anton 8-Jan-2006 [817] | Ah, recursive rules. :) I pushed my variables onto a stack when recursing, then popped them off when returning. That tends to bloat the code a fair bit. ( push-vars [a b c] recursive-rule pop-vars [a b c] ) so then you get to thinking to generate this code automatically with a make-recursive-rule function, which takes a parse rule, looks for recursion in it, then surrounds it with push-vars and pop-vars for you (kind of macro expansion). Or I did something like that, anyway. |
Ammon 8-Jan-2006 [818] | I would be very interested in seeing this code of yours. I'm planning on going further down the rabit hole of parse than anyone has gone before over the next couple of months. ;-) |
Anton 8-Jan-2006 [819] | http://www.lexicon.net/antonr/rebol/library/make-recursive-rule.r (Mmm.. it says it has a big flaw, but I know I'm using it successfully in a program. Maybe my input never trips the flaw, or I fixed it and forgot to write that down... Anyway, it gives you an idea how the user interface can look.) |
Ammon 8-Jan-2006 [820] | Kewl, thanks! I'll dig right into it. ;-) (I'll be back, Wahahahaha!) |
Anton 8-Jan-2006 [821] | Mmm... I think only the old commented code has the problem. I would have to test that, though... |
Rebolek 12-Jan-2006 [822] | I'm forced to work with regular expressions now and I must say that PARSE is shining sun compared to that terrible black magic called regular expressions. They suck! |
Pekr 12-Jan-2006 [823x2] | :-) |
but they are said being powerfull tool, once you master them of course ... | |
Henrik 12-Jan-2006 [825] | I always hear that if you need to use a UNIX OS, you need to learn them. So far I've done fairly well without them, but have been configuring procmail once, which was a complete nightmare. :-) |
Ladislav 12-Jan-2006 [826] | regular expressions are *very* powerful, as long as you *don't* compare them with Parse :-) |
Henrik 12-Jan-2006 [827] | I've also been confronted with UNIX users who are disappointed that there is no regexp implementation in REBOL. :-) they find it hard to believe that there might be something superior to it |
Sunanda 12-Jan-2006 [828] | It'd be fun to compare parse and REs..... Maybe a shootout between experts in both. Both sides could learn a lot. |
Pekr 12-Jan-2006 [829] | do you think you can do everything allowed in regexp in rebol's parse? |
Sunanda 12-Jan-2006 [830] | No....I suspect they each have core abilities they excel and other things they can only do with ugly workarounds, if at all. It'd be interesting to see experts bringing out the best in both. |
Gregg 12-Jan-2006 [831] | There was some talk about that on the ML a few years back. Joel and Ladislav had some great exchanges IIRC. Parse and RegEx are different tools. I can see the power of RegExs, but they aren't for the faint of heart when you start doing complex things. A RegEx can be very concise, and can be very handy for simple pattern matching. |
Ladislav 13-Jan-2006 [832] | http://www.compkarori.com/vanilla/display/PARSE-Versus-Regexs |
older newer | first last |