UNPKG

solidity-antlr4

Version:

Solidity Lang Lexer and Parser by official ANTLR4 grammar

20 lines (19 loc) 664 B
import { PrettierPrinter } from "./printer.js"; import { parse, tokenizer } from "../parser/index.js"; import { comments } from "./printers/base.js"; export const getCommentTokens = (tokens) => { return tokens.filter((token) => comments.includes(token.type)); }; export class PrettierParser { static name = "solidity-antlr4"; astFormat = PrettierPrinter.name; locStart = (node) => node.range[0]; locEnd = (node) => node.range[1] + 1; parse = (text, _options) => { const ast = parse(text, { tolerant: true }); const tokens = tokenizer(text, { tolerant: true }); if (ast) ast.comments = getCommentTokens(tokens); return ast; }; }