GerHobbelt / jison

bison / YACC / LEX in JavaScript (LALR(1), SLR(1), etc. lexer/parser generator)
https://gerhobbelt.github.io/jison/
MIT License
117 stars 20 forks source link

How is possible to implement C-like pre-processor macros ? #66

Open dooxe opened 2 years ago

dooxe commented 2 years ago

Hello !

For my script language I want to implement a simple way to separate scripts into multiple file. In order to do so, I imagine using C-like preprocessor to include script files into another like:

@import "script1"
@import "script2"

# ... remaining of the script 

The idea would be to load the file content of "script1" and "script2" before parsing the whole content. The macros "@import ..." should be at the start of the script.

Is that possible to implement it with jison ?

For now, I'm using a dedicated parser that only parse comments and imports before parsing the script content, dou you think it's a good idea ?

Thanks a lot