Languages often have patterns that reappear in multiple places, like identifiers or argument-lists.
These can have quite some length to it and may make the match-expression as a whole less readable.
To solve this you could add a top-level dict to the grammar description that contains name-regex pairs which are substituted into the requested places at runtime.
A good solution would be to add all defined helper functions as a preamble to each match in a named group with 0 repetitions like (?<Name>...){0}
Another possible solution might be PCRE's (?&name) (and (?(DEFINE)...)) syntax
this could be emulated via preprocessing of the patterns and string superstition,
this would not break any old code because (?&...) is illegal in ECMA's regex subset
If a switch to PCRE happens or native support is added you would just need to add a list of (?(DEFINE)...)s to the start of each match
Languages often have patterns that reappear in multiple places, like identifiers or argument-lists. These can have quite some length to it and may make the match-expression as a whole less readable.
To solve this you could add a top-level dict to the grammar description that contains name-regex pairs which are substituted into the requested places at runtime.
A good solution would be to add all defined helper functions as a preamble to each match in a named group with 0 repetitions like
(?<Name>...){0}
Another possible solution might be PCRE's
(?&name)
(and(?(DEFINE)...)
) syntax this could be emulated via preprocessing of the patterns and string superstition, this would not break any old code because(?&...)
is illegal in ECMA's regex subsetIf a switch to PCRE happens or native support is added you would just need to add a list of
(?(DEFINE)...)
s to the start of each match