Skip to content

Commit 8704cdf

Browse files
authored
Added support for Structured Text (IEC 61131-3) (#2311)
1 parent 044dd27 commit 8704cdf

File tree

10 files changed

+136
-2
lines changed

10 files changed

+136
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@
458458
"title": "Icon",
459459
"owner": "Golmote"
460460
},
461+
"iecst": {
462+
"title": "Structured Text (IEC 61131-3)",
463+
"owner": "serhioromano"
464+
},
461465
"inform7": {
462466
"title": "Inform 7",
463467
"owner": "Golmote"

components/prism-iecst.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Prism.languages.iecst = {
2+
'comment': [
3+
{
4+
pattern: /(^|[^\\])(?:\/\*[\s\S]*?(?:\*\/|$)|\(\*[\s\S]*?(?:\*\)|$)|\{[\s\S]*?(?:\}|$))/,
5+
lookbehind: true,
6+
},
7+
{
8+
pattern: /(^|[^\\:])\/\/.*/,
9+
lookbehind: true,
10+
greedy: true,
11+
},
12+
],
13+
'string': {
14+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
15+
greedy: true,
16+
},
17+
'class-name': /\b(?:END_)?(?:PROGRAM|CONFIGURATION|INTERFACE|FUNCTION_BLOCK|FUNCTION|ACTION|TRANSITION|TYPE|STRUCT|(?:INITIAL_)?STEP|NAMESPACE|LIBRARY|CHANNEL|FOLDER|RESOURCE|VAR_(?:GLOBAL|INPUT|PUTPUT|IN_OUT|ACCESS|TEMP|EXTERNAL|CONFIG)|VAR|METHOD|PROPERTY)\b/i,
18+
'keyword': /\b(?:(?:END_)?(?:IF|WHILE|REPEAT|CASE|FOR)|ELSE|FROM|THEN|ELSIF|DO|TO|BY|PRIVATE|PUBLIC|PROTECTED|CONSTANT|RETURN|EXIT|CONTINUE|GOTO|JMP|AT|RETAIN|NON_RETAIN|TASK|WITH|UNTIL|USING|EXTENDS|IMPLEMENTS|GET|SET|__TRY|__CATCH|__FINALLY|__ENDTRY)\b/,
19+
'variable': /\b(?:AT|BOOL|BYTE|(?:D|L)?WORD|U?(?:S|D|L)?INT|L?REAL|TIME(?:_OF_DAY)?|TOD|DT|DATE(?:_AND_TIME)?|STRING|ARRAY|ANY|POINTER)\b/,
20+
'symbol': /%[IQM][XBWDL][\d.]*|%[IQ][\d.]*/,
21+
'number': /\b(?:16#[\da-f]+|2#[01_]+|0x[\da-f]+)\b|\b(?:T|D|DT|TOD)#[\d_shmd:]*|\b[A-Z]*\#[\d.,_]*|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i,
22+
'boolean': /\b(?:TRUE|FALSE|NULL)\b/,
23+
'function': /\w+(?=\()/,
24+
'operator': /(?:S?R?:?=>?|&&?|\*\*?|<=?|>=?|[-:^/+])|\b(?:OR|AND|MOD|NOT|XOR|LE|GE|EQ|NE|GE|LT)\b/,
25+
'punctuation': /[();]/,
26+
'type': {
27+
'pattern': /#/,
28+
'alias': 'selector',
29+
},
30+
};

components/prism-iecst.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-iecst.html

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<h2>Code</h2>
2+
<pre><code>
3+
CONFIGURATION DefaultCfg
4+
VAR_GLOBAL
5+
Start_Stop AT %IX0.0: BOOL; (* This is a comment *)
6+
END_VAR
7+
TASK NewTask (INTERVAL := T#20ms);
8+
PROGRAM Main WITH NewTask : PLC_PRG;
9+
END_CONFIGURATION
10+
11+
PROGRAM demo
12+
VAR_EXTERNAL
13+
Start_Stop: BOOL;
14+
StringVar: STRING[250] := "Test String"
15+
END_VAR
16+
VAR
17+
a : REAL; // Another comment
18+
todTest: TIME_OF_DAY := TOD#12:55;
19+
END_VAR
20+
a := csq(12.5);
21+
IF a > REAL#100 - 16#FAC0 + 2#1001_0110 THEN
22+
Start_Stop := TRUE;
23+
END_IF
24+
END_PROGRAM;
25+
26+
FUNCTION_BLOCK PRIVATE MyName EXTENDS AnotherName
27+
28+
END_FUNCTION_BLOCK
29+
30+
/* Get a square of the circle */
31+
FUNCTION csq : REAL
32+
VAR_INPUT
33+
r: REAL;
34+
END_VAR
35+
VAR CONSTANT
36+
c_pi: REAL := 3.14;
37+
END_VAR
38+
csq := ABS(c_pi * (r * 2));
39+
END_FUNCTION
40+
</code></pre>

plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"hpkp": "HTTP Public-Key-Pins",
7777
"hsts": "HTTP Strict-Transport-Security",
7878
"ichigojam": "IchigoJam",
79+
"iecst": "Structured Text (IEC 61131-3)",
7980
"inform7": "Inform 7",
8081
"javadoc": "JavaDoc",
8182
"javadoclike": "JavaDoc-like",

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/iecst/block.test

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
csq := ABS(c_pi * (r * 2));
2+
3+
----------------------------------------------------
4+
5+
[
6+
"csq ",
7+
["operator", ":="],
8+
["function", "ABS"],
9+
["punctuation", "("],
10+
"c_pi ",
11+
["operator", "*"],
12+
["punctuation", "("],
13+
"r ",
14+
["operator", "*"],
15+
["number", "2"],
16+
["punctuation", ")"],
17+
["punctuation", ")"],
18+
["punctuation", ";"]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks expression.

tests/languages/iecst/number.test

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
a := 100
2+
3+
----------------------------------------------------
4+
5+
[
6+
"a ",
7+
["operator", ":="],
8+
["number", "100"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks number.

tests/languages/iecst/symbol.test

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
VAR
2+
varname AT %QX1.0.0: BOOL := TRUE;
3+
END_VAR
4+
5+
----------------------------------------------------
6+
7+
[
8+
["class-name", "VAR"],
9+
"\n varname ",
10+
["keyword", "AT"],
11+
["symbol", "%QX1.0.0"],
12+
["operator", ":"],
13+
["variable", "BOOL"],
14+
["operator", ":="],
15+
["boolean", "TRUE"],
16+
["punctuation", ";"],
17+
["class-name", "END_VAR"]
18+
]
19+
20+
----------------------------------------------------
21+
22+
Checks symbols.

0 commit comments

Comments
 (0)