Is it possible to manage partial match properly?

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

Is it possible to manage partial match properly?

lquerel
I try to create a mini java expression interpreter to build an interactive console. Parse and interpret a valid expression is easy and cool with Parboiled. Thanks Mathias!
Now I would like to build a smart completion system on top of that. Something similar to the expression evaluator found in Intellij. What is the best approach to do that? Ideally I would like to retrieve a snapshot of the valuestack just before the first error occurs.

Thanks

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

Re: Is it possible to manage partial match properly?

mathias
Administrator
Laurent,

I'm not sure what exactly you current architecture looks like, so it's hard for me to recommend any specific solution.
What ParseRunner are you using?

Cheers,
Mathias

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

On 08.09.2011, at 10:57, lquerel [via parboiled users] wrote:

> I try to create a mini java expression interpreter to build an interactive console. Parse and interpret a valid expression is easy and cool with Parboiled. Thanks Mathias!
> Now I would like to build a smart completion system on top oh that. Something similar to the expression evaluator found in Intellij. What is the best approach to do that? Ideally I would like to retrieve a snapshot of the valuestack just before the first error occurs.
>
> Thanks
>
> Laurent  
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Is-it-possible-to-manage-partial-match-properly-tp3319076p3319076.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

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

Re: Is it possible to manage partial match properly?

lquerel
Mathias,

Some clarifications.

Currently I use the ReportingParseRunner (Java version). My grammar is pretty simple, see below for an excerpt.

    Rule JavaExpression() {
        return FirstOf(
                Assignment(),
                ObjectMethodInvocation(),
                Literal(),
                EOI
        );
    }

    Rule ObjectMethodInvocation() {
        return Sequence(
                ObjectIdentifier(),
                ACTION(actions.objectId()),
                ZeroOrMore(MethodCall())
        );
    }

    Rule Assignment() {
        return Sequence(
                ObjectIdentifier(),
                ACTION(actions.objectId()),
                EQUAL,
                ZeroOrMore(Sequence(ObjectIdentifier(), ACTION(actions.objectId()), EQUAL, ACTION(actions.assign()))),
                ObjectMethodInvocation(),
                ACTION(actions.assign()));
    }

    Rule ObjectIdentifier() {
        return Identifier();
    }

    Rule MethodCall() {
        return Sequence(
                DOT,
                Identifier(),
                push(match()),
                Arguments(),
                ACTION(actions.methodCall())
        );
    }

    Rule Identifier() {
        return Sequence(Letter(), ZeroOrMore(LetterOrDigit()), Spacing());
    }
AST
    Rule Arguments() {
        return Sequence(
                LPAR,
                push(new ArgsNode()),
                Optional(Sequence(Literal(), ACTION(actions.addArg())), ZeroOrMore(COMMA, Sequence(Literal(), ACTION(actions.addArg())))),
                RPAR
        );
    }
 
...

I use the stack approach to build my own AST. When the parsing is done I'm able to iinterpret java expression such as:

foo = obj.method1(1,2,3).method2(true)

Well, my main goal is to build an interactive console with a good support for smart completion. So when the user hits the TAB key on the following expression:

foo = obj.method1(1,2,3).method2([TAB]

I would like to suggest the expression

foo = obj.method1(1,2,3).method2(boolean)

But my current AST contains only the node for method1 because the method2 is not fully recognised by the parser. So if my understanding is good, the parser removes all nodes stacked for the last partial rule.

Best

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

Re: Is it possible to manage partial match properly?

mathias
Administrator
Laurent,

when you feed "foo = obj.method1(1,2,3).method2(" to your parser the ReportingParseRunner should come back with an error, since the input is not a legal statement.
The error will be of type "InvalidInputError", which contains all failed Matchers as a list.
Probably the easiest way to do something like smart completion is to suggest something based on this list of failed Matchers.

Anything more elaborate (like suggesting/completing identifiers) will likely require a completely different approach, where you need to look at a partially constructed AST and maybe even higher level structures.

Cheers,
Mathias

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

On 09.09.2011, at 11:36, lquerel [via parboiled users] wrote:

> Mathias,
>
> Some clarifications.
>
> Currently I use the ReportingParseRunner (Java version). My grammar is pretty simple, see below for an excerpt.
>
>     Rule JavaExpression() {
>         return FirstOf(
>                 Assignment(),
>                 ObjectMethodInvocation(),
>                 Literal(),
>                 EOI
>         );
>     }
>
>     Rule ObjectMethodInvocation() {
>         return Sequence(
>                 ObjectIdentifier(),
>                 ACTION(actions.objectId()),
>                 ZeroOrMore(MethodCall())
>         );
>     }
>
>     Rule Assignment() {
>         return Sequence(
>                 ObjectIdentifier(),
>                 ACTION(actions.objectId()),
>                 EQUAL,
>                 ZeroOrMore(Sequence(ObjectIdentifier(), ACTION(actions.objectId()), EQUAL, ACTION(actions.assign()))),
>                 ObjectMethodInvocation(),
>                 ACTION(actions.assign()));
>     }
>
>     Rule ObjectIdentifier() {
>         return Identifier();
>     }
>
>     Rule MethodCall() {
>         return Sequence(
>                 DOT,
>                 Identifier(),
>                 push(match()),
>                 Arguments(),
>                 ACTION(actions.methodCall())
>         );
>     }
>
>     Rule Identifier() {
>         return Sequence(Letter(), ZeroOrMore(LetterOrDigit()), Spacing());
>     }
> AST
>     Rule Arguments() {
>         return Sequence(
>                 LPAR,
>                 push(new ArgsNode()),
>                 Optional(Sequence(Literal(), ACTION(actions.addArg())), ZeroOrMore(COMMA, Sequence(Literal(), ACTION(actions.addArg())))),
>                 RPAR
>         );
>     }
>  
> ...
>
> I use the stack approach to build my own AST. When the parsing is done I'm able to iinterpret java expression such as:
>
> foo = obj.method1(1,2,3).method2(true)
>
> Well, my main goal is to build an interactive console with a good support for smart completion. So when the user hits the TAB key on the following expression:
>
> foo = obj.method1(1,2,3).method2([TAB]
>
> I would like to suggest the expression
>
> foo = obj.method1(1,2,3).method2(boolean)
>
> But my current AST contains only the node for method1 because the method2 is not fully recognised by the parser. So if my understanding is good, the parser removes all nodes stacked for the last partial rule.
>
> Best
>
> Laurent
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Is-it-possible-to-manage-partial-match-properly-tp3319076p3322371.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Loading...