textmate_grammar.engine.plist

Faithful port of microsoft/vscode-textmate src/plist.ts (v9.3.2).

A very fast dependency-free property-list (XML) parser for TextMate grammars. It is deliberately not a general XML parser: it understands exactly the tags TextMate grammars use (dict, array, key, string, real, integer, date, data, true, false, plist) and skips processing instructions, comments and doctypes. Semantics shipped here match the TypeScript implementation 1:1, including its errors and quirks:

  • Quirks preserved: closing tags and the plist tag are matched by string prefix (</dictionary> closes as </dict>); unterminated values at EOF are accepted; there is no CDATA support (<![CDATA[...]]> is skipped to the next > like a comment); named entities only cover &amp;&lt;&gt;&quot;&apos;, while numeric entities are decimal &#NNN; and lowercase-hex &#xNNN; (uppercase hex digits are not decoded; &#x4A; stays literal); <true>/<false> ignore their text content; <integer> values always yield a JS number (a Python float).

  • Locations ($vscodeTextmateLocation entries) are only produced in the parse_with_location debug path, exactly like upstream.

  • Errors are ValueError with the upstream message format:

    Near offset <pos>: <message> ~~~<50 chars of input>~~~
    

See plist.ts in microsoft/vscode-textmate for the reference implementation.

Module Contents

Functions

parse_with_location

Parse content, optionally embedding locations (debug mode).

parse_plist

A very fast plist parser (plist.parsePLIST upstream).

Data

API

textmate_grammar.engine.plist.PLIST_LOCATION_KEY = '$vscodeTextmateLocation'
textmate_grammar.engine.plist.parse_with_location(content: str, filename: str | None, location_key_name: str | None) → Any

Parse content, optionally embedding locations (debug mode).

textmate_grammar.engine.plist.parse_plist(content: str) → Any

A very fast plist parser (plist.parsePLIST upstream).