// Copyright (c) The Move Contributors // SPDX-License-Identifier: Apache-2.0 import { AstPath, Doc } from 'prettier'; import { Node } from '..'; import { treeFn } from '../printer'; /** * Node: `_literal_value` in the grammar.json. */ export enum Literal { StringLiteral = 'string_literal', AddressLiteral = 'address_literal', BoolLiteral = 'bool_literal', NumLiteral = 'num_literal', HexStringLiteral = 'hex_string_literal', ByteStringLiteral = 'byte_string_literal', } export default function (path: AstPath): treeFn | null { switch (path.node.type) { case Literal.AddressLiteral: return printAddressLiteral; case Literal.BoolLiteral: return printBoolLiteral; case Literal.NumLiteral: return printNumLiteral; case Literal.HexStringLiteral: return printHexStringLiteral; case Literal.ByteStringLiteral: return printByteStringLiteral; case Literal.StringLiteral: return printStringLiteral; } return null; } /** * Print `byte_string_literal` node. */ export function printByteStringLiteral(path: AstPath): Doc { return path.node.text; } /** * Print `string_literal` node. */ export function printStringLiteral(path: AstPath): Doc { return path.node.text; } /** * Print `bool_literal` node. */ export function printBoolLiteral(path: AstPath): Doc { return path.node.text; } /** * Print `num_literal` node. */ export function printNumLiteral(path: AstPath): Doc { return path.node.text; } /** * Print `address_literal` node. */ export function printAddressLiteral(path: AstPath): Doc { return path.node.text; } /** * Print `hex_literal` node. */ export function printHexStringLiteral(path: AstPath): Doc { return path.node.text; }