UNPKG

solidity-antlr4

Version:

Solidity Lang Lexer and Parser by official ANTLR4 grammar

23 lines (22 loc) 695 B
import * as prettier from "prettier/standalone"; import { plugin } from "../prettier/index.js"; import { PrettierParser, getCommentTokens } from "../prettier/parser.js"; class PrettierGenerator extends PrettierParser { static name = "solidity-antlr4-generator"; parse = (ast, _options) => JSON.parse(ast); } const generatorPlugin = { ...plugin, parsers: { [PrettierGenerator.name]: new PrettierGenerator() } }; export const generate = async (ast, options = {}) => { if (options.tokens) ast.comments = getCommentTokens(options.tokens); return prettier.format(JSON.stringify(ast), { ...options, parser: PrettierGenerator.name, plugins: [generatorPlugin] }); };