solidity-antlr4
Version:
Solidity Lang Lexer and Parser by official ANTLR4 grammar
55 lines (54 loc) • 2 kB
JavaScript
import { doc } from "prettier";
import { blockComments, comments } from "./base.js";
export const isBlockComment = (node) => {
return node?.type && blockComments.includes(node.type);
};
export const canAttachComment = (node) => !!node?.type && !comments.includes(node.type);
export const printComment = (path, _options) => {
const comment = path.node;
if (!comment.text)
return "";
if (comment.text.startsWith("///")) {
const content = comment.text.replace("///", "").trim();
return ["/// ", content];
}
if (comment.text.startsWith("//")) {
const content = comment.text.replace("//", "").trim();
return ["// ", content];
}
const isMultiline = comment.text.includes("\n");
const multiline = isMultiline ? doc.builders.hardline : doc.builders.line;
if (comment.text.startsWith("/**") && comment.text.endsWith("*/")) {
const lines = comment.text.slice(3, -2).split("\n").map((line) => {
const trimmed = line.trim();
if (trimmed.startsWith("*")) {
return trimmed.slice(1).trim();
}
return trimmed;
}).filter(Boolean);
return [
"/**",
multiline,
doc.builders.join(
multiline,
lines.map((line) => [" * ", line])
),
multiline,
" */"
];
}
if (comment.text.startsWith("/*") && comment.text.endsWith("*/")) {
const lines = comment.text.slice(2, -2).split("\n").map((line) => line.trim()).filter(Boolean);
return ["/*", multiline, doc.builders.join(multiline, lines), multiline, "*/"];
}
return comment.text;
};
const ignoredProperties = /* @__PURE__ */ new Set(["location", "range", "comments"]);
export const massageAstNode = () => {
};
massageAstNode.ignoredProperties = ignoredProperties;
export const handleComments = {
// ownLine: (commentNode, text, options, ast, isLastComment) => false,
// endOfLine: (commentNode, text, options, ast, isLastComment) => false,
// remaining: (commentNode, text, options, ast, isLastComment) => false,
};