@hegeldev/hegel
    Preparing search index...

    Function fromLark

    • Generate strings matching a grammar written in the syntax of the Lark parsing library, starting from its start rule.

      The whole grammar language is supported: rules, terminals with string and regex patterns and priorities, %import (including Lark's bundled common, python, unicode and lark grammars), %ignore, %declare, %override, %extend and templates. Generated strings are ones Lark's Earley parser accepts for the grammar, with %ignored terminals such as whitespace and comments inserted wherever a lexer would skip them; a string Lark's basic lexer would read differently is avoided where the grammar allows it. A draw that cannot produce such a string after several attempts rejects the test case, as a failed assume does.

      The grammar is checked and compiled the first time a test draws from the generator; a grammar Lark would reject, an undefined start rule, a maxSize below the smallest string the grammar can produce, or an explicit generator for a terminal the grammar does not use fails the test then. Strings range up to 8192 characters by default, biased toward the larger end; use maxSize and maxDepth to keep them smaller.

      Parameters

      Returns PrintableGenerator<string>

      const expressions = fromLark(`
      ?start: sum
      ?sum: product | sum "+" product
      ?product: atom | product "*" atom
      ?atom: NUMBER | "(" sum ")"
      %import common.NUMBER
      %import common.WS
      %ignore WS
      `);