Function variable

  • Create a parser for variables. If we wanted to parse type variables in Elm, we could try something like this:

    const typeVar: P.Parser<string> = P.variable({
    start: Helpers.isLower,
    inner: (c: string) => Helpers.isAlphaNum(c) || c === "_",
    reserved: new Set(["let", "in", "case", "of"]),
    });

    This is saying it must start with a lower-case character. After that, characters can be letters, numbers, or underscores. It is also saying that if you run into any of these reserved names, it is definitely not a variable.

    Parameters

    • args: {
          inner: ((char: string) => boolean);
          reserved: Set<string>;
          start: ((char: string) => boolean);
      }
      • inner: ((char: string) => boolean)
          • (char: string): boolean
          • Parameters

            • char: string

            Returns boolean

      • reserved: Set<string>
      • start: ((char: string) => boolean)
          • (char: string): boolean
          • Parameters

            • char: string

            Returns boolean

    Returns Simple.Parser<string>