Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Microgrammar<T>

Central class for microgrammar usage. Represents a microgrammar that we can use to match input in a string or stream. Modifications are tracked and we can get an updated string afterwards.

Type parameters

  • T

Hierarchy

  • Microgrammar

Implements

Index

Constructors

constructor

Properties

$id

$id: string

definitions

definitions: any = this.matcher.definitions

matcher

matcher: Concatenation

Methods

exactMatch

  • Return a match if it explains the whole of the input. This style of usage is more like a traditional parser, building an AST for a whole file.

    deprecated

    prefer perfectMatch

    Parameters

    • input: string | InputStream
    • Default value parseContext: object = {}

      context for the whole parsing operation

    • Optional l: Listeners

      listeners observing input characters as they are read

    Returns PatternMatch & T | DismatchReport

findMatchReportsAsync

findMatches

  • Convenience method to find matches without the ability to update them

    Parameters

    • input: string | InputStream
    • Optional parseContext: __type

      context for the whole parsing operation

    • Optional l: Listeners

      listeners observing input characters as they are read

    • Default value stopAfterMatch: function = () => false

    Returns Array<T & PatternMatch>

findMatchesAsync

firstMatch

matchIterator

matchReportIterator

perfectMatch

  • Return a MatchReport. if it is successful, call .toValueStructure() to get the match value. Otherwise, call .toExplanationTree() to get a report of why it didn't match.

    Parameters

    • input: string | InputStream
    • Default value parseContext: object = {}

      context for the whole parsing operation

    • Optional l: Listeners

      listeners observing input characters as they are read

    Returns MatchReport

Static fromDefinitions

  • Create a microgrammar with typed properties according to the given interface. If the definitions aren't nested, infer string type

    Type parameters

    • T

    Parameters

    Returns Microgrammar<T>

Static fromDefinitionsAs

  • Create a microgrammar with inferred interface taking properties of type "any" from definitions. Use fromDefinitions for stronger typing. If the definitions aren't nested, infer string type

    Type parameters

    • T

    Parameters

    Returns Microgrammar<AnyKeysOf<T>>

Static fromString

  • Create a microgrammar with string variables. String is of form "method ${name}(): ${returnType}". Definitions should be provided for each string variable. Use fromDefinitions to achieve nesting or non-string typing. If the definitions aren't nested, infer string type

    Type parameters

    • T

    Parameters

    Returns Microgrammar<T>

Static fromStringAs

  • Create a microgrammar with string variables with automatic typing as in fromDefinitionsAs. String is of form "method ${name}(): ${returnType}". Definitions should be provided for each string variable. Use fromDefinitions to achieve nesting or non-string typing. If the definitions aren't nested, infer string type

    Type parameters

    • T

    Parameters

    Returns Microgrammar<AnyKeysOf<T>>

Static updatable

  • Make these matches transparently updatable using property mutation

    Type parameters

    • T

    Parameters

    • matches: Array<T & PatternMatch>

      matches

    • content: string

      content the matches are within

    Returns Updatable<T>

Static updatableMatch

  • Make this match transparently updatable using property mutation

    Type parameters

    • T

    Parameters

    • match: T & PatternMatch

      match to make updatable

    • content: string

      the match is within

    Returns T & MatchUpdater

Generated using TypeDoc