/** * Detects whether a string is a pure CashAssembly expression. * * CashAssembly expressions look like `$()` or `$( )`. This pattern checks * that the entire string is one such expression and nothing else. It will not match if * there is other text surrounding the expression. * * For example: * `$()` matches (a full expression) * `OP_DUP $()` does not match (extra text before it) * `$()` does not match (empty expression) */ export const CASHASSEMBLY_EXPRESSION_PATTERN = /^\$\([^)]+\)$/; /** * Finds all CashAssembly evaluations embedded in a larger string. * * An evaluation looks like `$(...)`, for example `$()` or `$( )`. This pattern * locates every occurrence in the input and returns them all (global flag `g`). * Empty evaluations `$()` are intentionally excluded because they reference no variables. * * For example, scanning `"OP_DUP <$()> OP_HASH160 $()"` would return * `['$()', '$()']`. */ export const CASHASSEMBLY_EVALUATION_PATTERN = /\$\([^)]+\)/g; /** * Extracts variable names from angle-bracket references inside a CashAssembly evaluation. * * Inside an evaluation like `$( )`, variables are referenced as ``. * This pattern captures the name between the brackets. The global flag `g` allows iterating * over every variable reference in a single evaluation string. * * For example, running this against `$( )` would return the variable names * `["pubkeyHash", "fee"]`. */ export const CASHASSEMBLY_VARIABLE_PATTERN = /<([^>]+)>/g; /** * Identifies CashAssembly literal tokens that appear inside angle-bracket push statements. * * Inside an evaluation, not everything between `<` and `>` is a variable name. Literals are * also valid push contents: numeric literals (e.g. `<0>`, `<32>`), hex literals (`<0x02>`), * binary literals (`<0b1010>`), and string literals (`<"minting">`, `<'hello'>`). This pattern * matches any captured token that starts with a digit or a quote character. */ export const CASHASSEMBLY_LITERAL_TOKEN_PATTERN = /^[0-9"']/; /** * Matches a single dot variable method reference inside an angle-bracket identifier. * * Used to detect primitive method references such as `expiry.toIso8601`. * * For example: * `expiry.toIso8601` matches (base `expiry`, method `toIso8601`) * `requestedSatoshis` does not match (no method) * `key.schnorr_signature.all_outputs` does not match (more than one dot) * `key.public_key` matches the pattern shape but it is only resolved * when `hint` maps to a primitive */ export const CASHASSEMBLY_VARIABLE_METHOD_REFERENCE_PATTERN = /^([^.]+)\.([^.]+)$/;