World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Ladislav 11-Oct-2005 [489] | maybe we should put it to RAMBO as an enhancement request? |
Tomc 11-Oct-2005 [490x2] | split-text: func [txt [string!] n [integer!] /local frag fraglet bl frag-rule bs ws ][ ws: charset [#" " #"^-" #"^/"] bs: complement ws bl: copy [] frag-rule: [ any ws [copy frag [n skip] [opt[copy fraglet some bs (insert tail frag fraglet)] ] |[copy frag to end] (insert tail bl frag) ] parse/all txt [some frag-rule] bl ] |
untries | |
Graham 11-Oct-2005 [492x3] | Ladislav, that doesn't work. |
tom, untried fails :) | |
this is being done to try and format and wrap text of course. | |
Ladislav 11-Oct-2005 [495] | >> n: 5 parse "" [copy frag [n skip | to end] (frag: any [frag ""])] == true >> frag == "" |
Graham 11-Oct-2005 [496] | this is a little tricky for such a simple function. |
Ladislav 11-Oct-2005 [497] | that is why I am saying that the NONE issue is annoying |
Graham 11-Oct-2005 [498] | Did you get a chance to talk to Carl? |
Ladislav 11-Oct-2005 [499] | yes, I did, he accepted all my proposals - more than 600 lines of text when written |
Pekr 11-Oct-2005 [500x2] | Ladislav - could you post it, please? :-) |
or at least pointers to some older articles already written, which were accepted by Carl? | |
Ladislav 11-Oct-2005 [502] | (but this one deserves to be put to Rambo too - do you want me to put it there?) |
Graham 11-Oct-2005 [503x3] | yes. |
Do we have a final function that works yet? | |
it might be easier to to a parse/all txt #" " and then build up the lines one at a time. | |
Tomc 11-Oct-2005 [506x2] | I can get rid of the infinate nones by making an error ... |
but that dosent really count | |
Ladislav 11-Oct-2005 [508] | split-text: func [ txt n /local frag result bl stop-rule ][ bl: copy [] result: copy "" stop-rule: none end-rule: [to end (stop-rule: [end skip])] frag-rule: [ copy frag [n skip | end-rule] (frag: any [frag ""] print frag append result frag) copy frag [to #" " | end-rule] (frag: any [frag ""] print frag append result frag append bl copy result clear result)] parse/all txt [some [frag-rule stop-rule]] bl ] |
Tomc 11-Oct-2005 [509] | split-text: func [txt [string!] n [integer!] /local frag fraglet bl frag-rule bs ws ][ ws: charset [#" " #"^-" #"^/"] bs: complement ws bl: copy [] frag-rule: [ any ws copy frag [ [1 n skip opt[copy fraglet some bs] ] | to end skip ] (all [fraglet join frag fraglet] insert tail bl frag print frag ) ] parse/all txt [some frag-rule] bl ] |
Graham 11-Oct-2005 [510] | I have to say Tomc is a winner ! |
Tomc 11-Oct-2005 [511] | it was the copy frag 1 n skip |
Graham 11-Oct-2005 [512] | Unspecified .. but tom's function removes leading white space as well. Ladislav's preserves whitespace. |
Ladislav 11-Oct-2005 [513] | yes |
Graham 11-Oct-2005 [514] | should stick both up on the library .. |
Tomc 11-Oct-2005 [515x2] | can easily commont out the any ws line if that is not desired ... or make it a refinement |
good night thanks for the puzzle | |
Graham 11-Oct-2005 [517x2] | thanks for the input. |
and thanks both for the solution. | |
Ladislav 11-Oct-2005 [519] | good night, Tom |
Graham 11-Oct-2005 [520x2] | Next Devcon they should set aside a few mins for some programming contests :) |
and virtual spectators being allowed to compete. | |
Ammon 11-Oct-2005 [522x2] | Not a half bad idea. |
Word on the street is that you're offering to host this next one. | |
Ladislav 11-Oct-2005 [524] | hi Ammon, missed you in Italy |
Ammon 11-Oct-2005 [525] | Hello. I missed you all as well. |
Graham 11-Oct-2005 [526] | well, if people want to come to Wellington .. I'll see what I can do. |
Ladislav 16-Oct-2005 [527x2] | I checked RAMBO and the discussed issue seems to be there: #3579 by Piotr. |
Gabriele: the [copy frag [n skip | to end] (insert tail result any [frag""])] looks too complicated for the PARSE setting words to NONE justification, I would at least prefer to add it to the ticket as an example. | |
MichaelB 23-Oct-2005 [529] | I just found out that I can't do the following: s: "a b c" s: "a c b" parse s ["a" to ["b" | "c"] to end] The two strings should only symbolize that b and c can alternate. But 'to and 'thru don't work with subrules. It's not even stated in the documentation that it should but wouldn't it be natural ? Or am I missing some complication for the parser if it would support this (in the general case indefinite look-ahead necessary for the parser - is this the problem?) ? How are other people doing things like this - what if you want to parse something like "a bla bla bla c" or "a bla bla bla d" if you are interested in the "bla bla bla" which might be arbitrary text and thus can't be put into rules ? |
Volker 23-Oct-2005 [530x2] | Carl mentioned performance-problems. Although everyone asks for it. |
i use "a" any[ "b" | "c" | skip ] to end Even slower and less elegantly, but works. | |
MichaelB 23-Oct-2005 [532] | OK, thanks. Didn't know this. But this solution will work for me as well. In a sense this is interesting, as skip isn't a real token, but a command - but it's treated as a token. :-) |
Chris 23-Oct-2005 [533x2] | Volker, that will return true for "a" as well as "a b c". |
I tend to use charsets for this, though again, there is probably a performance cost... | |
Volker 23-Oct-2005 [535x2] | true. never thought about that. |
'some would do half the trick. except if nothing is found, it eats all and counts as true here. | |
Chris 23-Oct-2005 [537] | non-bc: complement charset "bc" parse "a b c" ["a" any non-bc ["b" | "c"] to end] |
Volker 23-Oct-2005 [538] | but if it is longer, like "be", every "bi" would fail to. |
older newer | first last |