-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide highlighting of Oberon source code
This supports highlighting for the final revision of the original Oberon language from 2016 (also called Oberon-07) as defined by the Oberon report https://miasap.se/obnc/oberon-report.html
- Loading branch information
1 parent
62f8a60
commit 9bce502
Showing
5 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
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,64 @@ | ||
/* | ||
Language: Oberon | ||
Description: Syntax highlighting for the final version of Oberon (also known as Oberon-07) | ||
Author: Karl Landstrom <[email protected]> | ||
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 | ||
] | ||
}; | ||
} |
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,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. |
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,77 @@ | ||
<span class="hljs-keyword">MODULE</span> <span class="hljs-title">M</span>; | ||
<span class="hljs-comment">(*a non-nested comment*)</span> | ||
<span class="hljs-comment">(*a <span class="hljs-comment">(*nested*)</span> comment*)</span> | ||
|
||
<span class="hljs-keyword">IMPORT</span> Math; | ||
|
||
<span class="hljs-keyword">CONST</span> | ||
<span class="hljs-comment">(*strings*)</span> | ||
str = <span class="hljs-string">"a string"</span>; | ||
null = <span class="hljs-string">0X</span>; | ||
linefeed = <span class="hljs-string">0AX</span>; | ||
|
||
<span class="hljs-comment">(*integers*)</span> | ||
i1 = <span class="hljs-number">0</span>; | ||
i2 = <span class="hljs-number">12</span>; | ||
i3 = -<span class="hljs-number">12</span>; | ||
i4 = <span class="hljs-number">0H</span>; | ||
i5 = <span class="hljs-number">01H</span>; | ||
i6 = <span class="hljs-number">0AH</span>; | ||
i7 = <span class="hljs-number">0A7H</span>; | ||
|
||
<span class="hljs-comment">(*real numbers*)</span> | ||
r1 = <span class="hljs-number">1.</span>; | ||
r2 = <span class="hljs-number">1.2</span>; | ||
r3 = <span class="hljs-number">1.23</span>; | ||
r4 = <span class="hljs-number">1.E0</span>; | ||
r5 = <span class="hljs-number">1.2E+10</span>; | ||
r6 = <span class="hljs-number">1.23E-10</span>; | ||
|
||
<span class="hljs-keyword">TYPE</span> | ||
T = <span class="hljs-keyword">POINTER</span> <span class="hljs-keyword">TO</span> <span class="hljs-keyword">RECORD</span> <span class="hljs-keyword">END</span>; | ||
|
||
<span class="hljs-keyword">VAR</span> | ||
b: <span class="hljs-type">BOOLEAN</span>; | ||
y: <span class="hljs-type">BYTE</span>; | ||
ch: <span class="hljs-type">CHAR</span>; | ||
i: <span class="hljs-type">INTEGER</span>; | ||
r: <span class="hljs-type">REAL</span>; | ||
A: <span class="hljs-type">SET</span>; | ||
s: <span class="hljs-keyword">ARRAY</span> <span class="hljs-number">32</span> <span class="hljs-keyword">OF</span> <span class="hljs-type">CHAR</span>; | ||
x: T; | ||
|
||
<span class="hljs-keyword">PROCEDURE</span> <span class="hljs-title">Func</span>(): <span class="hljs-type">INTEGER</span>; | ||
<span class="hljs-keyword">BEGIN</span> | ||
A := {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>}; | ||
x := <span class="hljs-keyword">NIL</span>; | ||
s[<span class="hljs-number">0</span>] := <span class="hljs-string">0X</span>; | ||
<span class="hljs-keyword">CASE</span> <span class="hljs-number">1</span> <span class="hljs-keyword">DIV</span> <span class="hljs-number">2</span> <span class="hljs-keyword">MOD</span> <span class="hljs-number">3</span> <span class="hljs-keyword">OF</span> <span class="hljs-number">0</span>, <span class="hljs-number">1</span>: <span class="hljs-keyword">END</span>; | ||
<span class="hljs-keyword">FOR</span> i := <span class="hljs-number">0</span> <span class="hljs-keyword">TO</span> <span class="hljs-number">100</span> <span class="hljs-keyword">BY</span> <span class="hljs-number">10</span> <span class="hljs-keyword">DO</span> <span class="hljs-keyword">END</span>; | ||
<span class="hljs-keyword">IF</span> (<span class="hljs-number">0</span> <span class="hljs-keyword">IN</span> {}) <span class="hljs-keyword">OR</span> (x <span class="hljs-keyword">IS</span> T) & <span class="hljs-keyword">TRUE</span> <span class="hljs-keyword">THEN</span> | ||
<span class="hljs-keyword">ELSIF</span> <span class="hljs-keyword">FALSE</span> <span class="hljs-keyword">THEN</span> | ||
<span class="hljs-keyword">ELSE</span> | ||
<span class="hljs-keyword">END</span>; | ||
<span class="hljs-keyword">REPEAT</span> <span class="hljs-keyword">UNTIL</span> <span class="hljs-keyword">TRUE</span>; | ||
<span class="hljs-keyword">WHILE</span> <span class="hljs-keyword">FALSE</span> <span class="hljs-keyword">DO</span> <span class="hljs-keyword">END</span>; | ||
r := <span class="hljs-built_in">ABS</span>(r); | ||
i := <span class="hljs-built_in">ASR</span>(i, <span class="hljs-number">1</span>); | ||
<span class="hljs-built_in">ASSERT</span>(<span class="hljs-keyword">TRUE</span>); | ||
ch := <span class="hljs-built_in">CHR</span>(<span class="hljs-number">0</span>); | ||
<span class="hljs-built_in">DEC</span>(i); | ||
<span class="hljs-built_in">EXCL</span>(A, <span class="hljs-number">0</span>); | ||
i := <span class="hljs-built_in">FLOOR</span>(r); | ||
r := <span class="hljs-built_in">FLT</span>(i); | ||
<span class="hljs-built_in">INC</span>(i); | ||
<span class="hljs-built_in">INCL</span>(A, <span class="hljs-number">0</span>); | ||
i := <span class="hljs-built_in">LEN</span>(s); | ||
i := <span class="hljs-built_in">LSL</span>(i, <span class="hljs-number">1</span>); | ||
<span class="hljs-built_in">NEW</span>(x); | ||
b := <span class="hljs-built_in">ODD</span>(i); | ||
i := <span class="hljs-built_in">ORD</span>(ch); | ||
<span class="hljs-built_in">PACK</span>(r, <span class="hljs-number">1</span>); | ||
i := <span class="hljs-built_in">ROR</span>(i, <span class="hljs-number">1</span>); | ||
<span class="hljs-built_in">UNPK</span>(r, i) | ||
<span class="hljs-keyword">RETURN</span> <span class="hljs-number">0</span> | ||
<span class="hljs-keyword">END</span> Func; | ||
|
||
<span class="hljs-keyword">END</span> M. |
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,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. |