# All files / src/parser fragment.js

100% Statements 16/16
100% Branches 0/0
100% Functions 3/3
100% Lines 16/16

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39

    27x
    27x
    27x
    27x
    27x
    27x

    27x

    24x
    24x
    24x

    24x

    24x

    27x
    22x
    27x
    2x
     /**
     * Syntax Analysis
     *
     * The parser below creates the "bare" Abstract Syntax Tree.
     */

    // @flow
    import statement from "./statement";
    import expression from "./expression";
    import Context from "./context";
    import Tokenizer from "../tokenizer";
    import Stream from "../utils/stream";
    import tokenStream from "../utils/token-stream";

    import type { NodeType } from "../flow/types";

    export const fragment = (
      source: string,
      parser: (ctx: Context) => any
    ): NodeType => {
      const stream = new Stream(source);
      const tokenizer = new Tokenizer(stream);
      const tokens = tokenStream(tokenizer.parse());

      const ctx = new Context({
        stream: tokens,
        token: tokens.tokens[0],
        lines: stream.lines,
        filename: "unknown.walt",
      });

      return parser(ctx);
    };

    export const expressionFragment = (source: string) =>
      fragment(source, expression);
    export const statementFragment = (source: string) =>
      fragment(source, statement);