-
Notifications
You must be signed in to change notification settings - Fork 20
⚙️ combinator
aliases:
- combinators
- "#⚙️combinator"
- combinated parser
A #⚙️combinator is an operator that creates a new parser based on a 🧩subject parser, parameters, and other input parsers like separators and terminators.
Applying a ⚙️ combinator to a subject parser returns a parser node with the 🧩subject and other parsers as child nodes. This means combinators introduce overhead, but they’re also the glue that allows you to construct more complex parsers.
Each application of a combinator creates a single parse node. This is due to several reasons:
- It lets users make connections between their code (combinator applications) and the resulting parse tree, which helps with debugging.
- Smaller parse trees also result in better performance.
This means that a combinator can’t be a direct shorthand for applying two other combinators, since that would add two nodes instead of one.
Combinators are constructed using a constructor function which has the same name as the combinator.
This is combinator type that’s used by the library. Object combinators are objects with an apply
method. This is a change from v1.
This method accepts the 🧩subject parser as its only argument and returns the new parser.
Combinators also have other kinds of members.
- Combinator-specific boosters that change how it works.
- Generic 🚀boosters like 🚀compose that exist on all combinators.
A combinator can also just be a function, like in v1. But built-in combinators aren’t functions
Each booster constructor is a function that has a function property is
that just checks whether an object is an instance of the booster in question.