Quantcast

What is "FollowMatchersVisitor" exactly?

classic Classic list List threaded Threaded
4 messages Options
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What is "FollowMatchersVisitor" exactly?

fge
Hello,

I have trouble understanding what this MatcherVisitor does exactly; I cannot really make sense out of the documentation which says:

/**
 * Collects the matchers that can legally follow the given matcher according to
 * the grammar into a given list. The visitor returns true if the collected
 * matchers are all possible followers, and false if other matchers higher up
 * the rule stack can also follow.
 */

Uh, not really crystal clear, that :/

This visitor overrides DefaultMatcherVisitor and only overrides the visit method for three Matcher classes: ZeroOrMoreMatcher, OneOrMoreMatcher, SequenceMatcher.

It creates a List<Matcher> which seems to be its "production" and acts as follows:

* for ZeroOrMore or OneOrMore, it adds the submatcher to the list and returns false;
* for a SequenceMatcher, it grabs the "intTag" of the context (which is the index of the last successful matched submatcher), adds one to it, walks the rest of the children until one can match an empty match; if one matches empty, it returns true, otherwise it returns false (and "swallows" all children into the list as a result).

Now, the .getFollowMatchers() method is given a context as an argument; it goes up the context stack, visits the matcher at that context with itself and breaks if one returns true. It then returns the result.

The only user of it is the RecoveringParseRunner. It seems to be related to replaying actions or something... But frankly, at this moment I cannot really make sense out of it.

Can someone explain what this is meant to do? And why the stop condition is a "possibly empty" matcher in a Sequence?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is "FollowMatchersVisitor" exactly?

mathias
Administrator
Francis,

the RecoveringParseRunner logic is somewhat involved, no doubt!

Have you read the docs as to what exactly the logic is that it applies?:
https://github.com/sirthias/parboiled/wiki/Parse-Error-Handling#the-recoveringparserunner

It says:

> Essentially, parboiled tries to perform single-character deletion, insertion or replacement upon having recognized an unexpected input, if possible. If not, parboiled finds a suitable resynchronization rule in the current rule stack and consumes all illegal characters up to the point where the parser can be resynchronized to continue parsing.

The job of the `FollowMatchersVisitor` is the latter thing: finding the resynchronisation rules.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 1 May 2014, at 12:20, fge [via parboiled users] <[hidden email]> wrote:

> Hello,
>
> I have trouble understanding what this MatcherVisitor does exactly; I cannot really make sense out of the documentation which says:
>
> /**
>  * Collects the matchers that can legally follow the given matcher according to
>  * the grammar into a given list. The visitor returns true if the collected
>  * matchers are all possible followers, and false if other matchers higher up
>  * the rule stack can also follow.
>  */
>
>
> Uh, not really crystal clear, that :/
>
> This visitor overrides DefaultMatcherVisitor and only overrides the visit method for three Matcher classes: ZeroOrMoreMatcher, OneOrMoreMatcher, SequenceMatcher.
>
> It creates a List<Matcher> which seems to be its "production" and acts as follows:
>
> * for ZeroOrMore or OneOrMore, it adds the submatcher to the list and returns false;
> * for a SequenceMatcher, it grabs the "intTag" of the context (which is the index of the last successful matched submatcher), adds one to it, walks the rest of the children until one can match an empty match; if one matches empty, it returns true, otherwise it returns false (and "swallows" all children into the list as a result).
>
> Now, the .getFollowMatchers() method is given a context as an argument; it goes up the context stack, visits the matcher at that context with itself and breaks if one returns true. It then returns the result.
>
> The only user of it is the RecoveringParseRunner. It seems to be related to replaying actions or something... But frankly, at this moment I cannot really make sense out of it.
>
> Can someone explain what this is meant to do? And why the stop condition is a "possibly empty" matcher in a Sequence?
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/What-is-FollowMatchersVisitor-exactly-tp4024314.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML

fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is "FollowMatchersVisitor" exactly?

fge
Hello,

On Mon, May 5, 2014 at 10:55 AM, mathias [via parboiled users]
<[hidden email]> wrote:

> Francis,
>
> the RecoveringParseRunner logic is somewhat involved, no doubt!
>
> Have you read the docs as to what exactly the logic is that it applies?:
> https://github.com/sirthias/parboiled/wiki/Parse-Error-Handling#the-recoveringparserunner
>
> It says:
>
>> Essentially, parboiled tries to perform single-character deletion,
>> insertion or replacement upon having recognized an unexpected input, if
>> possible. If not, parboiled finds a suitable resynchronization rule in the
>> current rule stack and consumes all illegal characters up to the point where
>> the parser can be resynchronized to continue parsing.
>
> The job of the `FollowMatchersVisitor` is the latter thing: finding the
> resynchronisation rules.
>
> Cheers,
> Mathias
>

I admit I haven't read this all yet; right now I'm working on the test
code (I can test parse trees without having to go through string
testing now! If you are interested I can provide a pull request).

Would you mind giving a very simple, handcrafted example? Or links?

Regards,
--
Francis Galiegue, [hidden email]
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is "FollowMatchersVisitor" exactly?

mathias
Administrator
Francis,

I’m sorry but I don’t have any capacity for parboiled 1 related stuff right now.

If you have specific questions I might be able to help but longer explanations or code examples are not currenty possible.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 5 May 2014, at 12:03, fge [via parboiled users] <[hidden email]> wrote:

> Hello,
>
> On Mon, May 5, 2014 at 10:55 AM, mathias [via parboiled users]
> <[hidden email]> wrote:
>
> > Francis,
> >
> > the RecoveringParseRunner logic is somewhat involved, no doubt!
> >
> > Have you read the docs as to what exactly the logic is that it applies?:
> > https://github.com/sirthias/parboiled/wiki/Parse-Error-Handling#the-recoveringparserunner
> >
> > It says:
> >
> >> Essentially, parboiled tries to perform single-character deletion,
> >> insertion or replacement upon having recognized an unexpected input, if
> >> possible. If not, parboiled finds a suitable resynchronization rule in the
> >> current rule stack and consumes all illegal characters up to the point where
> >> the parser can be resynchronized to continue parsing.
> >
> > The job of the `FollowMatchersVisitor` is the latter thing: finding the
> > resynchronisation rules.
> >
> > Cheers,
> > Mathias
> >
>
> I admit I haven't read this all yet; right now I'm working on the test
> code (I can test parse trees without having to go through string
> testing now! If you are interested I can provide a pull request).
>
> Would you mind giving a very simple, handcrafted example? Or links?
>
> Regards,
> --
> Francis Galiegue, [hidden email]
> JSON Schema in Java: http://json-schema-validator.herokuapp.com
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/What-is-FollowMatchersVisitor-exactly-tp4024314p4024319.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML


signature.asc (858 bytes) Download Attachment
Loading...