mna / pigeon

Command pigeon generates parsers in Go from a PEG grammar.
BSD 3-Clause "New" or "Revised" License
834 stars 66 forks source link

Help Required for developing expression evaluation parser! #102

Closed aamironline closed 2 years ago

aamironline commented 3 years ago

Hello,

Hope you are doing great! Thank you very much for developing such a wonderful library.

For one of our project (https://github.com/maniartech/x/), we are developing expression evaluator in Golang. We have used expr library for now. But would like to replace with our own evaluator/parser. We do not want to write from the scratch. The pigeon seems to provide perfect solution for our requirements. This seems to be easy. I started with changing calculator parser provided with the pigeon library. However, it is not working out.

I am new to PEG ecosystem, can anyone help me develop this parser! I am open to start a new MIT licensed open source project for this expression evaluator.

Thanks and Regards.

The expression evaluator has got following syntax!

-a-----a-----b-----b----------c----d------------l-------c----e---
SUM(AVERAGE(varA, obj.key, 10 + (2 + 3), [1, 23, 4]), 10 - 2, x)
-------------e-----e----------e--------------e-----------e----e---

-a---o-k---v----k---v----k------v--------
KEYS({ a: true, b: false, c: [1, 2, 3] })
------------t---------t-------l------------
- a: Function Name
- b: Variables, it should be JSON like variable with dot notation support
- c: Expression, Could be mathematical (+ - * /), comparison(== != > etc..), boolean (| & ~) etc...
- d: Bracketed Expression
- e: Comma separated function parameters
- o: JSON like object with nested object and array support
- k: The object key
- v: The object value
- l: The list (array) value in object 
- t: The boolean value
breml commented 3 years ago

Hi @aamironline

Thanks for your kind words. I am the current maintainer of pigeon and I am happy to provide you with some hints and links you might find helpful in your endeavor.

Over all, I feel like you might find a lot of inspiration in https://github.com/breml/logstash-config/blob/master/logstash_config.peg

An other good example is https://github.com/bytesparadise/libasciidoc/blob/master/pkg/parser/parser.peg

Use the two links in the Wiki to find more examples.

aamironline commented 3 years ago

Wow, what a detailed response! Thank you so much. I'll try your suggestions and provide my progress in this thread. Thanks again 👍🏻