parse question
[1/4] from: princepawn:mailandnews at: 14-Sep-2000 5:18
In order to improve my skills with the REBOL parse word, I thought I would go
through "Mastering Regular Expressions" by Jeffrey Freidl and do all the
examples in REBOL. Here is my first attempt and it does not work.
The script is supposed to take a list of files and indicate whether the word
setsize
occurs equally, more, or less than the number of times that the word
resetsize
occurs.
REBOL [
Title: "Balance setsize and resetsize"
]
;; q1 in my head: how do I do word boundaries?
rules: [
to "resetsize" (size-cmds: size-cmds - 1)
|
to "setsize" (size-cmds: size-cmds + 1)
]
proc: func [ filenames [block!] ] [
foreach file filenames [
size-cmds: 0
parse read to-file file rules
prin reform [ "in" file ": " ]
either size-cmds = 0 [
print "resetsize cmds matched # of setsize cmds"
][ either size-cmds > 0 [
print "resetsize cmds > # of setsize cmds"
][ print "resetsize cmds < # of setsize cmds" ]
]
]
]
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer]
free-email: http://www.MailAndNews.com
free-usenet: http://www.mailAndNews.com
; all the above is real REBOL code, believe it or not.
[2/4] from: al::bri::xtra::co::nz at: 14-Sep-2000 21:34
terrence-brannon wrote:
> rules: [
> to "resetsize" (size-cmds: size-cmds - 1)
> |
> to "setsize" (size-cmds: size-cmds + 1)
> ]
Try 'thru instead of 'to.
Note that "setsize" is equal to last seven letters of "resetsize".
Me: [
"Andrew Martin"
ICQ: 26227169
http://members.ncbi.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/
-><- ; All hail discordia!
]
[3/4] from: princepawn:mailandnews at: 14-Sep-2000 10:25
using thru did not result in correct parsing
>===== Original Message From [Al--Bri--xtra--co--nz] >terrence-brannon wrote:
>> rules: [
<<quoted lines omitted: 11>>
> -><- ; All hail discordia!
> ]
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer]
free-email: http://www.MailAndNews.com
free-usenet: http://www.mailAndNews.com
; all the above is real REBOL code, believe it or not.
[4/4] from: jeff:rebol at: 14-Sep-2000 11:37
Howdy, Terrence:
Neat stuff. Planning on making web page out of the result?
> In order to improve my skills with the REBOL parse word, I thought I would go
> through "Mastering Regular Expressions" by Jeffrey Freidl and do all the
> examples in REBOL. Here is my first attempt and it does not work.
[ . . .]
> rules: [
> to "resetsize" (size-cmds: size-cmds - 1) | to
<<quoted lines omitted: 11>>
> ] ]
> ]
Try this:
s-size: ["setsize" (size-cmds: size-cmds + 1)]
rs-size: ["resetsize" (size-cmds: size-cmds - 1)]
rules: [some [rs-size | s-size]]
-jeff
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted