#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "_gpfErrorDeclare\("([a-zA-Z\\]+)", {\n((?:.*\n)*)\s*}\)"
Local $sString = "/**" & @CRLF & _
" * @file Error base class" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
"/*#ifndef(UMD)*/" & @CRLF & _
""use strict";" & @CRLF & _
"/*global _gpfExtend*/ // gpf.extend" & @CRLF & _
"/*global _gpfIgnore*/ // Helper to remove unused parameter warning" & @CRLF & _
"/*global _gpfObjectForEach*/ // Similar to [].forEach but for objects" & @CRLF & _
"/*global _gpfStringCapitalize*/ // Capitalize the string" & @CRLF & _
"/*global _gpfStringReplaceEx*/ // String replacement using dictionary map" & @CRLF & _
"/*exported _gpfErrorDeclare*/ // Declare new gpf.Error names" & @CRLF & _
"/*#endif*/" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * GPF Error class" & @CRLF & _
" *" & @CRLF & _
" * @constructor" & @CRLF & _
" * @alias gpf.Error" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
"var _GpfError = gpf.Error = function () {};" & @CRLF & _
"" & @CRLF & _
"_GpfError.prototype = new Error();" & @CRLF & _
"_gpfExtend(_GpfError.prototype, /** @lends gpf.Error.prototype */ {" & @CRLF & _
"" & @CRLF & _
" constructor: _GpfError," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * Error code" & @CRLF & _
" *" & @CRLF & _
" * @readonly" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" code: 0," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * Error name" & @CRLF & _
" *" & @CRLF & _
" * @readonly" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" name: "Error"," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * Error message" & @CRLF & _
" *" & @CRLF & _
" * @readonly" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" message: ""," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * Build message by substituting context variables" & @CRLF & _
" *" & @CRLF & _
" * @param {Object} context Dictionary of named keys" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" _buildMessage: function (context) {" & @CRLF & _
" var replacements;" & @CRLF & _
" if (context) {" & @CRLF & _
" replacements = {};" & @CRLF & _
" _gpfObjectForEach(context, function (value, key) {" & @CRLF & _
" replacements["{" + key + "}"] = value.toString();" & @CRLF & _
" });" & @CRLF & _
" this.message = _gpfStringReplaceEx(this.message, replacements);" & @CRLF & _
" }" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
"});" & @CRLF & _
"" & @CRLF & _
"function _gpfErrorFactory (code, name, message) {" & @CRLF & _
" function NewErrorClass (context) {" & @CRLF & _
" this._buildMessage(context);" & @CRLF & _
" }" & @CRLF & _
" NewErrorClass.prototype = new _GpfError();" & @CRLF & _
" _gpfExtend(NewErrorClass.prototype, {" & @CRLF & _
" code: code," & @CRLF & _
" name: name," & @CRLF & _
" message: message" & @CRLF & _
" });" & @CRLF & _
" // constructor can't be enumerated with wscript" & @CRLF & _
" NewErrorClass.prototype.constructor = NewErrorClass;" & @CRLF & _
" _GpfError[_gpfStringCapitalize(name)] = NewErrorClass;" & @CRLF & _
" return function (context) {" & @CRLF & _
" throw new NewErrorClass(context);" & @CRLF & _
" };" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * Generates an error class" & @CRLF & _
" *" & @CRLF & _
" * @param {Number} code Error code" & @CRLF & _
" * @param {String} name Error name" & @CRLF & _
" * @param {String} message Error message" & @CRLF & _
" * @return {Function} New error class" & @CRLF & _
" * @gpf:closure" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
"function _gpfGenenerateErrorFunction (code, name, message) {" & @CRLF & _
" var result = _gpfErrorFactory(code, name, message);" & @CRLF & _
" result.CODE = code;" & @CRLF & _
" result.NAME = name;" & @CRLF & _
" result.MESSAGE = message;" & @CRLF & _
" return result;" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"// Last allocated error code" & @CRLF & _
"var _gpfLastErrorCode = 0;" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * Declare error messages." & @CRLF & _
" * Each source declares its own errors." & @CRLF & _
" *" & @CRLF & _
" * @param {String} source Source name" & @CRLF & _
" * @param {Object} dictionary Dictionary of error name to message" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
"function _gpfErrorDeclare (source, dictionary) {" & @CRLF & _
" _gpfIgnore(source);" & @CRLF & _
" _gpfObjectForEach(dictionary, function (message, name) {" & @CRLF & _
" var code = ++_gpfLastErrorCode;" & @CRLF & _
" gpf.Error["CODE_" + name.toUpperCase()] = code;" & @CRLF & _
" gpf.Error[name] = _gpfGenenerateErrorFunction(code, name, message);" & @CRLF & _
" });" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"_gpfErrorDeclare("error", {" & @CRLF & _
" /**" & @CRLF & _
" * ### Summary" & @CRLF & _
" *" & @CRLF & _
" * Method or function is not implemented" & @CRLF & _
" *" & @CRLF & _
" * ### Description" & @CRLF & _
" *" & @CRLF & _
" * This error is used to flag methods or functions that are not yet implemented." & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" notImplemented:" & @CRLF & _
" "Not implemented"," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * ### Summary" & @CRLF & _
" *" & @CRLF & _
" * Method is abstract" & @CRLF & _
" *" & @CRLF & _
" * ### Description" & @CRLF & _
" *" & @CRLF & _
" * This error is used to implement abstract methods. Mostly used for interfaces." & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" abstractMethod:" & @CRLF & _
" "Abstract method"," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * ### Summary" & @CRLF & _
" *" & @CRLF & _
" * An assertion failed" & @CRLF & _
" *" & @CRLF & _
" * ### Description" & @CRLF & _
" *" & @CRLF & _
" * This error is triggered when an assertion fails" & @CRLF & _
" *" & @CRLF & _
" * @see {@link gpf.assert}" & @CRLF & _
" * @see {@link gpf.asserts}" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" assertionFailed:" & @CRLF & _
" "Assertion failed: {message}"," & @CRLF & _
"" & @CRLF & _
" /**" & @CRLF & _
" * ### Summary" & @CRLF & _
" *" & @CRLF & _
" * Method or function was called with an invalid parameter" & @CRLF & _
" *" & @CRLF & _
" * ### Description" & @CRLF & _
" *" & @CRLF & _
" * This error is used when a parameter is invalid" & @CRLF & _
" * @since 0.1.5" & @CRLF & _
" */" & @CRLF & _
" invalidParameter:" & @CRLF & _
" "Invalid parameter"" & @CRLF & _
"});" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH)
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm