naming

package
v3.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package naming holds label conversions shared across packages: the Go-name to TypeDB-label conversion used by gotype (which derives default type names) and tqlgen (which must know when a generated struct needs an explicit type: override), and the injective label to TypeQL-variable encoding used by gotype and ast.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KebabCase

func KebabCase(name string) string

KebabCase converts a PascalCase Go struct name to kebab-case, treating consecutive uppercase runs as initialisms. e.g. "UserAccount" → "user-account", "HTTPServer" → "http-server", "User2FA" → "user2-fa".

The conversion is not a left inverse of tqlgen's label → Go name mapping: "user_account" and "user-account" both become "UserAccount". Callers that start from a TypeDB label must carry the label explicitly.

func RootSpelling

func RootSpelling(role string) string

RootSpelling returns the readable variable candidate for the player of a role (issue #138, R8). It is VarLabel(role) when that result starts with a letter or digit, contains no "__", and does not end with "_". Otherwise it is "0" followed by the role with the VarLabel escapes ("_" → "_u", "-" → "_h"), so the result is always a valid TypeQL variable name: "author" → "author", "first-author" → "first_author", "first_author" → "0first_uauthor". formal/lean/Allocator.lean proves these properties (rootSpelling_valid, rootSpelling_injective).

func VarLabel

func VarLabel(label string) string

VarLabel encodes a TypeDB label as TypeQL variable-name characters ([A-Za-z0-9_]). The encoding is injective, so distinct labels never share a generated variable (which TypeQL would treat as an implicit equality):

  • a label that starts with a letter or digit and contains only letters, digits, and hyphens maps hyphens to underscores ("first-name" → "first_name"), keeping the common case readable;
  • any other label gets a leading underscore, which the first form never produces, followed by the label with "_" → "_u", "-" → "_h", and other bytes → "_x" plus two hex digits ("first_name" → "_first_uname").

formal/lean/Naming.lean proves the encoding injective.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL