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

World: r3wp

[Parse] Discussion of PARSE dialect

Graham
8-Oct-2005
[453]
no matter...
Brock
9-Oct-2005
[454]
Not an expert, but if you ask, you never know!!!
Graham
10-Oct-2005
[455x3]
I want to split a text string at n characters but not in the middle 
of a word ie. split at the next space.
split-text: func [ txt n 
	/local frag result bl
][
    bl: copy []
    result: copy ""

    frag-rule: compose/deep [ copy frag (n) skip (print frag append result 
    frag) copy frag to #" " (if not none? frag [ print frag append result 
    frag ]
append bl copy result clear result) ]
    parse/all txt [ some frag-rule ]
    bl
]
works outside the function, but not inside :(
Ladislav
11-Oct-2005
[458]
compose/deep [ copy frag (n) skip (print frag append result frag) 
copy frag to #" " (if not none? frag [ print frag append result frag 
]
append bl copy result clear result) ]


looks suspicious to me - don't forget that your parens are there 
for two different purposes. My guess is, that you don't need compose?
Graham
11-Oct-2005
[459x2]
I think I tried it without the compose ...
I'll give it another go.
Ladislav
11-Oct-2005
[461]
copy frag n skip should be perfectly OK
Graham
11-Oct-2005
[462]
hmm.  that works.  except I miss the last piece of the text as if 
last piece less than n, it doesn't get copied.
Ladislav
11-Oct-2005
[463]
example of what you get and what want?
Graham
11-Oct-2005
[464x2]
split-text "this is a sentence" 11
[]
I want [ "this is a sentence" ]
Ladislav
11-Oct-2005
[466]
how about:

    copy frag [to #" " | to end]
Graham
11-Oct-2005
[467x2]
yah! that works.
I tried putting in an alternate rule of " | copy frag to end " but 
that hung the parser.
Ladislav
11-Oct-2005
[469x2]
this should work too:

    [copy frag #" " | copy frag to end]
rather:  [copy frag to #" " | copy frag to end]
Graham
11-Oct-2005
[471]
Hmm.  It's failing when the text is less than n.
Ladislav
11-Oct-2005
[472]
strange
Graham
11-Oct-2005
[473x2]
[ copy frag n | copy frag to end ]
at the beginning I guess
Ladislav
11-Oct-2005
[475]
aha, this one, yes, right
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?)