gmplSurfacePatternStatement
:page_with_curl: SurfacePattern Statement Summary
Section titled “:page_with_curl: SurfacePattern Statement Summary”SurfacePattern is a terminal, refactoring statement that occurs only within a Refactor statement. It sets the surface pattern authored for an operation. The setting applies to the current target dialect.
The attributes of the SurfacePattern statement are as follows:
| Attribute | Description |
|---|---|
| opc | This required identifier attributes specifies the opcode and subcode that identifies the operation to be modified. If the opcode or subcode is not found, the statement is ignored. |
| narg | This optional numeric value specifying the number of parameters that are expected in the pattern string. The parameter values are pulled from the string stack associated with the current instance of the operation. |
| status | An optional keyword describing the overall status of the operation authored via the surface pattern strings: Ok, Delete, Deprecated, NotImplemented, MustCorrect, NotIdent, Postfix, or NeedsPren. The default is Ok. |
| code | The pattern string to be used in authoring the operation. |
:bulb: Example
Section titled “:bulb: Example”The following example shows how to use the SurfacePattern statement to alter how On Error Resume Next (OERN) is expressed in translations. In the default translation for OERN, the translator evaluates the code context of the OERN, and if appropriate, it rewrites the protected block of statements as a call to helper method, gmRTL.Core.ErrorHandling.ResumeNext. The syntax for authoring this call block is expressed with two special surface patterns: one to open the block and one to close the block. This syntax is associated with the IFS opcode that is specified in the VBASIC.XML metalanguage file as follows:
<pattern id="IFS"> ... <subcode id="OpenResumeNext"> <csh role="command" narg="0" code="gmRTL.Core.ErrorHandling.ResumeNext(() =>\n{\p"/> <vbn role="command" narg="0" code="gmRTL.Core.ErrorHandling.ResumeNext(Sub()\p"/> </subcode> <subcode id="CloseResumeNext"> <csh role="command" narg="0" code="\q});\n"/> <vbn role="command" narg="0" code="\qEnd Sub)\n"/> </subcode>Although we start most projects with the default translation using gmRTL.Core.ErrorHandling.ResumeNext, we will usually recommend reworking the use of OERN. For example, we will change the translation to simply report comments at teh beginning and ending of the protected block. The SurfacePattern commands below replace the IFS.OpenResumeNext and IFS.CloseResumeNext syntax with these comments. In this case, the opcode.subcode operations’ syntax are overridden by adding Refactor/SurfacePattern rules to the Compile command in the translation script.
...<Compile> <Refactor> <SurfacePattern opc="IFS.OpenResumeNext" narg="0" code="// UPGRADE_INFO: START OERN\c"/> <SurfacePattern opc="IFS.CloseResumeNext" narg="0" code="// UPGRADE_INFO: END OERN\c"/> </Refactor></Compile>...The effect of these SurfacePattern rules is to alter how the OERN operations are authored in generated code as shown below.
