Skip to content

Commit 1c69eac

Browse files
committed
iecst readme
1 parent a7fb9f6 commit 1c69eac

2 files changed

Lines changed: 122 additions & 2 deletions

File tree

‎iecst/Cargo.toml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
name = "iecst"
33
version = "0.1.0"
44
edition = "2021"
5-
description = "IEC 61131-3 Structured Text parser"
6-
license = "MIT OR Apache-2.0"
5+
description = "IEC 61131-3 Structured Text parser for PLC programming"
6+
license = "MIT"
77
repository = "https://github.com/radevgit/plc"
8+
homepage = "https://github.com/radevgit/plc/tree/main/iecst"
9+
documentation = "https://docs.rs/iecst"
10+
readme = "README.md"
811
keywords = ["plc", "iec61131", "structured-text", "parser", "automation"]
912
categories = ["parsing", "development-tools"]
13+
authors = ["radevgit"]
14+
rust-version = "1.70"
1015

1116
[dependencies]
1217
winnow = "0.7"

‎iecst/README.md‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# iecst
2+
3+
IEC 61131-3 Structured Text parser for Rust.
4+
5+
[![Crates.io](https://img.shields.io/crates/v/iecst.svg)](https://crates.io/crates/iecst)
6+
[![Documentation](https://docs.rs/iecst/badge.svg)](https://docs.rs/iecst)
7+
[![License](https://img.shields.io/crates/l/iecst.svg)](LICENSE)
8+
9+
## Overview
10+
11+
`iecst` is a parser for IEC 61131-3 Structured Text (ST), the high-level programming language used in PLC (Programmable Logic Controller) programming.
12+
13+
## Features
14+
15+
- **Full ST syntax support** - expressions, statements, POUs, declarations
16+
- **Minimal dependencies** (`winnow` for parsing)
17+
- **Detailed error reporting** with source locations
18+
- **AST output** for further analysis or transformation
19+
- **Basic static analysis** - type checking, unused variables, code smells
20+
21+
## Installation
22+
23+
Add to your `Cargo.toml`:
24+
25+
```toml
26+
[dependencies]
27+
iecst = "0.1"
28+
```
29+
30+
## Quick Start
31+
32+
```rust
33+
use iecst::{parse_statement, parse_expression};
34+
35+
// Parse a statement
36+
let stmt = parse_statement("x := 1 + 2;").unwrap();
37+
38+
// Parse an expression
39+
let expr = parse_expression("a AND b OR c").unwrap();
40+
```
41+
42+
## Supported Constructs
43+
44+
### Expressions
45+
- Literals: integers, reals, strings, booleans, time literals
46+
- Identifiers and qualified names
47+
- Binary operators: `+`, `-`, `*`, `/`, `MOD`, `**`, `AND`, `OR`, `XOR`, comparisons
48+
- Unary operators: `-`, `NOT`
49+
- Function calls: `SIN(x)`, `MAX(a, b)`
50+
- Array indexing: `arr[i]`, `arr[i, j]`
51+
- Member access: `struct.field`
52+
53+
### Statements
54+
- Assignment: `x := expr;`
55+
- IF/THEN/ELSIF/ELSE/END_IF
56+
- CASE/OF/ELSE/END_CASE
57+
- FOR/TO/BY/DO/END_FOR
58+
- WHILE/DO/END_WHILE
59+
- REPEAT/UNTIL/END_REPEAT
60+
- EXIT, RETURN, CONTINUE
61+
62+
### Program Organization Units (POUs)
63+
- PROGRAM/END_PROGRAM
64+
- FUNCTION/END_FUNCTION
65+
- FUNCTION_BLOCK/END_FUNCTION_BLOCK
66+
67+
### Declarations
68+
- VAR/VAR_INPUT/VAR_OUTPUT/VAR_IN_OUT/VAR_TEMP/VAR_GLOBAL
69+
- TYPE/END_TYPE (structures, enums, arrays, subranges)
70+
71+
## Example: Parsing a Function Block
72+
73+
```rust
74+
use iecst::parse_pou;
75+
76+
let code = r#"
77+
FUNCTION_BLOCK Counter
78+
VAR_INPUT
79+
Reset : BOOL;
80+
END_VAR
81+
VAR_OUTPUT
82+
Count : INT;
83+
END_VAR
84+
VAR
85+
_count : INT := 0;
86+
END_VAR
87+
88+
IF Reset THEN
89+
_count := 0;
90+
ELSE
91+
_count := _count + 1;
92+
END_IF;
93+
94+
Count := _count;
95+
END_FUNCTION_BLOCK
96+
"#;
97+
98+
let pou = parse_pou(code).unwrap();
99+
println!("Parsed: {:?}", pou.name);
100+
```
101+
102+
## Static Analysis
103+
104+
```rust
105+
use iecst::{parse_pou, analyze_pou};
106+
107+
let code = "FUNCTION Test : INT VAR x : INT; END_VAR x := 1; Test := x; END_FUNCTION";
108+
let pou = parse_pou(code).unwrap();
109+
let diagnostics = analyze_pou(&pou);
110+
111+
for diag in diagnostics {
112+
println!("[{}] {}", diag.severity, diag.message);
113+
}
114+
```
115+

0 commit comments

Comments
 (0)