r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

Graham
11-Oct-2005
[476]
[ copy frag n skip | copy frag to end ]
Ladislav
11-Oct-2005
[477]
or copy frag [n skip | to end]
Graham
11-Oct-2005
[478]
nope.
Ladislav
11-Oct-2005
[479]
if append "" none works as it does, then it is a problem with the 
none value
Tomc
11-Oct-2005
[480x2]
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] (print frag)
        opt[copy fraglet some bs  (print fraglet)]
        (insert tail bl join frag fraglet)
    ]
    parse/all txt [some frag-rule]
    bl
]
will prolly fail on tezt < n as well
Graham
11-Oct-2005
[482x2]
it does fail.
simpler to just check the size of the string before it gets worked 
on.
Tomc
11-Oct-2005
[484x2]
yep
but the last  line being less than n is the same thing
Ladislav
11-Oct-2005
[486]
I must say, that the NONE issue is quite annoying/inconsistent (IMO)
Graham
11-Oct-2005
[487]
yeah .. it is.
Ladislav
11-Oct-2005
[488x2]
how about this one?: copy frag [n skip | to end] (frag: any [frag 
""])
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.