Skip to content

Debugging the Reference Parser

Staś Małolepszy edited this page May 18, 2018 · 2 revisions

Debugging the reference parser is easy!

map(print)

You can log the output of any parser with map(print). In the following identifier parser, map(print) is ued three times to inspect the parsing result after each step:

let identifier =
    sequence(
        charset("a-zA-Z"),
        repeat(
            charset("a-zA-Z0-9_-")))
    .map(print)
    .map(flatten(1))
    .map(print)
    .map(join)
    .map(print);

The result for parsing the string foo = Foo is:

[
    "f",
    [
        "o",
        "o"
    ]
]
[
    "f",
    "o",
    "o"
]
"foo"

bin/parse.mjs

The bin/parse.mjs CLI utility can be used to parse FTL files. It prints out the resulting AST. Remember to turn on ES Modules with the --experimental-modules flag. (alias mode=node --experimental-modules did it for me).

$ node --experimental-modules bin/parse.mjs path/to/file.ftl

If - is given as the file name, bin/parse.mjs will read standard input until C-C or C-D are pressed. It's helpful to be able to pipe FTL to bin/parse.mjs:

$ echo "x = X" | node --experimental-modules bin/parse.mjs path/to/file.ftl -

Or using process substitution:

$ node --experimental-modules bin/parse.mjs <(echo "x = X")
Clone this wiki locally