# PSPad User Highlighter — AI Specification

Portable specification for generating PSPad user highlighter definition files (`.ini`). Any AI can use this document without access to the PSPad source tree.

**Format version:** based on PSPad + SynEdit `TSynGeneralSyn` (user highlighter engine).

---

## 1. How to create a user highlighter (for humans)

### 1.1 Quick steps

1. Use any AI.
2. Attach the file `PSPad-User-Highlighter-AI-Spec.md`.
3. Send the prompt from Section 1.2. Replace `<enter syntax>` with the language name. You can also add a URL with a description of the syntax.
4. Save the `.ini` file:
   - Portable version: `.\PSpad\Syntax`
   - Installed version: `%appData%\PSPad\Syntax`
5. In PSPad, open **Settings → Highlighters Settings**. Assign a free user slot (`General` … `General9`) to the file name (without `.ini`) and check that the file extensions match.

You can use the same specification to improve an existing user highlighter. Attach this file and the current `.ini`, and ask the AI to update it.

### 1.2 Copy-paste prompt (simple)

Replace `<enter syntax>`, then send together with the attached specification file:

```
Based on the attached specification, create a PSPad editor user highlighter file for syntax <enter syntax>.
```

Optional: add a URL with the syntax description, for example:

```
Syntax description: https://example.com/language/syntax
```

Optional: add file extensions, comment rules, or a keyword list when the documentation URL is not enough (see Section 2.2 for a detailed template).

To improve a highlighter you already have:

```
Based on the attached specification, improve the existing PSPad user highlighter file for syntax <enter syntax>.
```

Attach the current `.ini` together with this specification.

### 1.3 After you receive the highlighter

1. Save the AI output as one `.ini` file.
2. Put it in `.\PSpad\Syntax` (portable version) or `%appData%\PSPad\Syntax` (installed version).
3. Open **Settings → Highlighters Settings**, choose a free user slot, and select the new file.
4. Open a sample file of that syntax and check comments, strings, and keywords.

If you want to help the PSPad community, send your file to [support@pspad.com](mailto:support@pspad.com). I will include it in a future build.

---

## 2. Copy-paste prompts for AI

### 2.1 System prompt

Copy everything inside the block below as the system (or first) message:

```
You are an expert at creating PSPad user highlighter definition files.

You MUST follow the specification in "PSPad User Highlighter — AI Specification".

Rules:
1. Output a COMPLETE, valid .ini file — no placeholders like "add more keywords here".
2. Use ONLY comment-style INI keys listed in the specification. Never invent new keys.
3. Enable the MINIMAL set of comment styles that match the target language. Extra styles cause false highlighting.
4. Every keyword entry MUST end with "=" (e.g. "while=").
5. Include all five sections: [Settings], [KeyWords], [ReservedWords], [KeyWords2], [KeyWords3] (keyword sections may be empty but must exist).
6. First line MUST be: ;PSPad user HighLighter definition file
7. If the language needs a comment form NOT in the spec, say that engine source code must be extended — do NOT fake it with a wrong key.
8. After the INI, provide: (a) brief rationale for comment/case choices, (b) save the file to .\PSpad\Syntax (portable version) or %appData%\PSPad\Syntax (installed version), then assign a user slot in Settings → Highlighters Settings, (c) any limitations.

Do not enable PasComment or LBracketComment if { starts code blocks.
Do not enable BackSlashComment if backslash is used for line continuation.
```

### 2.2 User prompt template

```
Based on the attached specification, create a PSPad editor user highlighter file for syntax {LanguageName}.

File extensions: {Extensions}
Syntax documentation: {SyntaxDocUrl or paste}

Comments:
- Line: {e.g. # to end of line}
- Block: {e.g. /* */ or none}

Strings:
- Delimiters: {e.g. double quotes only}
- Escape character: {e.g. \ or none}
- Case-sensitive identifiers: {yes/no}

Keywords (language):
{paste list or "extract from documentation"}

Reserved / builtins:
{paste list}

API / functions (optional second group):
{paste list}

Additional API (optional third group):
{paste list}

Special requirements:
{e.g. fold on { }, no $variables, etc.}
```

