import type { CodePattern } from "./types.js"; // // The default patterns for code generation that are automatically included // export const DEFAULT_PATTERNS: CodePattern[] = [ { type: "control", pattern: /\(/ }, { type: "control", pattern: /\)/ }, { type: "control", pattern: /,/ }, { type: "control", pattern: /{/ }, { type: "control", pattern: /}/ }, { type: "control", pattern: /(?([ ...BUILT_IN_PATTERNS, ...INDICES_HELPER_PATTERNS, //TODO: add more patterns as needed ]); export function lookupPattern(name: string): CodePattern | undefined { return PATTERN_MAP.get(name); } export function createParamPattern(name: string): CodePattern { // Validate that the parameter name is a valid identifier // Valid identifiers: start with letter or underscore, followed by letters, digits, or underscores const identifierPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/; if (!identifierPattern.test(name)) { throw new Error( `Invalid parameter identifier: "${name}". Parameter names must start with a letter or underscore and contain only letters, digits, and underscores.` ); } return { type: "param", pattern: `\\b${name}\\b` }; }