Possible to parse input without evaluating? i.e. skip actions?

46 views
Skip to first unread message

thej...@gmail.com

unread,
Aug 22, 2019, 5:49:12 PM8/22/19
to PEG.js: Parser Generator for JavaScript
Sorry if this is the incorrect place to post questions.  If so, is there a slack or discord or should I use github issues?


I'm building a prefix DSL with pegjs and it's going pretty well.  The idea is that users can define expressions according to the DSL and those expressions can be evaluated dynamically later with varying context.

I've run into a snag separating the parsing from the evaluation.  Some expressions in my grammar require runtime context.  Specifically, variable resolution from an object passed in options.  I would like to be able to validate that the input syntax is valid according to my DSL separately without actually running the runtime actions.  Later, the generated parser can emit runtime issues if the provided context is invalid.

In pegjs, is the parsing separate from the evaluation of the input?  I've thought about trying to create an interface and injecting mock implementations of my actions, but I'm worried I'm over-complicating this or that I will affect downstream parsing.  Are the return values from the action actually used in any downstream parsing or just to evaluate the final response.

Hope this is clear.  Any thoughts on this?

Thanks,
Justin


P.S.  Thanks for pegjs.  It's awesome and I'm loving using it.

Arun Jayapal

unread,
Aug 30, 2019, 5:05:04 AM8/30/19
to PEG.js: Parser Generator for JavaScript
Find the github issues site.

There has to be some action. If not specified, (i.e. by default) you get an array of characters. For your use case, you need an AST. Later when you want to evaluate this against some payload (not parser input), you walk this tree. 

thej...@gmail.com

unread,
Sep 3, 2019, 4:32:00 PM9/3/19
to PEG.js: Parser Generator for JavaScript
Thanks for the response @Arun.

I had pretty much come to this conclusion and I'm working on returning either a tree or just a function that can be interpreted with context.

Thanks again,
Justin
Reply all
Reply to author
Forward
0 new messages