World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Volker 13-Aug-2005 [276x2] | s: "Hello cè World" es: charset[#"e" #"è"#"è"#"ê"#"i"#"î" #"y"] parse/all s [ to "c" p: skip es p2: ( p: change/part p "s" p2 ) :p ] ? s |
questions: -long string? then better copy instead of change/part -more patterns in same path, then not 'to. | |
shadwolf 13-Aug-2005 [278] | Volker that's not what I want to get ... I'm seeking a rebol ruke that allow me to test the character after a key char example #"c" but keeping it into the parsing stack |
Volker 13-Aug-2005 [279] | you know p: and :p in parse-rules? |
shadwolf 13-Aug-2005 [280] | k I will try it thank u :) |
BrianW 13-Aug-2005 [281] | yargh. I know how to split with a single character as the delimiter: chunks: parse/all text "^/" How do I split where a blank line (2 newlines with nothing in between) is the delimiter? The naive solution I can think of just doesn't work: chunks: parse/all text "^/^/" |
Graham 13-Aug-2005 [282x2] | you can make up a rule. |
lines: copy [] rule: [ copy txt to "^/^/" (append lines txt) skip 2 ] parse mytext [ some rule ] untested ... | |
BrianW 13-Aug-2005 [284] | I get lost trying to find a good way to describe my rule. Here's the bad code that states my intent, but doesn't work ('parse doesn't seem to like having that 'until in there) chunks: parse/all text [ until [ chunk: copy "" copy chunk to "^/^/" skip if chunk [ append chunks chunk ] ] ] |
Graham 13-Aug-2005 [285] | ummm.. don't think you can do that |
BrianW 13-Aug-2005 [286] | nope, I discovered that :-D |
Graham 13-Aug-2005 [287x4] | parse expects to see a parse dialect if you following it with a block |
try my way ... | |
and your code is mixing rebol code with the parse dialect. | |
Rebol code has to be in ( ) when used within the dialect | |
BrianW 13-Aug-2005 [291] | oh okay. I understand that now. |
Graham 13-Aug-2005 [292] | that should be parse/all mytext [ some rule ] |
BrianW 13-Aug-2005 [293] | thanks |
Graham 13-Aug-2005 [294] | np |
BrianW 13-Aug-2005 [295x2] | Hm. Still having issues: >> rule: [ copy chunk to "^/^/" (append lines chunk) skip 2 ] == [copy chunk to "^/^/" (append lines chunk) skip 2] >> text: "Dude.^/^/Sweet!^/" == "Dude.^/^/Sweet!^/" >> lines: copy [] == [] >> parse/all text rule ** Script Error: Invalid argument: ** Near: parse/all text rule >> |
oh, wait. | |
Graham 13-Aug-2005 [297] | oops .. should be "2 skip" and not "skip 2" |
BrianW 13-Aug-2005 [298x2] | That's okay, I forgot to include the possibility that there would be only one line, so my tests were blowing up somewhere else. |
Hm, that misses the last line if the text doesn't end in "^/^/" | |
Graham 13-Aug-2005 [300] | easy enough .. add {^/^} to end of text before parsing |
BrianW 13-Aug-2005 [301x2] | That *is* a nice and easy solution, thanks a lot! |
sweet, all my tests pass now. Time to add more tests :-) | |
Graham 13-Aug-2005 [303] | sometimes I find it easier to change the data than to change the rule :) |
BrianW 13-Aug-2005 [304x2] | Hey, as long as it works. |
Working on a textile parser over here to build my 'parse skills and make it easier to build my website with Rebol | |
Graham 13-Aug-2005 [306] | not that you shouldn't do it, but I use http://www.rebol.it/~steel/retools/remark/ |
BrianW 13-Aug-2005 [307] | I'm <>-phobic ;-) |
Graham 13-Aug-2005 [308] | Remark takes care of all of those taggy things |
BrianW 13-Aug-2005 [309] | and all of my pages are already in textile format, and I think a few of my friends would be more interested in Rebol if I had a textile parser for them |
Graham 13-Aug-2005 [310] | what's textile ? A type of fabric ? |
BrianW 13-Aug-2005 [311] | http://hobix.com/textile/ |
Graham 13-Aug-2005 [312] | A structured text variant ... |
BrianW 13-Aug-2005 [313x2] | yep |
I like some of the different structured text formatting systems | |
shadwolf 14-Aug-2005 [315] | Volker thank you it works great now and the code rule is tiny ;) |
Volker 14-Aug-2005 [316] | :) |
BrianW 18-Aug-2005 [317] | Any parse suggestions for trying to find #"(" without a matching #")" in text that might also have proper pairs of parens? |
Henrik 18-Aug-2005 [318] | you probably need to count them and see where you end up after finding all parens. I'm not sure if it can be used to see which are missing... |
BrianW 18-Aug-2005 [319] | That would probably work fine. This if for the textile parser, where a declaration like "p(." means a paragraph with left margin of 1em, repeated for additional ems of margin. Counting will be quite useful. |
Henrik 18-Aug-2005 [320] | count one up on #"(" and one down on #")". If correct, the end result is zero. |
BrianW 18-Aug-2005 [321x3] | thanks |
Perfect, Henrik. That took me exactly where I needed to go for this feature. | |
Gonna have to work on my test-simple.r script soon to provide better summaries. The number of tests that are passing in this thing is getting rather large! | |
BrianW 22-Aug-2005 [324] | Any tips on how to convert " *text* " to " <strong>text</strong>"? |
Sunanda 22-Aug-2005 [325] | One way: replace text "*" <strong> replace text "*" </strong> If there are multiple pairs of "*", repeat in a loop until the length no longer changes |
older newer | first last |