diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 3757dfab7f..94974c23ee 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -162,6 +162,7 @@ The table below shows the full list of languages (and corresponding classes/alia | Oak | oak | [highlightjs-oak](https://github.com/timlabs/highlightjs-oak) | | Object Constraint Language | ocl | [highlightjs-ocl](https://github.com/nhomble/highlightjs-ocl) | | OCaml | ocaml, ml | | +| Oberon | obn, mod | [highlightjs-oberon](https://github.com/miasapkarl/highlightjs-oberon) | | Objective C | objectivec, mm, objc, obj-c, obj-c++, objective-c++ | | | Odin | odin | [highlightjs-odin](https://github.com/NinjasCL/highlightjs-odin) | | OpenGL Shading Language | glsl | | diff --git a/src/languages/oberon.js b/src/languages/oberon.js new file mode 100644 index 0000000000..d0005e3e42 --- /dev/null +++ b/src/languages/oberon.js @@ -0,0 +1,64 @@ +/* +Language: Oberon +Description: Syntax highlighting for the final version of Oberon (also known as Oberon-07) +Author: Karl Landstrom +Website: https://miasap.se/obnc/oberon-report.html +Category: system +*/ + +export default function(hljs) +{ + const COMMENT = hljs.COMMENT(/\(\*/, /\*\)/, {contains: ["self"]}); + + const STRING = { + scope: "string", + variants: [ + {begin: '"', end: '"'}, + {begin: /\b\d[A-Z0-9]*X/} + ] + }; + + const NUMBER = { + scope: "number", + variants: [ + {begin: /\b\d+\.\d*(E[+-]?\d+)?/}, + {begin: /\b\d[A-Z0-9]*H/}, + {begin: /\b\d+/} + ] + }; + + const PUNCTUATION = { + scope: "punctuation", + begin: /[][(){}.,:;]/ + }; + + const MODULE_OR_PROCEDURE_DECLARATION = { + match: [ + /\b(?:MODULE|PROCEDURE)/, + /\s+/, + /\b\w+/], + scope: {1: "keyword", 3: "title"} + }; + + const RESERVED_WORDS = ["ARRAY", "BEGIN", "BY", "CASE", "CONST", "DIV", "DO", "ELSE", "ELSIF", "END", "FALSE", "FOR", "IF", "IMPORT", "IN", "IS", "MOD", "MODULE", "NIL", "OF", "OR", "POINTER", "PROCEDURE", "RECORD", "REPEAT", "RETURN", "THEN", "TO", "TRUE", "TYPE", "UNTIL", "VAR", "WHILE"]; + + const PREDEFINED_TYPES = ["BOOLEAN", "BYTE", "CHAR", "INTEGER", "REAL", "SET"]; + + const PREDEFINED_PROCEDURES = ["ABS", "ASR", "ASSERT", "CHR", "DEC", "EXCL", "FLOOR", "FLT", "INC", "INCL", "LEN", "LSL", "NEW", "ODD", "ORD", "PACK", "ROR", "UNPK"]; + + return { + name: "Oberon", + keywords: { + keyword: RESERVED_WORDS, + built_in: PREDEFINED_PROCEDURES, + type: PREDEFINED_TYPES + }, + contains: [ + COMMENT, + STRING, + NUMBER, + PUNCTUATION, + MODULE_OR_PROCEDURE_DECLARATION + ] + }; +} diff --git a/test/detect/oberon/default.txt b/test/detect/oberon/default.txt new file mode 100644 index 0000000000..241a43694d --- /dev/null +++ b/test/detect/oberon/default.txt @@ -0,0 +1,77 @@ +MODULE M; +(*a non-nested comment*) +(*a (*nested*) comment*) + + IMPORT Math; + + CONST + (*strings*) + str = "a string"; + null = 0X; + linefeed = 0AX; + + (*integers*) + i1 = 0; + i2 = 12; + i3 = -12; + i4 = 0H; + i5 = 01H; + i6 = 0AH; + i7 = 0A7H; + + (*real numbers*) + r1 = 1.; + r2 = 1.2; + r3 = 1.23; + r4 = 1.E0; + r5 = 1.2E+10; + r6 = 1.23E-10; + + TYPE + T = POINTER TO RECORD END; + + VAR + b: BOOLEAN; + y: BYTE; + ch: CHAR; + i: INTEGER; + r: REAL; + A: SET; + s: ARRAY 32 OF CHAR; + x: T; + + PROCEDURE Func(): INTEGER; + BEGIN + A := {1, 2, 4}; + x := NIL; + s[0] := 0X; + CASE 1 DIV 2 MOD 3 OF 0, 1: END; + FOR i := 0 TO 100 BY 10 DO END; + IF (0 IN {}) OR (x IS T) & TRUE THEN + ELSIF FALSE THEN + ELSE + END; + REPEAT UNTIL TRUE; + WHILE FALSE DO END; + r := ABS(r); + i := ASR(i, 1); + ASSERT(TRUE); + ch := CHR(0); + DEC(i); + EXCL(A, 0); + i := FLOOR(r); + r := FLT(i); + INC(i); + INCL(A, 0); + i := LEN(s); + i := LSL(i, 1); + NEW(x); + b := ODD(i); + i := ORD(ch); + PACK(r, 1); + i := ROR(i, 1); + UNPK(r, i) + RETURN 0 + END Func; + +END M. diff --git a/test/markup/oberon/default.expect.txt b/test/markup/oberon/default.expect.txt new file mode 100644 index 0000000000..f4004f1f3e --- /dev/null +++ b/test/markup/oberon/default.expect.txt @@ -0,0 +1,77 @@ +MODULE M; +(*a non-nested comment*) +(*a (*nested*) comment*) + + IMPORT Math; + + CONST + (*strings*) + str = "a string"; + null = 0X; + linefeed = 0AX; + + (*integers*) + i1 = 0; + i2 = 12; + i3 = -12; + i4 = 0H; + i5 = 01H; + i6 = 0AH; + i7 = 0A7H; + + (*real numbers*) + r1 = 1.; + r2 = 1.2; + r3 = 1.23; + r4 = 1.E0; + r5 = 1.2E+10; + r6 = 1.23E-10; + + TYPE + T = POINTER TO RECORD END; + + VAR + b: BOOLEAN; + y: BYTE; + ch: CHAR; + i: INTEGER; + r: REAL; + A: SET; + s: ARRAY 32 OF CHAR; + x: T; + + PROCEDURE Func(): INTEGER; + BEGIN + A := {1, 2, 4}; + x := NIL; + s[0] := 0X; + CASE 1 DIV 2 MOD 3 OF 0, 1: END; + FOR i := 0 TO 100 BY 10 DO END; + IF (0 IN {}) OR (x IS T) & TRUE THEN + ELSIF FALSE THEN + ELSE + END; + REPEAT UNTIL TRUE; + WHILE FALSE DO END; + r := ABS(r); + i := ASR(i, 1); + ASSERT(TRUE); + ch := CHR(0); + DEC(i); + EXCL(A, 0); + i := FLOOR(r); + r := FLT(i); + INC(i); + INCL(A, 0); + i := LEN(s); + i := LSL(i, 1); + NEW(x); + b := ODD(i); + i := ORD(ch); + PACK(r, 1); + i := ROR(i, 1); + UNPK(r, i) + RETURN 0 + END Func; + +END M. diff --git a/test/markup/oberon/default.txt b/test/markup/oberon/default.txt new file mode 100644 index 0000000000..241a43694d --- /dev/null +++ b/test/markup/oberon/default.txt @@ -0,0 +1,77 @@ +MODULE M; +(*a non-nested comment*) +(*a (*nested*) comment*) + + IMPORT Math; + + CONST + (*strings*) + str = "a string"; + null = 0X; + linefeed = 0AX; + + (*integers*) + i1 = 0; + i2 = 12; + i3 = -12; + i4 = 0H; + i5 = 01H; + i6 = 0AH; + i7 = 0A7H; + + (*real numbers*) + r1 = 1.; + r2 = 1.2; + r3 = 1.23; + r4 = 1.E0; + r5 = 1.2E+10; + r6 = 1.23E-10; + + TYPE + T = POINTER TO RECORD END; + + VAR + b: BOOLEAN; + y: BYTE; + ch: CHAR; + i: INTEGER; + r: REAL; + A: SET; + s: ARRAY 32 OF CHAR; + x: T; + + PROCEDURE Func(): INTEGER; + BEGIN + A := {1, 2, 4}; + x := NIL; + s[0] := 0X; + CASE 1 DIV 2 MOD 3 OF 0, 1: END; + FOR i := 0 TO 100 BY 10 DO END; + IF (0 IN {}) OR (x IS T) & TRUE THEN + ELSIF FALSE THEN + ELSE + END; + REPEAT UNTIL TRUE; + WHILE FALSE DO END; + r := ABS(r); + i := ASR(i, 1); + ASSERT(TRUE); + ch := CHR(0); + DEC(i); + EXCL(A, 0); + i := FLOOR(r); + r := FLT(i); + INC(i); + INCL(A, 0); + i := LEN(s); + i := LSL(i, 1); + NEW(x); + b := ODD(i); + i := ORD(ch); + PACK(r, 1); + i := ROR(i, 1); + UNPK(r, i) + RETURN 0 + END Func; + +END M.