-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Structured Text (IEC 61131-3) (#2311)
- Loading branch information
1 parent
044dd27
commit 8704cdf
Showing
10 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
a := 100 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
"a ", | ||
["operator", ":="], | ||
["number", "100"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks number. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |