• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

AltME groups: search

Help · search scripts · search articles · search mailing list

results summary

worldhits
r4wp134
r3wp1094
total:1228

results window for this page: [start: 201 end: 300]

world-name: r3wp

Group: Ann-Reply ... Reply to Announce group [web-public]
Tomc:
24-Feb-2005
if you are going to restart parse at that point maybe a skip  or 
'X here: (here: next :here) :here
Group: RAMBO ... The REBOL bug and enhancement database [web-public]
Pekr:
12-Aug-2005
So - if most ppl agree, that starting desktop and trying to connect 
to internet directly is good thing (with auto proxy detection it 
could be, without it it simply is not), then I want -i and --noinstall 
to skip Desktop launch phase - and that is what I am about to submit 
as a request, or as a bug report ...
Anton:
28-Aug-2005
Thorsten, I just quickly tested with

 port: open/direct/skip %user.r 3 probe copy/part port 20 close port

and found View beta versions 1.2.54.3.1 thru to 1.2.57.3.1e  do the 
skip correctly. Those versions are the ones with the async core, 
which was found not to be quite stable enough, and it was removed 
for the next beta version, View 1.2.100.3.1
Pekr:
5-Sep-2005
dunno, really - I tried that on linux and it did not appeared. The 
difference is only in one thing - you let os pass time-switch point, 
or you skip it. In linux, when you report time in console, you can 
see one other letter, which signals you if time shift is accounted 
for or not, but dunno how it is with Windows ...
Oldes:
18-Oct-2005
if I would like to just skip from the loop, I would use break, not 
return, but understand that carl made the cahnge for the propper 
report on errors.
Chris:
1-Dec-2005
I would say that sqlab's example was a bug, except that it is consistent 
with:
>> skip "" 5
== ""
Chris:
1-Dec-2005
>> head? skip "" 5
== true
Pekr:
1-Dec-2005
Chris - maybe it should, if you look at how skip "" 5 works. 'skip 
operation here is simply kind of doing "nothing" - trying to jump, 
but already at the end, so it jumps nowhere :-)
Volker:
1-Dec-2005
IMHO that is a bug. 
!> parse "123" [5 skip (print 1)]
== false
!> parse "123" [to 5 (print 1)]      
1
== true
Volker:
1-Dec-2005
skip makes more sense
Brett:
2-Dec-2005
>> parse {ab} [to {a} to {a} to {a} to {a} {b}]
== false
>> parse {ab} [to #"a" skip #"b"]
== true
>> parse {ab} [to #"a" to #"a" to #"a" skip #"b"]
== true
>> parse {ab} [to #"a" to #"a" to #"a" to #"a" skip #"b"]
== true
>> parse {12345} [to end to end to end to end]
== true
>> parse {12345} [to end to 6 to 10 to 100 to end]
== true
>> parse {123} [thru 4 (print 1)]
== false
>> parse {123} [to 5 skip]
== false
Brett:
2-Dec-2005
Thru seems closer semantics to skip. "To" seems to check before move 
and after move.  Which is wrong behaviour or expectations - I don't 
know.
Ladislav:
19-Apr-2006
this is the way: parse [/] [set w word! (nx: unless w = first [/] 
[[end skip]]) nx]
Anton:
23-Nov-2006
switch: func [

    "Selects a choice and evaluates the first block that follows it."

    [throw] ; <-- allows RETURN to be used by the user to jump out of 
    an enclosing function (not just this one)
    value "Value to search for."
    cases [block!] "Block of cases to search."
    /default case [block!] "Default case if no others are found."
    /all "Evaluate all matches (not just first one)"
    /local rule new
][
	rule: [
		1 1 () ; <-- value
		to block! set new block! ; <- re-use the 'case variable
		(

      if any [default none? case][default: none case: clear []] ; only 
      clear case the first time
			append case new
		)
		to end ; <--
		| skip to () ; <-- type? value
	]
	rule/3: value
	change back tail rule type? value
	rule/11: either all [type? value]['end]
	parse cases [some rule]
	do case
]
Group: Core ... Discuss core issues [web-public]
JaimeVargas:
7-Apr-2005
I hope this is useful for someone

REBOL []

rest: func [s [series!]][skip s 1]

define-object: func [
	spec [block!] 
	/local 

  arg-spec ctx-spec object-name constructor-name predicate-name attributes
		spec-rule type-spec continue? w
][
	arg-names: copy []

	continue?: [none] ;used to stop parsing
	name-rule: [set w word! (insert tail arg-names w)]

 type-rule: [set w word! (unless datatype? attempt [get w] [continue?: 
 [end skip]])]

 spec-rule: [name-rule some [name-rule opt [into [some [type-rule 
 continue?]]]]]

	if any [
		not parse spec spec-rule
		arg-names <> unique arg-names
	][
		make error! "invalid spec"
	]

    object-name: to-string first arg-names
	constructor-name: to-word join 'make- object-name
	predicate-name: to-word join first arg-names '?
	attributes: rest arg-names

	arg-spec: copy []
	foreach itm attributes [
		insert tail arg-spec reduce [
			to-word join itm '-value
			either block? w: select spec itm [w][[any-type!]]
		]
	]

	ctx-spec: copy []
	arg-names: extract arg-spec 2 1
	repeat i length? attributes [

  insert tail ctx-spec reduce [to-set-word attributes/:i to-get-word 
  arg-names/:i]
	]

	;create constructor function
	set constructor-name make function! 

  compose [(reform ["Makes a new" uppercase object-name "object with 
  attributes" mold attributes]) (arg-spec)]
		compose/only [make object! (ctx-spec)] ;body

	;create predicate function
	set predicate-name make function! 

  compose [(reform ["Determines if value is a" uppercase object-name 
  "object"]) value [object!] /local types]
		compose/deep/only [
			either (attributes) = rest first value [
				foreach itm (attributes) [
					unless any [

      [any-type!] = types: select (arg-spec) to-word join itm '-value
						find types type?/word value/:itm
					][return false]
				]
				true
			][
				false
			]
		] 
]
JaimeVargas:
7-Apr-2005
If anyone ever wanted multi-methods or function overload in rebol 
here is the answer. Enjoy ;-)

REBOL []

define-method: func [
	'name [word!] spec [block!] locals [block!] code [block!]

 /local w type-rule spec-rule continue? register-name methods-name
][
	;; first validate the spec
	continue?: [none] ;used to stop parsing

 type-rule: [set w word! (unless datatype? attempt [get w] [continue?: 
 [end skip]])]
	spec-rule: [some [word! into [type-rule continue?]]]
    unless parse spec spec-rule [make error! "invalid spec"]

	register-name: to-word join :name '-register
	methods-name: to-word join :name '-methods?
	unless value? name [
		
		context [
			dispatch-table: copy []
			
			spec-fingerprint: func [spec [block!] /local types][
				types: copy []
				foreach itm extract/index spec 2 2 [insert tail types itm/1 ]
				types
			]
			
			values-fingerprint: func [values [block!] /local types][
				types: copy []
				foreach v values [insert tail types type?/word v]
				types
			]
			

   retrieve-func: func [values [block!]][select/only dispatch-table 
   values-fingerprint values]
			
			set :name func [values [block!]][
				do compose [(retrieve-func values) (values)]
			]
			
			set :register-name func [spec code /local fingerprint pos][
				fingerprint: spec-fingerprint spec
				either found? pos: find/only dispatch-table fingerprint [
					poke dispatch-table 1 + index? pos function spec locals code
				][

     insert tail dispatch-table reduce [fingerprint function spec locals 
     code]
				]
			]
			
			set :methods-name does [probe dispatch-table]
		]
	]

	do reduce [register-name spec code]
]

define-method f [x [integer!]] [] [x + 1]
define-method f [s [block!]] [] [attempt [pick s 2]]
define-method f [x [decimal!]] [] [sine x] 

f[5] == 6
f[[one two three]] == two
f[90.0] == 1.0
Micha:
28-Apr-2005
handler: func [port ] [ 
                                    
       

          ping: to-integer  (0:00:30 - get-modes port 'timeout )* 1000
                                     

                    print [ "open" port/remote-ip  port/remote-port  "ping:" ping ]

                   insert port join  #{0401} [debase/base  skip to-hex 80 4 16 to-binary 
                   193.238.73.117 #{00} ]
           
    ]


port: make port! tcp://219.147.198.195:1080 

set-modes port [timeout: 00:01:00]

port/awake: :handler

insert tail system/ports/wait-list  port



open/binary port
Micha:
30-Apr-2005
rebol []

conn: make port! tcp://:80



black-lista: [ 69.64.51.223 194.69.207.145 80.252.0.145 194.69.207.165 
217.73.17.115]




adns: open/no-wait make port! dns:///async

adns/awake: func [port /local dat][                
		
		data: copy port

                print data
		
		false 
	]				

insert tail system/ports/wait-list adns





heandler: func [ port /local data dns  ]

               [ print "new connetion"

               serwer: first port

               client: make port! tcp://222.76.73.113:1080
              
               
               serwer/sub-port: client
               client/sub-port: serwer

               set-modes client [no-wait: true timeout: 00:01:00]
               set-modes serwer [no-wait: true ]

                          
 wait serwer
             
data: copy serwer



dns: to-tuple copy/part skip to-binary  data 4 4  

insert adns dns ;print dns name



either find black-lista dns [ close serwer  print "firtled" print 
read join dns:// dns ]
                           

                            [ insert serwer  join #{005A} [debase/base  skip to-hex serwer/port-id 
                            4 16 to-binary dns ] 



insert tail system/ports/timeout-list client

      open/binary client 

ping: to-integer  (0:01:00 - get-modes client 'timeout )* 1000 

  print [ "open" ping ]
                                                


                              insert client data

                              wait client

data: copy client



client/awake: :response

serwer/awake: :request

insert tail system/ports/wait-list  client


insert tail system/ports/wait-list  serwer







] 



       false         
]




request: func [ port /local data   ] 

              [ data: make string! 10000
               read-io port data 10000

                either data <> {} [ 
                                    insert port/sub-port data ] 

                            [  close port 

                              remove find system/ports/wait-list port port
                              print "close connetion serwer"

                              print length? system/ports/wait-list
                               ]

                 halt]




       
   


  
response: func [ port /local data   ] 

               [ data: make string! 10000
               read-io port data 10000

 
               either data <> {} [ 
                             insert port/sub-port data  ]

                            [  close port 

                              remove find system/ports/wait-list port port
                              print "close connetion client"

                              print length? system/ports/wait-list
                             ]

                 halt]




conn/awake: :heandler

set-modes conn [no-wait: false]

insert tail system/ports/wait-list  conn

open/direct/binary conn


print "proxy"

halt
Brock:
4-May-2005
there is probably a better way to skip the variable number of spaces 
following the labels you are searching for, but haven't any experience 
with parse for this yet.  With what I have provided you may be able 
to get the rest to work .  I believe you can use 'any to skip multiple 
or no occurences of a parse rule
Gordon:
6-May-2005
Hello;

  I'm wondering if there is a more efficeint way to assign values directly 
  to a block of  variables.  My example involves reading lines from 
  a file and assigning them one at a time to each variable.  Here is 
  the line format:


LineFormat: [DateStr Manufacturer MF_Part TD_Part Desc Price1 Price2 
Retail Stock Misc]

Data: read/lines Filename
Str: first Data

Then I go though the String 'Str' and do the assigns

      DateStr: First Str
      Manufacturer: Second Str
      MF_Part: Third Str
      TD_Part: Fourth Str
      Desc: Fifth str
      Price1: skip Str 5
      Price2: skip Str 6
      Retail: skip Str 7
      QOH: skip Str 8
      Misc: skip Str 9


Am I missing something obvious about assigning one block of  values 
to another block of  variables?
Micha:
7-May-2005
REBOL [Title: "proxy multiple" ] 

print "start-multiple"
 list: []

proxy: make object! [ host: 24.186.191.254
                      port-id: 29992 ]

ph: func [port][ switch port/locals/events [
                          
                          connect [insert tail list  port

                                   ping: to-integer (now/time - port/date ) * 1000 
                                   port/date: now/time

                                   print [ "open   ping: " ping ]  ]

                          close [ remove find list port
                                  init

                                  ping: (now/time - port/date ) * 1000 

                                   print ["close   ping: " ping ] close port ]

                                                ]


false ]



stop: func [] [ clear system/ports/wait-list
               forall list [close first list ]]

init: func [ /local port ][ port: make port! [ scheme: 'atcp
                                               host: proxy/host

                                               port-id: proxy/port-id
                                               awake: :ph 
                                               date: now/time ]

                            open/no-wait/binary  port


                            insert tail system/ports/wait-list  port ]



set: func [ h p ] [ proxy/host: h
                    proxy/port-id: p ]
                          

send: func [ port ][ port/date: now/time

insert port join  #{0401} [debase/base  skip to-hex 80 4 16 to-binary 
193.238.73.117 #{00}] ]
Sunanda:
7-May-2005
Any easy way of doing this? (I got a loop, but it feels there ought 
to be a more elegant way)
     a: "123123123"
     b: "12312345678"
     print skip-common a b
     "45678"      ;; string after common part of both strings
Sunanda:
7-May-2005
Gordon, your method only works for chars than happen to map to decimals. 
 Try this for an error:

print to-integer to-string to-hex to-integer to-decimal to-char "M"


Variant on Tom's to produce the same result as yours (may not work 
with 64-bit REBOL)
     form skip to-hex to-integer first "a" 6
Gordon:
7-May-2005
Here's another odd one that has be puzzled

(Notice that appending something to the Writefile variable, also 
appends it to the DateStr variable!  Very Strange!)

>> WriteFile: "WriteFileName_2005-05-07"
== "WriteFileName_2005-05-07"
>> DateStr: skip tail WriteFile -10
== "2005-05-07"
>> Success: append WriteFile "_Parsed.txt"
== "WriteFileName_2005-05-07_Parsed.txt"
>> probe DateStr
2005-05-07_Parsed.txt
== "2005-05-07_Parsed.txt"
Gordon:
7-May-2005
Yep, it just  needed a copy as in:
>> DateStr: skip tail copy WriteFile -10
== "2005-04-11"
Gregg:
28-May-2005
If REPEAT had /start and /skip refinements...
JaimeVargas:
1-Jun-2005
That seems to be the norm with Rebol. But we are so trained to look 
for complex explanations that we skip the path of less surprise.
Micha:
5-Jun-2005
rebol [ title: "SOCKS SERWER" ]

conn: make port! tcp://:800

proxy: make object! [ host: 208.59.117.69
                      port: 2988  ]



black-lista: [ 69.64.51.223 194.69.207.145 80.252.0.145 194.69.207.165 
217.73.17.115]




adns: open/no-wait make port! dns:///async

adns/awake: func [port /local data][                
		
		data: copy port

                print data
		
		false 
	]				

insert tail system/ports/wait-list adns





heandler: func [ port /local data dns  serwer client]

               [ serwer: first port

                          
 wait serwer
             
data: copy serwer
;data: make string! 10000
;read-io serwer data 10000
print ["data1" to-binary data]

dns: to-tuple copy/part skip to-binary  data 4 4  

insert adns dns ;print dns name



either find black-lista dns [ close serwer  print "firtled" print 
read join dns:// dns ]
                           
                            [ print "new connetion"

insert serwer  join #{005A} [debase/base  skip to-hex serwer/port-id 
4 16 to-binary dns ] 


client: make port! [ scheme: 'tcp 
                     host: system/words/proxy/host
                     port-id: system/words/proxy/port
]



;insert tail system/ports/timeout-list client

      open/no-wait/binary/async/direct client :response


client/sub-port: serwer





insert tail system/ports/wait-list  client

client/date: data

serwer/sub-port: client

serwer/awake: :request









] 



       false         
]




request: func [ port /local data  f ] 

              [ data: make string! 10000
               read-io port data 10000


if f: find data "GET /favicon.ico" [ insert port "HTTP/1.1 404 Not 
Found" 
                                      print "favicon.ico"]
 


                either (data <> {}) and not f [     print [ "data3" data  ]
                              

                                if error? try [    write-io port/sub-port data length? data ][ print 
                                "error: close serwer"]
                                   ; insert port/sub-port data 
]

                            [  close port 

                              remove find system/ports/wait-list port port
                               close port/sub-port

                              remove find system/ports/wait-list port/sub-port port/sub-port
                              print "close connetion client"

                               print length? system/ports/wait-list
                               ]

               false]




       
   


  
response: func [ port e a /local data  f  ] 

               [  switch e [ open [ insert port port/date ]
                                    
                             read [ data: copy/part port a

                                   either ( a <> 8 ) [write-io port/sub-port data length? data] 

                                                     [  insert tail system/ports/wait-list  port/sub-port ]
                                    ]
                                     
                             close [ close port 

                                     remove find system/ports/wait-list port port
                                     close port/sub-port

                                     remove find system/ports/wait-list port/sub-port port/sub-port

                                       print "close connetion serwer"

                                      print length? system/ports/wait-list]
 

                          ]   ]


start: func [] [

conn: make port! tcp://:800

conn/awake: :heandler

set-modes conn [no-wait: false]

insert tail system/ports/wait-list  conn

open/no-wait/direct/binary conn ]


stop: func [][ close conn
               remove find system/ports/wait-list conn]

set-proxy: func [ h p ] [ proxy/host: h
                          proxy/port: p ]
                          


print "proxy"

lay:  layout [ backdrop blue
              across  h3  red "PROXY" f: field 145 
              return
              button green "start" [ p: parse f/text  ":"
                                     remove find p "" 

                                     set-proxy  to-tuple p/1  to-integer p/2
                                     source p
                                    
                                     start]
              button  green "stop" [f/text: "" stop ] ]

view/offset lay 4x29 
halt
Graham:
11-Jun-2005
; open mailbox

len: length? mailbox
bounces: copy []

for i 1 len 1 [
	email: import-email raw: pick mailbox i
	if email/reply-to = "<>" [
		append bounces i
		print [ "Bounce at" i ]
	]
]

; remove bounces

reverse bounces
foreach num bounces [
	mailbox: head mailbox
	mailbox: skip mailbox ( num - 1 )
	remove mailbox
]

close mailbox
BrianH:
18-Jun-2005
The only time I've found it useful to use index is when using values 
in one series as a key to values in another series. Kind of rare 
when you have select/skip, but sometimes you don't want to modify 
the data series. All right, since RAMBO says that there are problems 
with select/skip right now, maybe not so rare.
Volker:
18-Jun-2005
IIRC that problems relate to select/skip on strings, which is not 
very common anyway.
Volker:
18-Jun-2005
Using Select/Skip on a String! doesn't behave in a manner consistant 
with the way that it acts on a Block! which leads to a state where 
it freezes the REBOL Interpreter.
Volker:
25-Jul-2005
b: ["s1" "s2" "s3" "s1"]
parse b[any[to "s1" p: (p/1: copy "t0") skip]]
? b
Robert:
21-Aug-2005
Does read/skip work in the new releases?
Anton:
21-Aug-2005
Doesn't look like it. I think file skip was removed because of moving 
to new Windows api.
Anton:
21-Aug-2005
you mean  "file seek"   or  "open/skip".
Anton:
21-Aug-2005
It was in the experimental releases, like View 1.2.57.3.1
Test with a line like:
	print copy/part read/skip %user.r 10 40    ;   compare 10 with 0
JaimeVargas:
24-Aug-2005
find-each: func [dataset [series!] value /local result][
    result: copy [] 
    parse dataset [

        some [set word string! (if find word value [append result word]) 
        | skip]
    ] 
    result
]


>> find-each ["Jaime" 1 "Carl" 2 "Cyphre" 3 http://google.com"Ladislav"] 
"a"   
== ["Jaime" "Carl" "Ladislav"]
Pekr:
13-Sep-2005
Hi .... as me and my friend use RebDB, we currently have to simulate 
'join functionality. I gave the idea a little thought, and I remembered, 
there are Rebol natives as 'union and 'intersest. They even do work 
with /skip refinement ..... and we miss that 'join functionality. 
Would it be difficult to add such functionality to work with blocks 
for 'union, or have a new native? I have an example:

; structure - name, last name, address, zip code

table1: [ "Petr" "Krenzelok" "Navsi 645" "739 92"  "Johny" "Handsome" 
"Dreamland 777" "777 77"]

; structure - age, place of birth
table2: [ 33 "Trinec" 38 "Some town"]

join-block/skip table1 table2 4 2


Do you think it would be usefull functionality to have as a native? 
Would be fast and would give us db 'join functionality to some extent 
....
Benjamin:
21-Sep-2005
read/skip never work's will this bug ever be fixed ?
Ingo:
22-Sep-2005
Why do I get an error "invalid argument" here?


>>       comp-length: func [a b][compare (length? a/2) (length? b/2)]
>>       sort/skip/compare files 2 :comp-length
** Script Error: Invalid argument: 2
** Near: sort/skip/compare files 2 :comp-length
>> source compare
compare: func [

    {compares to values, and returns -1 / 0 / 1 for values a<b / a=b 
    / a>b}
    a b
    /local return
][
    case [
        a > b [-1]
        a < b [1]
        true [0]
    ]
]

REBOL/View 1.3.1.3.1
Sunanda:
22-Sep-2005
Add /all to the sort:
sort/all/skip/compare files 2 :comp-length
Sunanda:
22-Sep-2005
It works for me:
files: copy  [%abc [%a/ %xx/] %def [%xyz/]]
compare: func [

        {compares to values, and returns -1 / 0 / 1 for values a<b / a=b 
        / a>b}
        a b
        /local return
    ][
        case [
                a > b [-1]
                a < b [1]
                true [0]
            ]
    ]


print system/version
sort/compare/all/skip files  :compare 2
probe files

1.3.1.3.1
== [%def [%xyz/] %abc [%a/ %xx/]]
Group: Make-doc ... moving forward [web-public]
Robert:
12-Jan-2005
=include How about an option to disable it? The CGI could insert 
something like =option include-off into the submitted text and than 
MDP will skip =inlcude commands.
Group: Parse ... Discussion of PARSE dialect [web-public]
BrianH:
22-Aug-2005
Tomc: "you may be better off  with :here skip to gaurentee progress"


Put the skip after the paren and I may agree with you there. Of course 
you would skip the number of chars in the replacement text then.
BrianW:
22-Aug-2005
Here's what I have right now:

		markup-chars: charset "*_@"
		non-markup: complement markup-chars
		inline-tags: [
			"*" "strong"
			"_" "em"
			"@" "code"
		]

		markup-rule: [
			any non-markup
			any [
				[ a: "*" b: to "*" c: skip d: |
				  a: "_" b: to "_" c: skip d: | 
				  a: "@" b: to "@" c: skip d: ] :a (
					change/part a rejoin [ 
						"<" select inline-tags copy/part a b ">"
						copy/part b c 
						"</" select inline-tags copy/part a b ">"
					] d
				) any non-markup
			]
			to end
		]
		parse text markup-rule
BrianH:
22-Aug-2005
If you want to guarantee progress with my and your examples (and 
better support multichar markup tags) change the last
  any non-markup
to
  any non-markup | skip
and that would do it.
BrianW:
22-Aug-2005
okay, here's a slightly tweaked version that uses a multichar markup 
tag:

        markup-chars: charset "[*_-:---]"
        non-markup: complement markup-chars
        inline-tags: [
            "*" "strong"
            "_" "em"
            "@" "code"
            "--" "small"
        ]

        markup-rule: [
            any non-markup
            any [
                [ a: "*" b: to "*" c: skip d: |
                  a: "_" b: to "_" c: skip d: | 
                  a: "@" b: to "@" c: skip d: |
                  a: "--" b: to "--" c: skip skip d: ] :a (
                    change/part a rejoin [ 
                        "<" select inline-tags copy/part a b ">"
                        copy/part b c 
                        "</" select inline-tags copy/part a b ">"
                    ] d
                ) any non-markup | skip
            ]
            to end
        ]
        parse/all text markup-rule
Graham:
10-Oct-2005
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
]
Ladislav:
11-Oct-2005
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?
Ladislav:
11-Oct-2005
copy frag n skip should be perfectly OK
Graham:
11-Oct-2005
[ copy frag n skip | copy frag to end ]
Ladislav:
11-Oct-2005
or copy frag [n skip | to end]
Tomc:
11-Oct-2005
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
]
Ladislav:
11-Oct-2005
how about this one?: copy frag [n skip | to end] (frag: any [frag 
""])
Tomc:
11-Oct-2005
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
]
Ladislav:
11-Oct-2005
>> n: 5 parse "" [copy frag [n skip | to end] (frag: any [frag ""])]
== true
>> frag
== ""
Ladislav:
11-Oct-2005
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
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
]
Tomc:
11-Oct-2005
it was the copy frag 1 n skip
Ladislav:
16-Oct-2005
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.
Volker:
23-Oct-2005
i use 
 "a" any[ "b" | "c" | skip ] to end
Even slower and less elegantly, but works.
MichaelB:
23-Oct-2005
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. :-)
Volker:
23-Oct-2005
Maybe i used this?
 parse s ["a" some[ "be" break | "ce" break | skip] p: to end]

if nothing is found, it skips to the end. returns true, but if you 
require something after it,
that fails (because already at end).
Volker:
31-Oct-2005
or "end skip". with break the parsed part counts as success. with 
end skip it counts as failure and backtracks.
Volker:
31-Oct-2005
the general way:

 rule: [  ( dummy-rule: [] if not ok? [ dummy-rule: [end skip] ) dummy-rule 
 ]
BrianH:
1-Nov-2005
I didn't do a really useful example, just one to demonstrate the 
current way of faking the behavior.
Example:  [if (test) | ...]
Fix:  [(unless test [dummy: [end skip]]) dummy | ...]
BrianH:
1-Nov-2005
See, this is why I wanted that if clause. It's so easy to mess up 
the workaround.
Fix:  [(dummy: unless test [[end skip]]) dummy | ...]
Volker:
4-Nov-2005
should work like thru.  "any non-caret" is like "to caret", then 
skipping it is like "thru caret". without caret it would go to end, 
and then the final skip fail.
Graham:
4-Nov-2005
pipe: charset "|" 
nonpipe: complement charset "|"
caret: charset "^^"
non-caret: complement caret
digits: charset [ #"0" - #"9" ]

labsupplier: 
hl7level: 
datetime:
patient:
labno:
labno2: none


nte-rule: [ "NTE" pipe digits pipe 1 skip pipe copy notes to newline 
(append txt notes) ]
oru-rule: [ "ORU" pipe copy labno some digits pipe ]
datetime-rule: [ copy datetime some digits ] 

msh-rule: [ "MSH" pipe some nonpipe pipe copy labsupplier some nonpipe 
pipe some nonpipe pipe copy hl7level 
	some nonpipe 2 skip datetime-rule 2 skip oru-rule thru newline 
]

msa-rule: [ "MSA" pipe 3 skip copy labno2 some digits thru newline 
]

pid-rule: [ "PID" 2 skip some nonpipe pipe some digits pipe some 
nonpipe pipe copy patient some nonpipe 

 2 pipe copy dob some digits pipe copy gender [ #"F" | #"M" ] thru 
 newline 
]
obr-rule: [ "OBR" pipe 1 digits pipe copy drcode some nonpipe
	pipe some nonpipe pipe copy panelcode some nonpipe
	pipe 1 skip pipe copy bleeddate some digits
	pipe copy reportdate some digits 
	pipe 2 skip pipe 2 skip

 5 pipe copy bleeddate some digits 2 pipe copy requestdr some nonpipe	
	3 pipe copy nzcouncilcode some nonpipe thru newline
]

txt: copy ""
cnt: 1

obx-rule: [ "OBX" pipe copy cntr some digits ( 

  if cnt <> to-integer cntr [ print "halted as out of sequence" halt] 
  cnt: cnt + 1 
	) 
	pipe  
		[
			st-rule | 
			ft-rule 
	]
]



ft-rule: [ "FT" pipe some non-caret any caret copy comm some non-caret 
any caret 3 skip 

 copy comments some nonpipe (repend txt [ comm " " comments newline 
 ]) thru newline ]


st-rule: [ "ST" pipe some non-caret any caret copy testtype some 
non-caret  
	any caret 3 skip copy testresult some nonpipe 
	pipe [ pipe | copy units some nonpipe pipe ]
	copy range some nonpipe thru newline

 ( repend txt [ testtype " " testresult " " units " " range newline 
 ] )
]
	
record-rule: [
	( cnt: 1 txt: copy "" )
	msh-rule
	msa-rule
	pid-rule
	obr-rule
	obx-rule
	[ some obx-rule ]
	nte-rule
]

parse read %hl7data.txt record-rule
print [ labsupplier hl7level datetime patient 
labno labno2 dob gender panelcode bleeddate reportdate 
requestdr nzcouncilcode newline txt
]
Graham:
4-Nov-2005
hl7msg: make object! [
	msh: []
	msa: []
	pid: []
	obr: []
	obx: []
	nte: []
]

datafile: %hl7data.txt

parse-hl7msg: func [datafile [string!]
	/local segment segbl v
] [
	hl7: make hl7msg []
	trim/head/tail datafile
	append datafile {^/}
	line-rule: [copy segment to "^/" 1 skip (
			segbl: parse/all segment "|"
			either segbl/1 = "OBX" [
				insert/only tail hl7/obx skip segbl 1
			] [
				v: to-word segbl/1
				insert hl7/:v skip segbl 1
			]
		)
	]
	parse/all datafile [ some line-rule ]
	hl7
]

test: parse-hl7msg read datafile
Anton:
5-Mar-2006
Man, I wish you could do:

	parse [1][integer! -1 skip]

and arrive back at the head of the input.
Oldes:
7-Mar-2006
count-word-frequency: func[
	"Counts word frequency from the given text"
	text [string!] "text to analyse"
	/exclude ex [block!] "words which should not be counted"
	/local counts f wordchars nonwordchars
][
	counts: make hash! 100000

 wordchars: charset [#"a" - #"z" #"A" - #"Z" "̊؎ύѪ"]
	nonwordchars: complement wordchars
	parse/all text [
		any nonwordchars
		any [
			copy word some wordchars (
				;probe word
				if any [not exclude none? find ex word][
					either none? f: find/tail counts word [
						repend counts [ word 1 ]
					][
						change f (f/1 + 1)
					]
				]
			)
			any nonwordchars
		]
	]
	counts: to-block counts
	sort/skip/compare/reverse counts 2 2
	new-line/skip counts true 2
]
BrianH:
27-Jun-2006
You can drop one charset by changing [non-alpha | end] to [alpha 
end skip | end | none] .
BrianH:
27-Jun-2006
No, that would break out of the enclosing all loop. The end skip 
will always fail and proceed to the next alternate.
Tomc:
27-Jun-2006
capital: charset {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
latipac: complement capital
rule: [
    any latipac here:
    copy token some capital there:
    (all[ 4 < length? token
        insert :there "</strong>"
        insert :here "<strong>"
        there: skip :there 16
    ])
    :there
]
parse/all/case txt [some rule]
Tomc:
27-Jun-2006
capital: charset {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
latipac:  complement capital
ws: charset { ^/^-}
rule: [
    any latipac here:
    copy token some capital there:
    opt [some ws
        (all[ 4 < length? token
            insert :there "</strong>"
            insert :here  "<strong>"
            there: skip :there 16]
        )
    ]
    :there
]
parse/all/case txt [some rule]
Tomc:
28-Jun-2006
capital: charset {ABCDEFGHIJKLMNOPQRSTUVWXYZ}
ws: charset { ^/^-}
latipac: difference complement capital ws


sub-rule: [
	some capital there:
	[ws | end]
	(all[ 4 < length? copy/part :here :there
		insert :there "</strong>"
		insert :here  "<strong>"
		there: skip :there 17]
	)
]
rule: [
	any latipac 
	[	some ws here:
		sub-rule
	]|[skip there:]
	:there
]
parse/all/case txt [here: opt sub-rule some rule]
BrianH:
29-Jun-2006
Volker, it still might be a good point that you can skip a step with 
parse, depending on the listener. Parse is more of a compiler-interpreter 
really. The real point I was making was about the lookahead.
Graham:
1-Jul-2006
Trying to do some macro expansion in text ...

This is not working :(

expand-macros: func [tmp [string!] macros [block!]
	/local white-rule rule len lexp
] [
	white-rule: charset [#" " #"^/"]
	foreach [macro expansion] macros [
        len: length? macro
		lexp: length? expansion
		rule:  compose/deep copy [

            [ to here: white-rule (macro) white-rule ( change/part here expansion 
            len  ?? macro) lexp skip ]
            to end
        ]
		parse/all tmp [some [rule]]
	]
	tmp
]
BrianH:
1-Jul-2006
expand-macros: func [data [string!] macros [block!]
	/local whitespace macro-rule macro here there
] compose [
	whitespace: (charset " ^/")
    macro-rule: make block! length? macros
	foreach [macro expansion] macros [
        macro-rule: insert insert macro-rule macro '|
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        here: copy macro macro-rule there: [whitespace | end] (

            there: change/part here select/skip macros macro 2 there
        ) :there |
        skip
    ]]
    macro-rule: none
    data
]
BrianH:
1-Jul-2006
expand-macros: func [data [string!] macros [block!]
    /local whitespace macro-rule macro here there
] compose [
    whitespace: (charset " ^/")
    macro-rule: make block! length? macros
    foreach [macro expansion] macros [
        macro-rule: insert insert macro-rule macro '|
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        here: copy macro macro-rule there: [whitespace | end] (

            there: change/part here select/skip macros macro 2 there
        ) :there |
        skip
    ]]
    macro-rule: none
    data
]
BrianH:
1-Jul-2006
expand-macros: func [data [string!] macros [block!]
    /local whitespace macro-rule macro expansion here there
] compose [
    whitespace: (charset " ^/")
    macro-rule: make block! 2.5 * length? macros
    foreach [macro expansion] macros [
        macro-rule: insert macro-rule
            compose [here: (macro) there: [whitespace | end] '|]
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        macro-rule (
            macro: copy/part here there

            there: change/part here select/skip macros macro 2 there
        ) :there |
        skip
    ]]
    macro-rule: none
    data
]
BrianH:
1-Jul-2006
expand-macros: func [data [string!] macros [block!]
    /local whitespace macro-rule macro expansion here there
] compose [
    whitespace: (charset " ^/")
    macro-rule: make block! 2.5 * length? macros
    foreach [macro expansion] macros [
        macro-rule: insert macro-rule
            compose [here: (macro) there: [whitespace | end] |]
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        macro-rule (
            macro: copy/part here there

            there: change/part here select/skip macros macro 2 there
        ) :there |
        skip
    ]]
    macro-rule: none
    data
]
BrianH:
1-Jul-2006
expand-macros: func [data [string!] macros [block!]
    /local whitespace macro-rule macro expansion here there
] compose [
    whitespace: (charset " ^/")
    macro-rule: make block! 2.5 * length? macros
    foreach [macro expansion] macros [
        macro-rule: insert macro-rule
            compose [here: (macro) there: [whitespace | end] |]
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        macro-rule (
            macro: copy/part here there

            there: change/part here select/skip macros macro 2 there
        ) :there |
        thru whitespace
    ] to end]
    macro-rule: none
    data
]
BrianH:
1-Jul-2006
; Now whitespace is dealt with
expand-macros: func [data [string!] macros [block!]
    /local whitespace macro-rule macro expansion here there
] compose [
    whitespace: (charset " ^/")
    macro-rule: make block! 2.5 * length? macros
    foreach [macro expansion] macros [
        macro-rule: insert macro-rule
            compose [here: (macro) there: [whitespace | end] |]
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [any whitespace [
        macro-rule (
            macro: copy/part here there

            there: change/part here select/skip macros macro 2 there
        ) :there |
        to whitespace
    ]] to end]
    macro-rule: none
    data
]
BrianH:
1-Jul-2006
expand-macros: func [data [string!] macros [block!]
    /local ws non-ws macro-rule macro expansion here there
] compose [
    ws: (charset " ^/") non-ws: (complement charset " ^/")
    macro-rule: make block! 2.5 * length? macros
    foreach [macro expansion] macros [
        macro-rule: insert macro-rule
            compose [here: (macro) there: [ws | end] |]
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [any ws [
        macro-rule (
            macro: copy/part here there

            there: change/part here select/skip macros macro 2 there
        ) :there |
        some non-ws
    ]] to end]
    macro-rule: none
    data
]
Pekr:
19-Jul-2006
REBOL []

template: {

<b><!--[mark-x]-->Hello x!<!--/[mark-y]--></b>
<b><!--[mark-y]-->Hello y!<!--/[mark-y]--></b>
<b><!--[mark-z]-->Hello z!<!--/[mark-z]--></b>
<b><!--[mark-w]-->Hello w!<!--/[mark-w]--></b>

}

parse/all template [
   some [
         thru "<!--["
         copy mark to "]-->"
         "]-->" 
         start:
         copy text to "<!--/["
         end:
         "<!--/[" mark "]-->"
         (print text)
         |
         skip
    ]
]           
         
halt
Pekr:
19-Jul-2006
this one works better for me:

parse/all template [
   some [
         thru "<!--["
         copy mark to "]-->"
         "]-->" 
         start:
         copy text to "<!--/["
         end:
         "<!--/[" 

         [mark "]-->" (print text) | (print ["not found end of: " mark]) :start]
         |
         skip
    ]
]
Group: Dialects ... Questions about how to create dialects [web-public]
Volker:
16-Sep-2006
rebol [
    Title: "Immersive" 
    Usage: {
>> fed
fed> p 3 This is a demo line, its not loadable :)
p with 3 " This is a demo line, its not loadable :)"
fed> print "This is pure rebol"
This is pure rebol
fed> "this too"
== "this too"
fed>
}
] 
ctx-fed: context [
    arg-lens: [p 2] 
    line: cmd: none 
    last-err: none 

    p: func [lineno line] [print ["p with" lineno mold line] exit] 
    t: func [lineno] [print ["t with" lineno] exit] 
    e: func ["format err"] [throw last-err] 
    do-line: func [line /local arg-len-pos res] [
        set [val rest] load/next line 
        either arg-len-pos: find/skip arg-lens val 2 [
            cmd: reduce [val] 
            loop arg-len-pos/2 - 1 [
                set [val rest] load/next rest 
                append cmd val
            ] 
            append cmd rest
        ] [
            cmd: load/all line
        ] 
        bind cmd self 
        case [
            error? set/any 'res try [do cmd] [
                probe disarm last-err: res
            ] 
            value? 'res [print ["==" mold :res]]
        ]
    ] 
    rebol/words/fed: func [] [
        forever [
            do-line ask "fed> "
        ]
    ]
] 
fed
Group: Rebol School ... Rebol School [web-public]
Geomol:
25-Jun-2007
Or you can do something like:

fp: open/lines %file.txt
until [
	line: first fp
	if find skip line 115 "Page" [print "new page"]
	tail? fp: next fp
]
close fp
Geomol:
26-Jun-2007
This is a way without copies:
str: "----+-----"

for Count 10 125 10 [change skip str either Count < 100 [8][7] Count 
prin str]
Sunanda:
6-Jul-2007
Not sure this is a case for parse......You seem to have four types 
of line:
-- those with "page" in a specific location on the line
-- those with "name" in a specific location on the line
-- those with "member" in a specific location on the line

-- others which are to be ignored .... eg your orginal line 6 "Line 
6       600    Desc 1 text         12/23/03"

What I would do is:
* use read/lines to get a block

* for each line in the block, identify what record type it is by 
the fixed literal .... something like: if "page" = copy/part skip 
line 25 4 [....]

* perhaps use parse to extract the items I need, once I know the 
line type
***

If you just use parse in the way you propose, you run the risk of 
mis-identifying lines when there is a member called "page" or "name"
Group: rebcode ... Rebcode discussion [web-public]
BrianH:
18-Oct-2005
In the meanwhile, ou can do it yourself:

pickz hi b 0
pickz lo b 1
lsl hi 8
add hi lo
skip b 2
Geomol:
18-Oct-2005
Series in rebcode are offset-1 based like normal (except image positions 
in DRAW). Would it be a good idea to make them offset-zero based 
in rebcode? Example: if I wanna read a pixel value at a certain position 
in REBOL, I could write:
image/1
or
first skip image position
(If position was 0x0, I'll get the first pixel.)

If I pick an image in rebcode at offset 0, I get an out of range 
error. It's a tough decision, but what seems most 'correct'?
BrianH:
25-Oct-2005
I get generic add by doing this:
    to-dec a
    to-dec b
    addd a b

You can skip one or both conversions if you can trace the type flow 
and be sure of the data types of the arguments.
Group: !Cheyenne ... Discussions about the Cheyenne Web Server [web-public]
Dockimbel:
2-Jun-2007
It just skip it.
Graham:
10-Jun-2007
url-encode: func [
    {URL-encode a string}
    data "String to encode"
    /local new-data
][
    new-data: make string! ""
    normal-char: charset [
        #"A" - #"Z" #"a" - #"z"
        #"@" #"." #"*" #"-" #"_"
        #"0" - #"9"
    ]
    if not string? data [return new-data]
    forall data [
        append new-data either find normal-char first data [
            first data
        ][

            rejoin ["%" to-string skip tail (to-hex to-integer first data) -2]
        ]
    ]
    new-data
]
Oldes:
10-Jun-2007
I use:
url-encode: func [
    "URL-encode a string" 
    data "String to encode" 
    /local new-data
][
    new-data: make string! "" 
    normal-char: charset [
        #"A" - #"Z" #"a" - #"z" 
        #"@" #"." #"*" #"-" #"_" 
        #"0" - #"9"
    ] 
    if not any [string? data binary? data] [return data] 
    parse/all data [any[
    	  copy tmp some normal-char (insert tail new-data tmp)

     | copy tmp some #" " (insert/dup tail new-data #"+" length? tmp)
    	| copy tmp 1 skip (

      insert tail new-data rejoin ["%" as-string skip tail (to-hex to integer! 
      to char! tmp) -2]
    	)
	]]
    new-data
]
Graham:
14-Jul-2007
and from Cheyenne


## Error in [uniserve] : On-received call failed with error: make 
object! [
    code: 305
    type: 'script
    id: 'invalid-arg
    arg1: none
    arg2: none
    arg3: none
    near: [parse/all data [
            some [
                s: to bound e: (
                    if e <> s [
                        either wrt? [
                            insert/part tmp/port s skip e -2
                        ] [
                            insert/part tail req/in/content s e
                        ]
                    ]
                )
                s: bound [
                    "--" to end s: break
                    | thru crlfcrlf e: (
                        insert/part tail req/in/content s e

                        if wrt?: to logic! find/part s "Content-Type" e [

                            append tmp/files name: make-tmp-filename

                            repend req/in/content [mold name crlf]
                            if tmp/port [close tmp/port]
                            tmp/port: open/mode name [
                                binary direct no-wait write new
                            ]
                        ]
                    )
                ]
            ]
        ]
        tmp/buffer: either
    ]
    where: 'process-content
] !
201 / 122812[3] 45...910111213