Skip to content

⚙️ combinator

GregRos edited this page Mar 26, 2025 · 7 revisions

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.

Types of combinators

Object combinators

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.

  1. Combinator-specific boosters that change how it works.
  2. Generic 🚀boosters like 🚀compose that exist on all combinators.

Function combinators

A combinator can also just be a function, like in v1. But built-in combinators aren’t functions

Meta-programming extras

is

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.

Clone this wiki locally