Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

'parse trick and 'unset

 [1/3] from: shannon:ains:au at: 17-Dec-2000 1:15


Anton wrote:
> Try this out: > line1: "Ju<li>e<><><<1234>" > id: [thru "<" 3 4 digits ">"] > rule: [a: some [id | [skip b:]] (print copy/part a b)] > parse line1 rule
Nice trick, I would never have thought of it. It will really be useful for 'extract rule checking (see my last post). I was surprised by the results of the following test though:
>> parse line1 rule
Ju<li>e<><>< == true
>> line2: "Jules<1234>ffg<5678>"
== "Jules<1234>ffg<5678>"
>> parse line2 rule
** Script Error: Invalid /part count: <1234>. ** Where: print copy/part a b Weird. After some stuffing around I discovered this was because 'a and 'b were still defined from the last operation, so the values need to be cleared. This is apparently not as easy as it would seem:
>> a: "" b: ""
== ""
>> parse line2 rule
** Script Error: Invalid /part count: . ** Where: print copy/part a b
>> a: none! b: none!
== none!
>> parse line2 rule
** Script Error: copy expected range argument of type: number series port. ** Where: print copy/part a b
>> a: [] b: []
== []
>> parse line2 rule
** Script Error: Invalid /part count: . ** Where: print copy/part a b Sascha wrote:
>> is there a trick to effectively destroy >> a variable from the shell's global namespace? >> (not found in manual..) >> many thanks >> Sascha.
That's what I wanted to know but just as I was going to post this I tried something:
>> ? unset
USAGE: UNSET word DESCRIPTION: Unsets the value of a word. UNSET is a native value. ARGUMENTS: word -- Word or block of words (Type: word block)
>> unset 'a unset 'b >> parse line2 rule
** Script Error: b has no value. ** Where: print copy/part a b
>> probe line2
== "Jules<1234>ffg<5678>"
>> probe rule
== [a: some [id | [skip b:]] (print copy/part a b)] Bloody hell! That should have worked! Any clues? Finally Anton, your trick always returns true, even if it didn't find the id !: line1: "Ju<li>e<><><<no-id-here>" parse line1 rule Ju<li>e<><><<no-id-here> == true So I'll have to redefine 'rule: parse line1 rule: [a: (success: false) some [id (success: true)| [skip b:]] (print copy/part a b)] if success [do something] SpliFF

 [2/3] from: arolls::bigpond::net::au at: 17-Dec-2000 3:34


Change 'id, so that the full code is: line1: "Ju<li>e<><><<1234>" line2: "Jules<1234>ffg<5678>" digits: charset "0123456789" id: ["<" 3 4 digits ">"] rule: [a: some [id | [skip b:]] (print copy/part a b)] parse line1 rule parse line2 rule
> > Try this out: > > line1: "Ju<li>e<><><<1234>"
<<quoted lines omitted: 18>>
> cleared. This > is apparently not as easy as it would seem:
That's not the reason. The reason is because parsing line2 didn't ever set 'b. 'b was still set to point to line1, with the index at "<1234>". Why? Because in 'line2 we instantly found 2 id's and got to the end in two steps. That's because id began with [thru ">" ...], which means "jump through all input until after the first ">". This happens twice and we're finished already. Remove the 'thru, and 'id is defined more precisely. My mistake.
> Finally Anton, your trick always returns true, even if it didn't > find the id
<<quoted lines omitted: 8>>
> (print copy/part a b)] > if success [do something]
That's a good idea. Anton.

 [3/3] from: chaz:innocent at: 17-Dec-2000 15:32


At 03:34 AM 12/17/00 +1100, you wrote:
>Change 'id, so that the full code is: >line1: "Ju<li>e<><><<1234>"
<<quoted lines omitted: 10>>
>This happens twice and we're finished already. >Remove the 'thru, and 'id is defined more precisely.
Your new code makes it possible to capture what is being parsed! Thanks. block: copy [] line2: "Jules<1234>ffg<5678>" digits: charset "0123456789" id: ["<" 3 4 digits ">"] rule: [a: some [c: id d: (append block copy/part c d)| [skip b:]] (print copy/part a b)] parse line2 rule print block

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted