Expand description
IEC 61131-3 Structured Text parser.
This crate provides a parser for IEC 61131-3 Structured Text (ST) language, used in PLC programming.
§Example
use iecst::parse_statement;
let code = "x := 1 + 2;";
let result = parse_statement(code);
assert!(result.is_ok());§Supported Constructs
§Expressions
- Literals: integers, reals, strings, booleans, time literals
- Identifiers and qualified names
- Binary operators: +, -, *, /, MOD, **, AND, OR, XOR, NOT, comparisons
- Unary operators: -, NOT
- Function calls:
SIN(x),MAX(a, b) - Array indexing:
arr[i],arr[i, j] - Member access:
struct.field
§Statements
- Assignment:
x := expr; - IF/THEN/ELSIF/ELSE/END_IF
- CASE/OF/ELSE/END_CASE
- FOR/TO/BY/DO/END_FOR
- WHILE/DO/END_WHILE
- REPEAT/UNTIL/END_REPEAT
- EXIT, RETURN, CONTINUE
- Function/FB calls
§Program Organization Units (POUs)
- PROGRAM/END_PROGRAM
- FUNCTION/END_FUNCTION
- FUNCTION_BLOCK/END_FUNCTION_BLOCK
§Declarations
- VAR/VAR_INPUT/VAR_OUTPUT/VAR_IN_OUT/VAR_TEMP/VAR_GLOBAL
- TYPE/END_TYPE (structures, enums, arrays, subranges)
Re-exports§
pub use security::ParserLimits;pub use security::ParserState;pub use security::SecurityError;pub use analysis::analyze_pou;pub use analysis::Diagnostic;pub use analysis::DiagnosticKind;pub use analysis::Severity;pub use analysis::Type;pub use analysis::Cfg;pub use analysis::CfgBuilder;pub use analysis::CfgNode;pub use analysis::NodeId;pub use analysis::NodeKind;pub use analysis::max_nesting_depth;
Modules§
- analysis
- Semantic analysis for IEC 61131-3 Structured Text.
- security
- Security limits for IEC 61131-3 ST parser to prevent DoS attacks
Structs§
- Array
Range - Array dimension range.
- CallArg
- Argument in a function/FB call.
- Case
Branch - A branch in a CASE statement.
- Direct
Address - Direct address (I/O or memory location). Examples: %IX0.0, %QW5, %MW100, %MD10
- Enum
Value - Enumeration value.
- Expr
- An expression node.
- Function
Arg - Function/FB call argument (may be named).
- Parse
Error - Parse error with location information.
- Pou
- A Program Organization Unit.
- Span
- A span in the source text (byte offsets).
- Stmt
- A statement node.
- Type
Decl - A type declaration.
- Type
Spec - Type specification.
- VarBlock
- Variable block (VAR, VAR_INPUT, etc.)
- VarDecl
- Variable declaration.
Enums§
- Binary
Op - Binary operators.
- Case
Value - A value or range in a CASE branch.
- Expr
Kind - Expression kinds.
- Location
Prefix - Location prefix for direct addresses.
- Parse
Error Kind - Kinds of parse errors that can occur.
- PouKind
- Kind of POU.
- Retain
Kind - Retain attribute.
- Size
Prefix - Size prefix for direct addresses.
- Stmt
Kind - Statement kinds.
- TypeDef
- Type definition body.
- Type
Kind - Type kinds.
- UnaryOp
- Unary operators.
- VarBlock
Kind - Kind of variable block.
Functions§
- parse_
expression - Parse an expression from source.
- parse_
pou - Parse a POU from source.
- parse_
statement - Parse a single statement from source.
- parse_
statements - Parse multiple statements from source.
- parse_
type_ block - Parse a TYPE block from source.
Type Aliases§
- Parse
Result - Result type for parsing operations.