-
Notifications
You must be signed in to change notification settings - Fork 421
Closed
Labels
Description
It could be extremely useful to have the ability to define grammars by importing rules from other grammars.
Several ideas ;
@include "expression.pegjs"
(or @from "expression.pegjs" import expression)
tag_if
= "if" space? expression space? { ... }
@import "expression.pegjs" as expr
tag_if
= "if" space? expr.expression space?
Ideally, this would not re-generate the whole code in every .pegjs that includes another ; maybe we would have to modify a little the behaviour of parse() to something of the like ;
Editing as per what you were saying in the options
issue ;
parse(input, startRule)
->
parse(input, { startRule: "...", startPos : 9000 })
And at the end, if startPos != 0 && result !== null
, we don't check if we went until input.length
, but instead return the result as well as the endPos (don't really know how to do that elegantly - maybe simply modifying the options parameter ?).
It would allow reusability of grammars and modularisation of the code, which I think are two extremely important aspects of coding in general.
rashidkpc, vyorkin, mnpenner, dmsnell, liyutech and 4 more