---

## 3. Architecture overview

PSPad user highlighters are **INI configuration files** loaded into the generic lexer `TSynGeneralSyn` (SynEdit component).

```
Language.ini  →  PSPad loads via SetUserHighLighter  →  TSynGeneralSyn applies comments, strings, keywords
```

| Concept | Detail |
|---------|--------|
| **File location** | Portable version: `.\PSpad\Syntax`. Installed version: `%appData%\PSPad\Syntax` |
| **INI filename** | Becomes the highlighter name referenced in settings (extension `.ini` / `.INI`, case-insensitive on Windows) |
| **User slots** | 10 slots: `General`, `General1` … `General9` (configured in `PSPad.ini` as `UserHighLighterName`, `UserHighLighterName1`, …) |
| **Engine** | `TSynGeneralSyn` — no per-language Pascal code for typical highlighters |
| **UI editor** | PSPad dialog "User highlighter" reads/writes the same INI format |

---

## 4. INI file format specification

### 4.1 File structure

```ini
;PSPad user HighLighter definition file
[Settings]
...key=value pairs...

[KeyWords]
keyword1=
keyword2=

[ReservedWords]
builtin1=

[KeyWords2]
api1=

[KeyWords3]
more_api=
```

### 4.2 Required first line

```
;PSPad user HighLighter definition file
```

### 4.3 `[Settings]` keys — complete reference

#### Identity and file association

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `Name` | string | — | Display name in PSPad (may differ from INI filename) |
| `FileType` | string | — | Comma-separated globs, e.g. `*.lua,*.luac` |
| `CommentString` | string | empty | Character(s) for PSPad "toggle line comment" action (often `#` or `//`) |

#### Comments (boolean `0` / `1`)

See Section 5 for which key matches which syntax. Only set `=1` for styles the language actually uses. When PSPad saves from the UI, disabled comment keys are often **omitted**; explicit `=0` is also valid.

#### Strings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `SingleQuote` | bool | `0` | String literals in `'...'` |
| `DoubleQuote` | bool | `1` | String literals in `"..."` |
| `ApostropheQuote` | bool | `0` | String literals in `` `...` `` |
| `EscString` | bool | `1` | Enable escape sequences inside strings |
| `EscChar` | char | `\` | Escape character |

#### Identifiers and keywords

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `CaseSensitive` | bool | `0` | `1` = keyword matching is case-sensitive |
| `KeyWordChars` | string | `_` | Extra characters allowed inside identifiers (e.g. `_`, `@`) |
| `KW1StartWith` | bool | `0` | If `1`, `[KeyWords]` match as prefix (e.g. `foo` matches `foobar`) |
| `KW2StartWith` | bool | `0` | Same for `[KeyWords2]` |
| `KW3StartWith` | bool | `0` | Same for `[KeyWords3]` |
| `KW4StartWith` | bool | `0` | Reserved for future use / symmetry with UI |

#### Editor behavior

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `TabWidth` | int | `0` | Tab display width |
| `IndentChar` | char | space | Character that increases indent level |
| `UnIndentChar` | char | space | Character that decreases indent level |
| `CodeFolding` | enum | `ftNone` | `ftNone` or `cftCurlyBracket` (fold on `{` `}`) |
| `CodeExplorer` | enum | `ftUnknown` | Code explorer parser type (see Section 4.4) |
| `DocComment` | string | empty | Documentation comment marker (if used) |

#### Special lexer modes

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `HTMLGroup` | bool | `0` | Part of HTML highlighter group |
| `Label` | bool | `1` | Highlight `label:` at line start |
| `Vectors` | bool | `0` | Vector syntax support |
| `PHPVariable` | bool | `0` | Highlight `$variables` |
| `RubySymbols` | bool | `0` | Ruby-specific `%q`, `#{}`, etc. |
| `Preprocessors` | bool | `0` | C-style `#include` / `#define` preprocessing |

