Quantcast

Parsing Error Messages

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

Parsing Error Messages

Gosia
Hi,

I don't know if I am doing it properly, but I am trying to build simple 'interpreter' and following rule is for defining an integer:

        public Rule IntegerName(){
                return Sequence(Name(), declaredIntegers.put(match(), 0)==null);
        }

declaredIntegers is a map

As I want it fails when trying to define two integers with same name, but no error message is given.
Is it any possibility to add to parsing errors for example "name already declared" or better specify proper name.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Parsing Error Messages

mathias
Administrator
Two things here:

First, I think you should separate the parser from subsequent logic in your application.
Usually the parser is responsible for the syntactical level of your language. The output is an abstract syntax tree that is then processed by higher-level parts of your application. Things like checking that no two identifiers collide really seem like they should not be part of the parser but rather subsequent logic.

However, the wish to generate custom parse error messages has already  come up a few times in the past. Currently this is not nicely possible.
I will think about how to incorporate it in some of the next releases.

Thanks for your feedback!

Cheers,
Mathias

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

On 23.01.2011, at 03:06, Gosia [via parboiled users] wrote:

> Hi,
>
> I don't know if I am doing it properly, but I am trying to build simple 'interpreter' and following rule is for defining an integer:
>
>         public Rule IntegerName(){
>                 return Sequence(Name(), declaredIntegers.put(match(), 0)==null ? true : false);
>         }
>
> declaredIntegers is a map
>
> As I want it fails when trying to define two integers with same name, but no error message is given.
> Is it any possibility to add to parsing errors for example "name already declared" or better specify proper name.
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Parsing-Error-Messages-tp2311699p2311699.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: Parsing Error Messages

Alessio Stalla
FWIW, I'd like to have that possibility as well. I don't need to check for duplicate declarations, instead I need to resolve a certain symbol against a namespace. So parsing foo:bar results in push(findSymbolTable("foo").intern("bar")). findSymbolTable can fail, and I'd like to signal it to the user in a meaningful way. Doing it at a later step would be inconvenient, because I don't currently have a later step at all - I directly produce the data structures I need from the parser. The data structures are very similar to a parse tree; they're Prolog terms. They mirror quite closely the shape of the input string.

Anyway, thanks a lot for your library! I used it to replace an old recursive-descent parser I had (poorly) written by hand years ago: it changed from an unmodifiable mess to very readable code, even if I'm doing some unorthodox things (I can change certain behaviors of the parser at runtime, while keeping the structure of the rules intact).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Parsing Error Messages

mathias
Administrator
Alessio,

thanks for your feedback.
I created a github issue to keep this feature request alive.

Cheers,
Mathias

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

On 25.03.2011, at 23:55, Alessio Stalla [via parboiled users] wrote:

> FWIW, I'd like to have that possibility as well. I don't need to check for duplicate declarations, instead I need to resolve a certain symbol against a namespace. So parsing foo:bar results in push(findSymbolTable("foo").intern("bar")). findSymbolTable can fail, and I'd like to signal it to the user in a meaningful way. Doing it at a later step would be inconvenient, because I don't currently have a later step at all - I directly produce the data structures I need from the parser. The data structures are very similar to a parse tree; they're Prolog terms. They mirror quite closely the shape of the input string.
>
> Anyway, thanks a lot for your library! I used it to replace an old recursive-descent parser I had (poorly) written by hand years ago: it changed from an unmodifiable mess to very readable code, even if I'm doing some unorthodox things (I can change certain behaviors of the parser at runtime, while keeping the structure of the rules intact).
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Parsing-Error-Messages-tp2311699p2733055.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: Parsing Error Messages

sulfinu
If anyone is still interested in the matter, I for one make heavy use of

     throw new ActionException("...some message...")

to convey error explanations.
Loading...