Skip to content

The compiler should provide a way to export the AST as JSON #370

@gilramir

Description

@gilramir

It's very useful to be able to analyze Gren source code in any language.
The Module and Context data from a parse can be exported as JSON.

One idea is to call this "gren parse":

 % ./gren.sh parse --help
The `parse` command parses a Gren source file and outputs its AST as JSON:

    gren parse <filename>

For example:

    gren parse src/Main.gren

This parses src/Main.gren and writes a JSON object containing the filename, the
AST ("ast" field), and all comments ("context" field) to stdout. Use
--output=file.json to write to a file instead.

You can customize this command with the following flags:

    --output=<output-file>
        Write the JSON output to a file instead of stdout

It could export the ast (Module), context (comments), and filename. E.g.:

% ./gren.sh parse ../gren-format/compiler-node/tests/src/Test/Formatter/Strings.gren | grep '^  "'
  "filename": "../gren-format/compiler-node/tests/src/Test/Formatter/Strings.gren",
  "ast": {
  "context": [

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions