Skip to content

Commit

Permalink
Added support for Structured Text (IEC 61131-3) (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhioromano authored Apr 12, 2020
1 parent 044dd27 commit 8704cdf
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@
"title": "Icon",
"owner": "Golmote"
},
"iecst": {
"title": "Structured Text (IEC 61131-3)",
"owner": "serhioromano"
},
"inform7": {
"title": "Inform 7",
"owner": "Golmote"
Expand Down
30 changes: 30 additions & 0 deletions components/prism-iecst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Prism.languages.iecst = {
'comment': [
{
pattern: /(^|[^\\])(?:\/\*[\s\S]*?(?:\*\/|$)|\(\*[\s\S]*?(?:\*\)|$)|\{[\s\S]*?(?:\}|$))/,
lookbehind: true,
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true,
},
],
'string': {
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
greedy: true,
},
'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,
'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/,
'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/,
'symbol': /%[IQM][XBWDL][\d.]*|%[IQ][\d.]*/,
'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,
'boolean': /\b(?:TRUE|FALSE|NULL)\b/,
'function': /\w+(?=\()/,
'operator': /(?:S?R?:?=>?|&&?|\*\*?|<=?|>=?|[-:^/+])|\b(?:OR|AND|MOD|NOT|XOR|LE|GE|EQ|NE|GE|LT)\b/,
'punctuation': /[();]/,
'type': {
'pattern': /#/,
'alias': 'selector',
},
};
1 change: 1 addition & 0 deletions components/prism-iecst.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions examples/prism-iecst.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h2>Code</h2>
<pre><code>
CONFIGURATION DefaultCfg
VAR_GLOBAL
Start_Stop AT %IX0.0: BOOL; (* This is a comment *)
END_VAR
TASK NewTask (INTERVAL := T#20ms);
PROGRAM Main WITH NewTask : PLC_PRG;
END_CONFIGURATION

PROGRAM demo
VAR_EXTERNAL
Start_Stop: BOOL;
StringVar: STRING[250] := "Test String"
END_VAR
VAR
a : REAL; // Another comment
todTest: TIME_OF_DAY := TOD#12:55;
END_VAR
a := csq(12.5);
IF a > REAL#100 - 16#FAC0 + 2#1001_0110 THEN
Start_Stop := TRUE;
END_IF
END_PROGRAM;

FUNCTION_BLOCK PRIVATE MyName EXTENDS AnotherName

END_FUNCTION_BLOCK

/* Get a square of the circle */
FUNCTION csq : REAL
VAR_INPUT
r: REAL;
END_VAR
VAR CONSTANT
c_pi: REAL := 3.14;
END_VAR
csq := ABS(c_pi * (r * 2));
END_FUNCTION
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"hpkp": "HTTP Public-Key-Pins",
"hsts": "HTTP Strict-Transport-Security",
"ichigojam": "IchigoJam",
"iecst": "Structured Text (IEC 61131-3)",
"inform7": "Inform 7",
"javadoc": "JavaDoc",
"javadoclike": "JavaDoc-like",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/languages/iecst/block.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
csq := ABS(c_pi * (r * 2));

----------------------------------------------------

[
"csq ",
["operator", ":="],
["function", "ABS"],
["punctuation", "("],
"c_pi ",
["operator", "*"],
["punctuation", "("],
"r ",
["operator", "*"],
["number", "2"],
["punctuation", ")"],
["punctuation", ")"],
["punctuation", ";"]
]

----------------------------------------------------

Checks expression.
13 changes: 13 additions & 0 deletions tests/languages/iecst/number.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
a := 100

----------------------------------------------------

[
"a ",
["operator", ":="],
["number", "100"]
]

----------------------------------------------------

Checks number.
22 changes: 22 additions & 0 deletions tests/languages/iecst/symbol.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
VAR
varname AT %QX1.0.0: BOOL := TRUE;
END_VAR

----------------------------------------------------

[
["class-name", "VAR"],
"\n varname ",
["keyword", "AT"],
["symbol", "%QX1.0.0"],
["operator", ":"],
["variable", "BOOL"],
["operator", ":="],
["boolean", "TRUE"],
["punctuation", ";"],
["class-name", "END_VAR"]
]

----------------------------------------------------

Checks symbols.

0 comments on commit 8704cdf

Please sign in to comment.