### 4.4 `CodeExplorer` values (`TFileType`)

Use `ftUnknown` unless PSPad has a dedicated code-explorer parser for the language.

Common values: `ftLUA`, `ftJS`, `ftPy`, `ftCPP`, `ftPAS`, `ftSQL`, `ftBAT`, `ftRuby`, `ftAutoIt`, `ftINI`, `ftJSON`, `ftPHP`, `ftVHDL`, `ftCSharp`, `ftPwrShell`, `ftUnknown`, …

If unsure, always use **`ftUnknown`**.

### 4.5 Keyword sections

| Section | Highlight role | Typical content |
|---------|----------------|-----------------|
| `[KeyWords]` | Primary keywords (keyword color) | `if`, `while`, `return`, types |
| `[ReservedWords]` | Reserved / builtins (reserved color) | `print`, `len`, system functions |
| `[KeyWords2]` | Secondary group (keyword2 color) | Standard library, modules |
| `[KeyWords3]` | Tertiary group (keyword3 color) | API functions, methods |

**Format:** one entry per line, **must** end with `=`:

```
while=
```

The value after `=` is ignored (usually empty). Keywords are sorted case-sensitively or insensitively according to `CaseSensitive`.

---

## 5. Comment styles reference

Enable only styles that match the target language. Enabling too many causes incorrect highlighting.

### 5.1 Block (multiline) comments

| INI key | Syntax pattern | Notes |
|---------|----------------|-------|
| `ANSIComment` | `(* … *)` | Pascal-style |
| `PasComment` | `{ … }` | **Warning:** entire `{…}` is a comment — do NOT use if `{` starts code |
| `CComment` | `/* … */` | C block comment |
| `DollarComment` | `$( … $)` | |
| `SmartComment` | `{* … *}` | Smarty templates |
| `HaskellComment` | `{- … -}` | |
| `DComment` | `/+ … +/` | D language |
| `JCLComment` | `//* … *//` | JCL block |
| `VLispComment` | `;\| … \|;` | Visual LISP |
| `CLispComment` | `#\| … \|#` | AutoLISP |
| `DeadComment` | `''' … '''` | Jovial |
| `2Exclamation` | `!! … !!` | |
| `DollarMultiComment` | `$ … $` | |
| `ForthComment` | `( … )` | Forth paren comments |
| `HTMLComment` | `<!-- … -->` | |
| `LuaComment` | `--[[ … ]]` | Lua long comment |
| `LilypondComment` | `%( … %)` | |
| `OkumaComment` | `( … )` | OKUMA CNC |
| `HellerComment` | `(* … *)` / `(/ … /)` | |
| `PwShellComment` | `<# … #>` | PowerShell |
| `SSComment` | `* … ;` | From `*` to `;` |
| `TexInfoComment` | `@c`, `@ignore` … `@end ignore` | Texinfo |
| `AutoitBlockComm` | `#cs … #ce` | AutoIt block |
| `AVIComment` | `[* … *]` | AviSynth; **nested** block comments |

### 5.2 Single-line comments

