BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
586 stars 165 forks source link

Add `parseRawCF` to use bnfc as library and parse LBNF from another application #484

Open chaserhkj opened 3 months ago

chaserhkj commented 3 months ago

This PR decouples the CF parsing process of LBNF file from unused back end options and checks, thus providing a new function parseRawCF that can be called from third party applications.

I wrote this mainly because I am building another project and wishes to use LBNF format as my project's input. I want to call BNFC parsing processes directly to parse LBNF in my application but found out that was impossible due to parseCF requiring SharedOptions. My project performs analysis and manipulation of the input grammar, rather than converting it to an output target format, thus will not use any part of the back end of BNFC.

Ideally we would want to separate ShareOptions to front end and back end options and just use front end options for parsing the raw CF. But for now it seems that the parsing process only uses lbnfFile option and so I separated this specific field and created the parseRawCF function.

Also, I will be implementing a few utilities to work on a parsed LBNF grammar in my project, most significant ones should be the formatter to print CF back to LBNF format, and the Chomsky normalization to convert any CF to Chomsky Normal Form. I am not sure if these are appropriate to be merged into BNFC as well, let me know you guys' thoughts on them, thank you!