TermSanitizer

scalus.uplc.TermSanitizer
object TermSanitizer

Sanitizes UPLC Terms to ensure all variable names conform to the identifier grammar accepted by the reference plutus-core textual parser (PlutusCore.Parser.ParserCommon.name, backed by PlutusCore.Name.Unique.isIdentifierStartingChar / isIdentifierChar; verified against plutus-core-1.45.0.0):

  • First character: an ASCII letter (a-z, A-Z) or underscore (_).
  • Subsequent characters: an ASCII letter, digit, underscore (_), or apostrophe (').
  • The reference parser additionally accepts a - "Unique" suffix (e.g. foo-123), but only as a terminal token component parsed by a separate combinator: once - starts, nothing else (not even more digits, letters, or apostrophes) may follow it in the same token. A name like a-91533'653 therefore parses as a-91533 followed by a stray, unparseable '653. Since Scalus never needs to emit that literal Unique-suffix syntax, this sanitizer does not attempt to reproduce it: every - in an original name is replaced with _ instead, which is always valid in any position and sidesteps the terminal-suffix ambiguity entirely.

This sanitizer transforms variable names to comply with these rules while avoiding conflicts.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def sanitizeName(name: String): String

Sanitizes a single name to conform to UPLC identifier rules.

Sanitizes a single name to conform to UPLC identifier rules.

Value parameters

name

the original name

Attributes

Returns

a sanitized version of the name

def sanitizeNames(term: Term): Term

Sanitizes all variable names in a Term to be valid UPLC identifiers.

Sanitizes all variable names in a Term to be valid UPLC identifiers.

Value parameters

term

the term to sanitize

Attributes

Returns

a new term with all variable names sanitized