Skip to content

Commit 32f8667

Browse files
committed
Initial comit
0 parents  commit 32f8667

File tree

12 files changed

+353
-0
lines changed

12 files changed

+353
-0
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true
4+
5+
[*.{js,css}]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.DS_Store

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
dist: xenial
3+
node_js:
4+
- lts/*
5+
6+
install:
7+
- npm install
8+
9+
cache:
10+
directories:
11+
- node_modules
12+
13+
script:
14+
- npm test

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ST Language Support
2+
3+
This repository provide syntax Highlights for highlight.js for Structured Text language. ST is one of the 6 languages of IEC 61131-3 standard developed in 1998 for developing PLC programs.
4+
5+
We want to provide ST syntax highlights in VS Code Markdown editor and Markdown preview. And other cases when tutorials are published in the web.

example.iecst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CONFIGURATION DefaultCfg
2+
VAR_GLOBAL
3+
Start_Stop AT %IX0.0: BOOL; (* This is a comment *)
4+
END_VAR
5+
TASK NewTask (INTERVAL := T#20ms);
6+
PROGRAM Main WITH NewTask : PLC_PRG;
7+
END_CONFIGURATION
8+
PROGRAM demo
9+
VAR_EXTERNAL
10+
Start_Stop: BOOL;
11+
END_VAR
12+
VAR
13+
a : REAL; // Another comment
14+
todTest: TIME_OF_DAY := TOD#12:55;
15+
END_VAR
16+
a := csq(12.5); 16#FAC0 2#1001_0110
17+
IF a > REAL#100 THEN
18+
Start_Stop := TRUE;
19+
END_IF
20+
END_PROGRAM;
21+
/* Get a square of the circle */
22+
FUNCTION csq : REAL
23+
VAR_INPUT
24+
r: REAL;
25+
END_VAR
26+
VAR CONSTANT
27+
c_pi: REAL := 3.14;
28+
END_VAR
29+
csq := ABS(c_pi * (r * 2));
30+
END_FUNCTION

iecst.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* highlight.js Structured Text syntax highlighting definition
3+
*
4+
* @see https://github.com/highlightjs/highlight.js
5+
*
6+
* @package: highlightjs-iecst
7+
* @author: Sergey Romanov <[email protected]>
8+
* @since: 2019-08-02
9+
*
10+
* Description: Structured Text is one of the 6 languages of IEC 61131-3
11+
* standard, for developing PLC programs.
12+
* Category: scripting
13+
*/
14+
15+
var module = module ? module : {}; // shim for browser use
16+
17+
function hljsDefineIECST(hljs) {
18+
return {
19+
aliases: ["scl", "stl", "structured-text"],
20+
case_insensitive: true,
21+
keywords: {
22+
keyword:
23+
"if then end_if elsif else case of end_case " +
24+
"to do by while repeat end_while end_repeat for end_for from " +
25+
"or and not xor le ge eq ne ge lt constant return exit at retain non_retain task with until using extend",
26+
title:
27+
"program end_program function end_function function_block end_function_block configuration " +
28+
"end_configuration action end_action transition end_transition type end_type struct end_struct step " +
29+
"end_step initial_step namespace end_namespace channel end_channel library end_library folder end_folder resource end_resource " +
30+
"var var_global end_var var_input VAR_EXTERNAL var_out var_output var_in_out var_temp var_interval var_access var_config method end_method property end_property interface end_interface",
31+
literal: "false true null ",
32+
built_in:
33+
"array pointer int sint dint lint usint uint udint ulint real lreal time date time_of_day date_and_time dt tod string bool byte world dworld lworld ref_to any_num any_int any_string",
34+
function:
35+
"mod abs acos asin atan cos exp expt ln log sin sqrt tan sel max min limit mux shl shr rol ror indexof sizeof adr ref adrinst bitadr add mul div sub trunc move"
36+
},
37+
contains: [
38+
{
39+
className: "string",
40+
begin: "'",
41+
end: "'",
42+
contains: [hljs.BACKSLASH_ESCAPE, { begin: "''" }],
43+
relevance: 0
44+
},
45+
{
46+
className: "string",
47+
begin: '"',
48+
end: '"',
49+
contains: [hljs.BACKSLASH_ESCAPE, { begin: '""' }],
50+
relevance: 0
51+
},
52+
{
53+
className: "symbol",
54+
begin: "(T|DT|TOD)#[0-9:-_shmyd]*"
55+
},
56+
{
57+
className: "symbol",
58+
begin: "[A-Za-z]{1,6}#[0-9_.e]*",
59+
relevance: 0
60+
},
61+
{
62+
className: "number",
63+
begin: "[0-9]*#[a-zA-Z0-9_]*",
64+
relevance: 0
65+
},
66+
{
67+
className: "number",
68+
begin: "[a-zA-Z_]*#[a-zA-Z_]*",
69+
relevance: 0
70+
},
71+
{
72+
className: "symbol",
73+
begin: "%(I|Q|M)(X|B|W|D|L)[0-9.]*"
74+
},
75+
{
76+
className: "symbol",
77+
begin: "%(I|Q|M)[0-9.]*"
78+
},
79+
hljs.C_NUMBER_MODE,
80+
hljs.COMMENT("//", "$"),
81+
hljs.C_BLOCK_COMMENT_MODE,
82+
hljs.COMMENT("\\(\\*", "\\*\\)")
83+
]
84+
};
85+
}
86+
87+
module.exports = function(hljs) {
88+
hljs.registerLanguage("iecst", hljsDefineIECST);
89+
};
90+
91+
module.exports.definer = hljsDefineIECST;

