ST parser wrapper around blark.
Provides parse_st() which parses IEC 61131-3 Structured Text source code
and returns a ParseResult containing the blark typed AST, original source,
and filename for error reporting.
Provides parse_file() which auto-detects file format by extension and
supports plain ST (.st, .txt) and TwinCAT/PLCopen XML (.xml, .TcPOU,
.TcDUT, .TcGVL) input files.
| ParseResult st2js.parser._parse_plcopen_xml |
( |
Path | file_path | ) |
|
|
protected |
Parse a PLCopen XML file by reconstructing ST source from XML structure.
Codesys PLCopen XML exports store POU declarations (PROGRAM,
FUNCTION_BLOCK, FUNCTION), data types, global variables, and actions
as XML elements. The ST body code is embedded inside ``<ST>`` elements,
either as direct text/CDATA or within an ``<xhtml>`` child element.
This function reconstructs syntactically valid IEC 61131-3 Structured
Text source code from the XML structure, then parses it with blark.
Two styles are supported:
1. **CDATA style** -- ``<ST><![CDATA[PROGRAM Main ... END_PROGRAM]]></ST>``
The ST text already contains full POU wrappers; we just extract & join.
2. **Codesys xhtml style** -- ``<pou pouType="program" name="Main">``
with ``<interface>`` holding variable sections and ``<body><ST><xhtml>``
holding only the body statements. We reconstruct the ST wrapper from
the XML structure.
Args:
file_path: Path to the PLCopen XML file.
Returns:
ParseResult with the typed AST.
Raises:
ParseError: If the file cannot be read, is not valid XML, or
contains no parseable ST code.
Parse an ST source file, auto-detecting format by extension.
Supports plain ST files (.st, .txt) and TwinCAT/PLCopen XML files
(.xml, .TcPOU, .TcDUT, .TcGVL). For XML files, blark.parse.parse()
handles extraction of ST code from CDATA sections.
Args:
path: Filesystem path to the input file.
Returns:
ParseResult with the typed AST, source, and filename.
Raises:
ParseError: If the file cannot be read or parsed.