| INI key | Syntax pattern | Notes |
|---------|----------------|-------|
| `SharpComment` | `#` to EOL | Python, shell, AviSynth, … |
| `SlashComment` | `//` to EOL | C, Java, JavaScript, … |
| `ExclComment` | `!` to EOL | |
| `PerCentComment` | `%` to EOL | |
| `SpecComment` | `/` (special rules) | |
| `BackSlashComment` | `\` to EOL | **Do NOT** use if `\` continues lines |
| `LineCComment` | `/*` to EOL | |
| `BasComment` | `'` REM style | Basic |
| `INIComment` | `;` at line start | INI files |
| `FoxComment` | `*` + `&&&&` | FoxPro |
| `REMComment` | `REM`, `::` | Batch files |
| `ByComment` | `@` to EOL | |
| `SinglQComment` | `'` to EOL | Comment, not string |
| `DblQComment` | `"` to EOL | Comment, not string |
| `SQLComment` | `--` to EOL | SQL |
| `CStarComment` | `C*` | |
| `FortranComment` | `C` in column 1 | Fortran |
| `LBracketComment` | `{` to EOL | **Do NOT** use if `{` starts code |
| `PocoComment` | `* ;` | |
| `DMISComment` | `$$` | |
| `PipeComment` | `\|` to EOL | |
| `WebFocusComment` | `-*` | |
| `TabKeyComment` | Tab key | |
| `2StarsComment` | `**` | |
| `PCLComment` | `!*` | |
| `SpaceComment` | leading space | Descript.ion style |
| `DashComment` | `-` at line start | |
| `AngleBrackets` | `<<<` | |
| `EuklidComment` | `..` | |
| `JCLsingleComment` | `//*` | |
| `AutomatonComment` | `%%` | |
| `CPLComment` | `$` to EOL | |

### 5.3 Comment selection guidelines

| Language feature | Recommended keys | Avoid |
|------------------|------------------|-------|
| `#` line comment | `SharpComment=1`, `CommentString=#` | |
| `//` line comment | `SlashComment=1`, `CommentString=//` | |
| `/* */` block | `CComment=1` | |
| `;` line comment (INI, Pascal) | `INIComment=1` or `SharpComment` depending on context | |
| `{` code blocks (C, AviSynth functions) | — | `PasComment`, `LBracketComment` |
| `\` line continuation | — | `BackSlashComment` |
| AviSynth | `SharpComment`, `CComment`, `AVIComment` | `BackSlashComment` |

---

## 6. AI workflow (step by step)

1. **Gather syntax facts:** comments, strings, identifier rules, case sensitivity, hex/number formats if relevant.
2. **Map comments** to keys in Section 5 — use existing keys only.
3. **Minimize** enabled comment flags (precision over completeness).
4. **Configure strings:** `SingleQuote`, `DoubleQuote`, `ApostropheQuote`, `EscString`, `EscChar`.
5. **Set** `CaseSensitive`, `KeyWordChars`, `FileType`, `Name`.
6. **Distribute keywords** across four sections by semantics (language words vs builtins vs API).
7. **Set** `CodeExplorer=ftUnknown` unless a known `ft*` parser applies.
8. **Set** `CodeFolding=cftCurlyBracket` only if `{` `}` delimit foldable blocks (not comments).
9. **Emit** complete INI (Section 7).
10. **Validate** against Section 8.
11. If required syntax has **no matching key**, report that PSPad source must be extended (Section 10) — do not invent keys.

---

## 7. Required AI output format

When generating a highlighter, the AI MUST produce:

### 7.1 Complete INI file

A single fenced code block with the full `.ini` content, ready to save.

### 7.2 Rationale (short paragraph)

- Which comment keys were enabled and why
- `CaseSensitive` choice
- How keywords were grouped

### 7.3 Registration instructions

Tell the user:

1. Save the file in `.\PSpad\Syntax` (portable version) or `%appData%\PSPad\Syntax` (installed version).
2. Open PSPad → Settings → Highlighters Settings.
3. Assign a free user slot (`General` … `General9`) to `<Name>` (INI name without extension).
4. Confirm file extensions in `FileType` match.

### 7.4 Limitations (if any)

List syntax features that cannot be highlighted correctly with INI alone.

---

## 8. Validation checklist

Before delivering the INI, verify:

- [ ] Line 1 is `;PSPad user HighLighter definition file`
- [ ] Section `[Settings]` exists with `Name` and `FileType`
- [ ] Sections `[KeyWords]`, `[ReservedWords]`, `[KeyWords2]`, `[KeyWords3]` all exist
- [ ] Every keyword line ends with `=`
- [ ] No duplicate keywords within the same section
- [ ] `FileType` includes all requested extensions
- [ ] `CommentString` matches the primary line-comment toggle character
- [ ] No conflicting comment styles (e.g. `PasComment` + language using `{` for code)
- [ ] `BackSlashComment` is off when `\` continues lines
- [ ] String settings match language (`DoubleQuote` vs `SingleQuote`, etc.)
- [ ] Only INI keys from this specification are used

---

## 9. Examples

### 9.1 Minimal example (C-like syntax)

```ini
;PSPad user HighLighter definition file
[Settings]
Name=Minimal
HTMLGroup=0
Vectors=0
Label=0
PHPVariable=0
RubySymbols=0
FileType=*.min
CommentString=//
SlashComment=1
CComment=1
IndentChar=
UnIndentChar=
TabWidth=2
CaseSensitive=1
SingleQuote=0
DoubleQuote=1
ApostropheQuote=0
EscString=1
EscChar=\
KeyWordChars=_
KW1StartWith=0
KW2StartWith=0
KW3StartWith=0
KW4StartWith=0
Preprocessors=0
CodeExplorer=ftUnknown
CodeFolding=ftNone
DocComment=
[KeyWords]
if=
else=
while=
for=
return=
[ReservedWords]
[KeyWords2]
[KeyWords3]
```

### 9.2 Reference: AviSynth (complex real-world highlighter)

See the shipped example `AviSynth.ini`.

Notable choices:

- `CaseSensitive=0` (AviSynth ignores case)
- `SharpComment=1` (`#` comments)
- `CComment=1` (`/* */`)
- `AVIComment=1` (nested `[* … *]`)
- `BackSlashComment` **not** enabled (`\` is line continuation)
- `PasComment` / `LBracketComment` **not** enabled (`{` starts function bodies)
- `CodeFolding=cftCurlyBracket`
- Keywords split across four sections (language, builtins, filters, clip properties)

---

## 10. Limitations — when INI is not enough

The user highlighter engine (`TSynGeneralSyn`) only supports the comment styles, string modes, and keyword lists defined in this document.

**INI alone cannot add:**

- New comment delimiters not listed in Section 5
- Nested comments except where explicitly supported (`AVIComment`)
- Language-specific parsers (e.g. heredocs, regex literals, custom number formats)
- Semantic highlighting (types vs variables by context)

**If new syntax is required**, PSPad/SynEdit **source code** must be modified:

| Component | Role |
|-----------|------|
| `SynHighlighterGeneral.pas` | Lexer: new comment state, procedures, `GetRange`/`SetRange` |
| `uUserHL.pas` + `uUserHL.dfm` | UI checkbox + Load/Save for new INI key |
| `uParams.pas` | `SetUserHighLighter`: map INI key → lexer enum |

Do not invent undocumented INI keys — they will be ignored by PSPad.

---

## 11. Common mistakes

| Mistake | Consequence |
|---------|-------------|
| `PasComment=1` for language with `{` code blocks | Entire function bodies highlighted as comments |
| `BackSlashComment=1` with line continuation | Trailing `\` highlighted as comment incorrectly |
| Missing `=` on keyword lines | Keywords may not load |
| INI saved outside `.\PSpad\Syntax` (portable version) or `%appData%\PSPad\Syntax` (installed version) | Highlighter missing from the user-slot list |
| Too many comment styles enabled | False positives in normal code |
| Invented INI keys | Silently ignored — feature won't work |
| `FileType` mismatch | Files not associated with highlighter |

---

## 12. Quick reference card

```
File:     ;PSPad user HighLighter definition file
          [Settings] Name, FileType, comments, strings, CaseSensitive, KeyWordChars
          [KeyWords]        → language keywords
          [ReservedWords]   → builtins
          [KeyWords2]       → stdlib / API group 2
          [KeyWords3]       → API group 3

Keywords: always "word=" format
Booleans: 0 or 1
Paths:    portable .\PSpad\Syntax  or  installed %appData%\PSPad\Syntax
Default:  CodeExplorer=ftUnknown, CodeFolding=ftNone
```

---

*End of specification.*
