From 196742712f11494ad32077f93ed645afe5fb9401 Mon Sep 17 00:00:00 2001 From: David de Hilster Date: Wed, 14 Oct 2026 13:05:47 -0400 Subject: [PATCH] Setting: start new rules passes with a @CODE region (nlp-engine#391) New setting nlp.newPass.codeRegion (default off). When on, a new rules pass starts with a @CODE region, which runs before the rules: a place to set up globals for the pass or to skip it with exitpass(). Co-Authored-By: Claude Opus 5.5 --- package.json | 6 ++++++ src/sequence.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/package.json b/package.json index 49dd3bd4..3457d56e 100644 --- a/package.json +++ b/package.json @@ -3441,6 +3441,12 @@ "default": true, "markdownDescription": "When you switch to another analyzer, close the open files of the one you are leaving and reopen the files you had open in the one you are switching to. Files with unsaved changes are never closed." }, + "nlp.newPass.codeRegion": { + "type": "boolean", + "scope": "application", + "default": false, + "markdownDescription": "Start every new rules pass with a `@CODE` region, which runs before the rules. Use it to set up globals for the pass, or to skip the pass with `exitpass()` (for example, to run only some passes)." + }, "nlp.format.enable": { "type": "boolean", "scope": "resource", diff --git a/src/sequence.ts b/src/sequence.ts index 95067387..deda98ed 100644 --- a/src/sequence.ts +++ b/src/sequence.ts @@ -680,6 +680,13 @@ export class SequenceFile extends TextFile { switch (type) { case newPassType.RULES: + // Setting nlp.newPass.codeRegion: a @CODE region runs before the rules, for + // pass setup or exitpass() (nlp-engine#391). + if (vscode.workspace.getConfiguration('nlp').get('newPass.codeRegion', false)) { + newpass = newpass.concat('@CODE\n'); + newpass = newpass.concat('L("hello") = 0;\n'); + newpass = newpass.concat('@@CODE\n\n'); + } newpass = newpass.concat('@NODES _ROOT\n\n'); newpass = newpass.concat('@RULES\n');