Interface FollowOperations<S>

A set of operations that determine how state is propagated and changed.

Type Parameters

  • S

Hierarchy

  • FollowOperations

Properties

assert?: ((state, direction, assertion, assertionDirection) => S)

Type declaration

    • (state, direction, assertion, assertionDirection): S
    • This function is called when dealing with lookarounds.

      It will not be called for predefined assertion - ^, $, \b, \B. Use enter or leave for predefined assertions instead.

      Parameters

      Returns S

      Default

      x => x
      
continueAfter?: ((element, state, direction) => boolean)

Type declaration

    • (element, state, direction): boolean
    • Whether the current path should continue after the given element (return true) or whether all elements that follow this element should be skipped (return false).

      If the current path is a fork path, then only the elements until the fork is joined will be skipped. A stopped fork path will be joined with all other forks like normal.

      You shouldn't modify state in this function. Modify state in leave instead.

      See the documentation on enter for more details.

      Parameters

      Returns boolean

      Default

      () => true
      
continueInto?: ((element, state, direction) => boolean)

Type declaration

    • (element, state, direction): boolean
    • Whether the current path should go into the given element (return true) or whether it should be skipped (return false). If the element is skipped, the given state will not be changed and passed as-is to the leave function.

      You shouldn't modify state in this function. Modify state in enter instead.

      See the documentation on enter for more details.

      Parameters

      Returns boolean

      Default

      () => true
      
continueOutside?: ((element, state, direction) => boolean)

Type declaration

    • (element, state, direction): boolean
    • Whether the current path should continue outside the given lookaround assertion.

      Paths that leave a lookaround assertions (= go outside of it) generally can't be followed. However, for some operations it makes sense to do it anyway.

      It usually makes sense to follow paths outside of assertions if getMatchingDirectionFromAssertionKind(element.kind) !== direction. This condition ensure that lookbehinds only follow paths going out to the right (e.g. (?<=a)->b) and lookaheads only follow paths going out to the left (e.g. b<-(?=a)).

      If this function returns false, endPath is guaranteed to be called next. If this function returns true, continueAfter is guaranteed to be called next for the lookaround assertion.

      You shouldn't modify state in this function. Modify state in endPath or enter instead.

      Parameters

      Returns boolean

      Default

      () => false
      
endPath?: ((state, direction, reason) => S)

Type declaration

    • (state, direction, reason): S
    • This function is called when a path ends.

      Paths end at the end the patterns and assertions. It means that there is no element after the pattern/assertion in that direction.

      Parameters

      Returns S

      Default

      x => x
      

      See

      FollowEndReason

enter?: ((element, state, direction) => S)

Type declaration

    • (element, state, direction): S
    • This function is called when entering an element.

      Operations for elements are called in the following order:

      1. enter
      2. if continueInto return true
        1. Element-specific operations (if any) that can change the current state.
      3. leave
      4. continueAfter (optional; might not be called for every element)

      Parameters

      Returns S

      Default

      (_, x) => x
      
fork?: ((state, direction) => S)

Type declaration

    • (state, direction): S
    • Split off a new path from the given one.

      This function should not modify the given state.

      If the state is immutable, then fork may be implemented as the identify function in regard to state. If the function is omitted, it will default to the identify function.

      If the state is mutable, then fork must be implemented.

      Parameters

      Returns S

      Default

      x => x
      
leave?: ((element, state, direction) => S)

Type declaration

    • (element, state, direction): S
    • This function is called when leaving an element.

      See the documentation on enter for more details.

      Parameters

      Returns S

      Default

      (_, x) => x
      

Methods

  • Joins any number of paths to create a combined path.

    Parameters

    Returns S