Re: commit and (s)
[email protected] (Dave McD)
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
First of all, as far as I understand it, the <commit>
directive only affects any following productions
within the rule it is being used. It's main purpose
is to prune that part of the parse tree for
efficiency. As far as I can tell, it does not affect
the backtracking algorithm of the parser as one might
think. It can be used with the <error> directive to
log potential errors
after a <commit> if the parse should eventually fail.
Your word(s) subrule will suceed if you get at least
one word to match. Assuming the 'bad' word is not a
EOS or EOSjunk since those are optional anyway in your
sentence rule, then your sentence rule should be
succeeding. The second time the sentence rule
executes, it will fail because of the 'bad' word and
cause the parser to backtrack. The parser will
eventually backtrack as you have described since there
are no alternate rules to be satisfied besides the
chained paragraph(s) -> sentence(s) rule. If you used
something like:
sentence: word
{record this word as my sentence, because it may be my
only one}
word(s)
{ oh, I got more than one word, append these to my
previously recorded sentence }
EOS? EOSjunk?
| <resync ...>
then you could possibly skip over the bad word or bad
sentence and move on.
Dave MC
--- Robert McArthur <[email protected]> wrote:
> Sorry if this is obvious, but I'm having problems
> with a concept. I
> think commit will do what I want but I don't know
> how to use it in the
> situation...
>
> Situation: parsing straight, but dirty, text : email
> msgs :-(
>
> (simple)text = set of paragraphs, paras = set of
> sentences etc.
>
> If I have a rule (simplified for this example) like:
>
> para: sentence(s) EOF
> sentence: word(s) EOS(?) EOSjunk(?)
>
> I'd like to commit once I've found each word
> (there's some reasoning
> behind this if it's not obvious).
>
> If I do
>
> para: sentence(s) EOF
> sentence: word(s) <commit> EOS(?) EOSjunk(?)
>
> then I still get back-tracking to the first word of
> the first sentence. Same if I
>
> para: sentence(s) <commit> EOF
> sentence: word(s) EOS(?) EOSjunk(?)
>
> What I'd like is to commit after each sentence (or
> after each
> word). How can I do this if I use the (s) format?
> Is there
> something silly in what I'm doing and obviously
> better done
> another way?
>
> Thanks for any help,
> Robert McArthur
> --
> Robert McArthur CRC for Enterprise Distributed
> System Technology
> Ph. +61 7 3365 4310 Brisbane,
> Australia
> Fax +61 7 3365 4311
> [email protected]
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/