-
I'm creating an Excel-like formula parser. For now, it's just for calling functions, not arithmetic, so eg =function(arg1,function2(arg2,arg3)). Two other requirements: (1) Different functions accept arguments of different types. (2) Users can modify the list of functions at runtime. The first thing I tried is creating an array of function definitions, so that the parser could look up the argument types and parse them correctly. However this doesn't work well with the recording phase. This other thing I've considered doing is constructing the entire ruleset dynamically similar to how langium does it. Would prefer not to as this seems like a lot of work. Any recommendation on general approach? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @lukasb, As far as I can tell, you're attempting to embed the type system of your language (i.e. the available functions and their arguments) into the parser. This is generally not recommended. Instead I would recommend to create an expression language that allows to create any functions call and supply any kinds of arguments. In a second, post-processing phase, you would assert that the arguments match the functions. Essentially, splitting the type system from the parser/grammar. See also langium-lox to see how one could implement this. A pure chevrotain implementation would use the same architecture. |
Beta Was this translation helpful? Give feedback.
Hey @lukasb,
As far as I can tell, you're attempting to embed the type system of your language (i.e. the available functions and their arguments) into the parser.
This is generally not recommended. Instead I would recommend to create an expression language that allows to create any functions call and supply any kinds of arguments. In a second, post-processing phase, you would assert that the arguments match the functions. Essentially, splitting the type system from the parser/grammar.
See also langium-lox to see how one could implement this. A pure chevrotain implementation would use the same architecture.