[EMAIL PROTECTED] wrote:
> Hi Petr,
>
> I'm also interested in a good challenge - and I happen to be looking for an
> opportunity to practive parse rules.
>
> If you have the time, could you release (on or off list) a more detailed
> specification for what you are trying to do? If parse can't handle it well,
> I'd like to know that that is the case and what the limitation is in your
> case.
>
Well, my abilities to create some parse rules are very limited :-) I am not
sure I would dare to create some recursive rule :-)
But OK, nothing secret here. My intention was to create some search-engine for
our Czech Amiga News site. First version was very primitive, but worked. I used
find/any, but was not satisfied with the result, as t*t would scan the string
for the next occurance in the particular news article. Too much matches was
returned then. So I thought of some mechanism, trying to limit * to word. For
e.g. standalone " * " would skip one word. I think it doesn't work either, it
was just one of my deeper experience with parser.
build-rule: func [str][
str: trim str
while [all [not empty? str (((first str) = #"?") or ((first str) =
#"*"))]][remove str]
; remove all initial "?" or "*"
if empty? str [return none]
if (last str) = #"*" [append str " "]
; ad space if last char is "*" to match the word ....
s: copy ""
non-wild: complement charset " ?*"
parse/all str [
mark:
(append s {[any [thru "}
append s rejoin [pick mark 1 {" }]
mark: skip mark 1)
:mark
some [copy txt some non-wild (append s join {"} [txt {" }])
|
some [#"?" (append s "skip ")] |
mark:
some [#"*" (append s {thru "}
append s pick mark 2
append s {" }
mark: skip mark 2)
:mark] |
some [#" " (append s {" " })]
]
to end (append s "] to end]")
]
return load s
]
rule: build-rule "*som?, mo?? *; to fi?d"
You can change the func to generate whatever you want. As I said - the problem
is with finding some "s", trying to apply the rule, and if not matched, trying
to find another occurance of "s".
But as I said - should not be a problem to let build-rule to return block,
containing two series - first one, being first char of requested string (in our
example "s", the second one, the entire rest of rule. Then let searchengine to
skip thru "s" and try to apply the rule
rules: build-rule "*som?, mo?? *; to fi?d"
first-char: first rule
rule: second rule
while [tmp: find str first-char][parse tmp rule and some other code here]
-pekr-
>
> TIA,
>
> Elan >> [: - )]
>