World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
shadwolf 30-Jun-2009 [3990x2] | hihihi hum ... no because nuclear thing hurts the planet ... |
there is so many interresting aspect in rebol than focusing on only one and going to the extend of it is really hard ... | |
Graham 30-Jun-2009 [3992] | How's the collaborative editor going? |
shadwolf 30-Jun-2009 [3993x7] | but rebolution can't come if it don't bring freedom with it isn't it ? |
graham i thought your irc was to handle that kind of conversation lol | |
well since i'm stuck with parse .... it's not going at all | |
if you hit metal and shape it you are a blacksmith if you hit parse and shape your code you are a reboler :P | |
i like the idea of building a colaborativ editor around irc and vid i find the cross of both technologies reallly interresting... but the bound to those technologies have to be parse parse parse and only parse | |
if i make another compse and if find based project steeve is going to kill me :P | |
ok i'm leaving to bed see u | |
Graham 30-Jun-2009 [4000] | bye |
Gregg 1-Jul-2009 [4001] | Shadwolf, I think you'll get a lot of agreement about the doc situation, but the REBOL community has never reached critical mass. Also, REBOLers tend to roll their own. That's partly due to REBOL not having support for PitL (e.g. modules), but also a mindset. |
Maxim 1-Jul-2009 [4002] | shadwolf. REBOL dialects are by definitions BLOCK parsing dialects. ypu fail to mention that there is block parsing in the document you started. |
shadwolf 3-Jul-2009 [4003x7] | maxim no i called it the block rule and i made a section dedicated to dialect So waht i will put in the block rule that is different than a dialact ... |
in the block rule i will explain the big lines and then i will try to apply those consepts to build a simple dialect that i will comment . | |
and as that's the most difficult part i don't really undersand it so we will see any help is welcome anyway. | |
for me and that's probably a noob though becasuse i'm not a guru... but none rule and string rule avec almost the same effect isolating and spliting items of a string and arranging it into a returned block! but yes the bigest part will be to explain the block rule the parse in a block rule instructions (copy at thru to etc...) | |
i will have to explain any some end newline all those kind of things that annimate parse and make it completly another thing compared to regular expression | |
Gregg well ... i'm not against contributing but I think one of the good way is for lower ranked programmer to express their problems and try to construct a doc helped by gurus to answers their ask then if it's readable and understandable by me I assum anyone could understand it My point is once people end rading the doc they will say "yeah i understoud what it's all about so now lets play with parse :P" if that only goal can be achieve I think a big step will be done. | |
and parse is something I really want to use in extensiv ways and if in the process i can acquiere enough knowledge and sahre it then we will all benefit from that | |
Maxim 10-Jul-2009 [4010] | shadwolf... just found this nice little tutorial... :-) http://compsci.ca/v3/viewtopic.php?t=17706 |
Brock 10-Jul-2009 [4011] | Can anyone explain the error indicated in the last comment? |
Graham 10-Jul-2009 [4012] | You should define a complement to spaces and then change the parse rule to copy the complementary characters. |
Anton 11-Jul-2009 [4013] | The changed rule has copy varb to spaces Note: that's *to* spaces, not *thru* spaces. That is, the spaces are not consumed like they were in the previous rule. If you have a rule spaces then those spaces will be consumed. If you have a rule to spaces then the parse index will be moved to the head of those spaces, so the spaces themselves will not be consumed. So if you want the spaces also to be consumed (the parse index to be advanced through them), then you need a rule: to spaces spaces That's right, you have to repeat yourself a little bit. So the fixed version of the broken rule from the article should be: rule: ["a" spaces copy varb to spaces spaces "c"] (Feel free to post this answer to the article.) |
sqlab 13-Jul-2009 [4014] | no, I see it differently. the problem is that spaces is " [some spacer]" , and R2 does not allow "to subrule". |
Anton 13-Jul-2009 [4015x5] | You are right. (I was so confident I didn't test my code. Good thing nobody posted it.) |
Ok, this is tested: | |
. spacer: charset " ^-^/" ; Space, tab, newline. non-spacer: complement spacer ; All chars except the three above. whatever: [some non-spacer] spaces: [some spacer] rule: ["a" spaces copy varb whatever spaces "c"] parse/all "a b c" rule ;== true | |
Maybe someone who subscribed can post this code, with additional comments: | |
The above problem reduces to: spacer: charset " " parse/all " " [to spacer] ** Script Error: Invalid argument: make bitset! #{ 0000000001000000000000000000000000000000000000000000000000000000 } ** Near: parse/all " " [to spacer] The reason is Rebol2 parse does not allow "to subrule". (Pointed out by sqlab, thanks.) Here's a way to do it using COMPLEMENT (suggested by Graham): spacer: charset " ^-^/" ; Space, tab, newline. non-spacer: complement spacer ; All chars except the three above. whatever: [some non-spacer] spaces: [some spacer] rule: ["a" spaces copy varb whatever spaces "c"] parse/all "a b c" rule ;== true | |
BrianH 13-Jul-2009 [4020] | Anton, this sounds like that question asked on stackoverflow.com, linked earlier here in this group. |
Anton 13-Jul-2009 [4021x2] | You're right. Some guy has been cross-posting the same question. |
Oh, and I see you gave a good reply in the stackoverflow.com site. | |
PatrickP61 17-Jul-2009 [4023] | Hi All, I'm new to PARSE, so I've come here to learn a little more. I'm working on and off on a little testing project of my own for R3. My goal is to navigate through some website(s), capture Rebol code, and the expeceted responses such as this page: http://rebol.com/r3/docs/functions/try.html I'd like to capture the text inside a block like this: [ "cmd" {if error? try [1 + "x"] [print "Did not work."]} rsp {Did not work.} cmd {if error? try [load "$10,20,30"] [print "No good"]} rsp {No good}] Can anyone point me to some parse example code which can "tear apart" an HTTP page based on text and the type of text? I realize I may be biting off a bit more than I can chew, but I'd still like to give it a try. Thanks in advance. |
Paul 17-Jul-2009 [4024] | You can just set your block that you want to parse to a word. Such as: blk: [ "cmd" {if error? try [1 + "x"] [print "Did not work."]} rsp {Did not work.} cmd {if error? try [load "$10,20,30"] [print "No good"]} rsp {No good}] ; and then do this: >> parse blk [some [set s string! (print s)]] |
PatrickP61 17-Jul-2009 [4025x4] | Hi Paul, I may have mis-stated what I'm after. You see the site http://rebol.com/r3/docs/functions/try.htmlhas displayable rebol code and responses within the html. If you captured the html code you would find something like this: <html> <head> ...(additional html code and text)... <title>REBOL 3 Functions: try</title>TRY returns an error value if an error happened, otherwise it returns the normal result of the block.</p> <pre>if error? try [1 + "x"] [print "Did not work."] <-- in this e.g. the tag <pre> will preceed the rebol command until the next tag <span class="eval">Did not work.</span></pre> <-- the tag <span class="eval"> will preceed the response <pre>if error? try [load "$10,20,30"] [print "No good"] <-- this is the next rebol command <span class="eval">No good</span></pre> <-- this is the next response <h2 id="section-3">Related</h2> I want to be able to interrogate the html code, parse it and capture the rebol commands and responses (if any), then put that into your above block example. |
I have this code which does this: cmd-txt: "unasg" cmd-term: "<" pre-txt: "unasg" pre-bgn: "<pre>" pre-end: "</pre>" rsp-txt: "unasg" rsp-bgn: {<span class="eval">} rsp-end: {</span>} site-url: http://rebol.com/r3/docs/functions/try.html page-txt: to-string read site-url probe parse page-txt [thru pre-bgn copy pre-txt to pre-end] probe parse pre-txt [copy cmd-txt to cmd-term] probe parse pre-txt [thru rsp-bgn copy rsp-txt to rsp-end] print [{"cmd"} "{" cmd-txt "}"] print [{"rsp"} "{" rsp-txt "}"] will yield this: cmd { if error? try [1 + "x"] [print "Did not work."] <-- this is close to what I want to do } rsp { Did not work. } This is close to what I want, but it is not foolproof. For example, I would like to capture all displayable text that is separated from any html tags. In my code example, if a displayable greater than symbol < was displayed, then the parse would stop prematurely. I am guessing someone has already created some code to "pull apart" a html web page, separating displayable text from invisible markup code. | |
p.s. I'm doing this in R3! | |
I think I may have found an example on REBOL.ORG called WebSplit.r that may be helpful. I welcome any other suggestions. | |
Graham 18-Jul-2009 [4029] | load/markup |
Brock 18-Jul-2009 [4030x9] | more to what Graham is saying is, try... >> load/markup http://rebol.com/r3/docs/functions/try.html you will be returned a block of strings and tags, which you could use the tag? word to test if each element is a tag or not to seperate HTML from regular Strings. |
This should help with the parse itself... parse page-txt [ thru pre-bgn copy cmd-txt to rsp-bgn thru rsp-bgn copy rsp-term to rsp-end (print ["Cmd: " cmd-txt "RSP: " rsp-term]) to end ] | |
which would return... Cmd: if error? try [1 + "x"] [print "Did not work."] RSP: Did not work. == true | |
sorry, missed the quotes around the returned set... parse page-txt [ thru pre-bgn copy cmd-txt to rsp-bgn thru rsp-bgn copy rsp-term to rsp-end (print ["Cmd: " mold cmd-txt "RSP: " mold rsp-term]) to end ] | |
which would return... Cmd: {if error? try [1 + "x"] [print "Did not work."] } RSP: "Did not work." | |
if you want the RSP line on a separte line from the '{', then put a the word newline before the string "RSP: ", or use "^/RSP: ", where the "^/" is equivalent to a newline or carriage return. | |
with the result... Cmd: {if error? try [1 + "x"] [print "Did not work."] } RSP: "Did not work." | |
if you want to capture multiple command and response blocks you wrap the parse block in... any[ parse statements] .... excluding the to end statement which you would want to include only after 'any' parse instances occured. | |
parse page-txt [ any[ thru pre-bgn copy cmd-txt to rsp-bgn thru rsp-bgn copy rsp-term to rsp-end (print ["Cmd: " mold cmd-txt "^/RSP: " mold rsp-term]) ] to end ] | |
PatrickP61 18-Jul-2009 [4039] | Excellent suggestions Brock and Graham -- That gives me a lot to play with!! Thank you. |
older newer | first last |