Class Pattern<T, ParentPattern>

Example

import {latexParser as lp} from 'latex-utensils'

const texString = 'a $x + y$ b'
const ast = lp.parse(texString)
const childPat = lp.pattern(lp.isInlineMath).child(lp.isMathCharacter)
const result = childPat.match(ast.content)
result?.node.content // 'x'

Type Parameters

  • T extends Node

  • ParentPattern extends Pattern<Node, any> | undefined = undefined

Hierarchy

  • Pattern

Properties

parentPattern: ParentPattern

Parent pattern.

typeguard: Typeguard<T>

Type guard to check whether nodes match.

Methods

  • Returns a pattern whose parent pattern is this. The pattern matches if typeguard returns true.

    Type Parameters

    Parameters

    • typeguard: ((x) => x is C)

      A type guard of the child pattern.

        • (x): x is C
        • Parameters

          Returns x is C

    Returns Pattern<C, Pattern<T, ParentPattern>>

  • Returns a pattern whose parent pattern is this. The pattern matches if typeguard returns true.

    Parameters

    • typeguard: ((x) => boolean)

      A callback of the child pattern.

        • (x): boolean
        • Parameters

          Returns boolean

    Returns Pattern<Node, Pattern<T, ParentPattern>>

Generated using TypeDoc