solidity-antlr4
Version:
Solidity Lang Lexer and Parser by official ANTLR4 grammar
75 lines (74 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.lineComments = exports.comments = exports.blockComments = exports.BasePrinter = void 0;
var _prettier = require("prettier");
const lineComments = exports.lineComments = ["LINE_COMMENT", "AssemblyBlockLINE_COMMENT", "YulLINE_COMMENT", "PragmaLINE_COMMENT"];
const blockComments = exports.blockComments = ["COMMENT", "AssemblyBlockCOMMENT", "YulCOMMENT", "PragmaCOMMENT"];
const comments = exports.comments = [...lineComments, ...blockComments];
class BasePrinter {
constructor(options, print) {
this.options = options;
this.print = print;
}
space = " ";
dot = ".";
comma = ",";
semi = ";";
quote = `"`;
singleQuote = `'`;
builders = _prettier.doc.builders;
// The pangu space
pangu = path => {
return _prettier.util.isNextLineEmpty(this.options.originalText, this.options.locEnd(path.node)) ? this.builders.hardline : "";
};
// value => "value"
literal = value => {
return this.options.singleQuote ? [this.singleQuote, value, this.singleQuote] : [this.quote, value, this.quote];
};
// value = { value }
block = (value, empty = false) => {
if (empty) return ["{", "}"];
const groupId = Symbol("block");
const line = this.options.bracketSpacing ? this.builders.line : this.builders.softline;
const beforeLine = this.builders.indentIfBreak(line, {
groupId
});
const content = this.builders.indentIfBreak(value, {
groupId
});
return this.builders.group(["{", beforeLine, content, line, "}"], {
id: groupId
});
};
// value[] => value1, value2, value3
paramater = (value, sep = [this.comma, this.builders.line]) => {
return this.builders.join(sep, value);
};
// value => (value)
tuple = (value, groupId = Symbol("tuple")) => {
const content = this.builders.indentIfBreak(value, {
groupId
});
const line = this.builders.softline;
return this.builders.group(["(", this.builders.indentIfBreak(line, {
groupId
}), content, line, ")"], {
id: groupId
});
};
// value => [value]
list = (value, groupId = Symbol("list")) => {
const content = this.builders.indentIfBreak(value, {
groupId
});
const line = this.builders.softline;
return this.builders.group(["[", this.builders.indentIfBreak(line, {
groupId
}), content, line, "]"], {
id: groupId
});
};
}
exports.BasePrinter = BasePrinter;