package-lock.json

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "highlightjs-structured-text",
3+
"version": "1.0.0",
4+
"description": "highlight.js syntax definition for Structured Text IEC 61131-3 language",
5+
"main": "iecst.js",
6+
"scripts": {
7+
"test": "jasmine"
8+
},
9+
"files": [
10+
"iecst.js"
11+
],
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/highlightjs/highlightjs-structured-text.git"
15+
},
16+
"keywords": [
17+
"ST",
18+
"Structured Text",
19+
"IEC 61131-3",
20+
"CoDeSys",
21+
"PLC",
22+
"highlight.js",
23+
"highlightjs",
24+
"syntax"
25+
],
26+
"author": "Sergey Romanov",
27+
"license": "MIT",
28+
"bugs": {
29+
"url": "https://github.com/Serhioromano/highlightjs-structured-text/issues"
30+
},
31+
"homepage": "https://github.com/highlightjs/highlightjs--structured-text#readme",
32+
"devDependencies": {
33+
"highlight.js": "^9.15.6",
34+
"jasmine": "^3.3.1"
35+
}
36+
}

spec/expected.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<span class="hljs-title">CONFIGURATION</span> DefaultCfg
2+
<span class="hljs-title">VAR_GLOBAL</span>
3+
Start_Stop <span class="hljs-keyword">AT</span> <span class="hljs-symbol">%IX0.0</span>: <span class="hljs-built_in">BOOL</span>; <span class="hljs-comment">(* This is comment *)</span>
4+
<span class="hljs-title">END_VAR</span>
5+
<span class="hljs-title">END_CONFIGURATION</span>

spec/iecst-spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const hljs = require("highlight.js/lib/highlight");
2+
const { definer: iecst } = require("../iecst");
3+
const fs = require("fs");
4+
const path = require("path");
5+
hljs.registerLanguage("iecst", iecst);
6+
7+
describe("respec-highlight bundle", () => {
8+
it("highlights iecst", () => {
9+
// Load the input file...
10+
const input = fs.readFileSync(
11+
path.resolve(__dirname, "./input.txt"),
12+
"utf-8"
13+
);
14+
15+
// Do the highlight...
16+
const { value: result, language } = hljs.highlightAuto(input, [
17+
"iecst"
18+
]);
19+
expect(language).toBe("iecst");
20+
21+
// Check the output is what we expect...
22+
const expected = fs.readFileSync(
23+
path.resolve(__dirname, "./expected.txt"),
24+
"utf-8"
25+
);
26+
expect(result).toBe(expected);
27+
});
28+
});

0 commit comments

Comments
 (0)