Skip to content

Commit 1263db4

Browse files
authored
Merge pull request #8 from Vardan2009/master
Added custom syntax highlighting
2 parents 71f6046 + 67ff951 commit 1263db4

16 files changed

+187
-79
lines changed

docs/arrays.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- `arr_slice(array, start, end)` - returns the items from the specified
1313
start index to the specified end index
1414

15-
```py linenums="1" title="methods.rn"
15+
```rn linenums="1" title="methods.rn"
1616
arr = [1, 2, 3, 4, 5]
1717
print(arr_len(arr)) # 5
1818
@@ -39,7 +39,7 @@ print(arr_slice(arr, 0, 5)) # [1, 2, 3, 4, 5]
3939
- `+` (concatenation)
4040
- `*` (repetition)
4141

42-
```py linenums="1" title="operators.rn"
42+
```rn linenums="1" title="operators.rn"
4343
arr1 = [1, 2, 3]
4444
arr2 = [4, 5, 6]
4545
@@ -62,7 +62,7 @@ print(arr1 * 2) # [1, 2, 3, 1, 2, 3]
6262
- `to_string()` - returns the string representation of the array
6363
- `is_array()` - returns `true` if the value is an array, otherwise `false`
6464

65-
```py linenums="1" title="array-standard-library.rn"
65+
```rn linenums="1" title="array-standard-library.rn"
6666
import Array # Include the Array standard library
6767
6868
# Create an array instance using the Array class

docs/assets/radon-highlight.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var script1 = document.createElement('script');
2+
script1.src = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js';
3+
script1.defer = true;
4+
script1.onload = function () {
5+
hljs.registerLanguage('rn', function (hljs) {
6+
return {
7+
contains: [
8+
{
9+
className: 'keyword',
10+
begin: '\\b(class|fun|if|else|true|false|null)\\b'
11+
},
12+
{
13+
className: 'string',
14+
begin: '"', end: '"',
15+
contains: [
16+
{
17+
className: 'escape',
18+
begin: '\\\\.', end: hljs.IMMEDIATE_RE
19+
}
20+
]
21+
},
22+
{
23+
className: 'number',
24+
begin: '\\b\\d+\\b'
25+
},
26+
{
27+
className: 'special',
28+
begin: '(?<=\\b(?:class|import|fun)\\s+)\\w+'
29+
},
30+
{
31+
className: 'special',
32+
begin: '\_\_constructor\_\_|this'
33+
},
34+
{
35+
className: 'fncall',
36+
begin: '(?<=\\b)(\\w+)\\s*\\('
37+
},
38+
{
39+
className: 'fncall',
40+
begin: '(\\)|\\()'
41+
},
42+
{
43+
className: 'comment',
44+
begin: '#',
45+
end: '\\n'
46+
},
47+
{
48+
className: 'identifier',
49+
begin: '(\\w+)'
50+
},
51+
{
52+
className: 'operator',
53+
begin: '(\\+|-|=|!|not|and\\^)'
54+
}
55+
]
56+
};
57+
});
58+
hljs.highlightAll();
59+
};
60+
document.head.appendChild(script1);

docs/classes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Let's start by creating a class. We can create a class using the `class`
1919
keyword. It is followed by the name of the class and the body of the class.
2020
The body of the class is enclosed in curly braces.
2121

22-
```py linenums="1" title="classes.rn"
22+
```rn linenums="1" title="classes.rn"
2323
class Person {
2424
# Class body
2525
}
@@ -31,7 +31,7 @@ Now that we have created a class, we can create an object. We can create an
3131
object by simply calling the class like as a function. It is followed by the
3232
name of the class and the arguments in parentheses. The arguments are optional.
3333

34-
```js linenums="1" title="objects.rn"
34+
```rn linenums="1" title="objects.rn"
3535
person = Person()
3636
```
3737

@@ -43,7 +43,7 @@ to each instance of the class. They are declared using the `var` keyword. It
4343
is followed by the name of the field and the type of the field.
4444
The type of the field is optional.
4545

46-
```js linenums="1" title="fields.rn"
46+
```rn linenums="1" title="fields.rn"
4747
class Person {
4848
name = "John"
4949
age = 20
@@ -57,7 +57,7 @@ class. They are called when an object is created. They are declared using the
5757
`fun` keyword. It is followed by the name (class name) of the constructor and
5858
the parameters in parentheses. The parameters are optional.
5959

60-
```js linenums="1" title="constructors.rn"
60+
```rn linenums="1" title="constructors.rn"
6161
class Person {
6262
fun Person(name, age) {
6363
this.name = name
@@ -75,7 +75,7 @@ define the behavior of the class. They are declared using the `fun` keyword.
7575
It is followed by the name of the method, the parameters in parentheses, and
7676
the return type. The parameters and the return type are optional.
7777

78-
```py linenums="1" title="methods.rn"
78+
```rn linenums="1" title="methods.rn"
7979
class Person {
8080
fun __constructor__(name, age) {
8181
this.name = name

docs/control-flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ statement is used to execute code if the condition is false. The `elif`
88
statement is used to execute code if the condition is false and another
99
condition is true. The `else` statement is optional.
1010

11-
```js linenums="1" title="conditional-statements.rn"
11+
```rn linenums="1" title="conditional-statements.rn"
1212
if true {
1313
print("true")
1414
@@ -17,7 +17,7 @@ if true {
1717
}
1818
```
1919

20-
```js linenums="1" title="conditional-statements.rn"
20+
```rn linenums="1" title="conditional-statements.rn"
2121
if true {
2222
print("true")
2323

docs/data-types.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@ The basic types are:
1414
Arrays are declared using the `[]` syntax. The type of the array is the type
1515
of the elements it contains.
1616

17-
```js linenums="1" title="arrays.rn"
18-
a = [1, 2, 3] // a is an array of ints
19-
b = [1.0, 2.0, 3.0] // b is an array of floats
20-
c = ["a", "b", "c"] // c is an array of strings
17+
```rn linenums="1" title="arrays.rn"
18+
a = [1, 2, 3] # a is an array of ints
19+
b = [1.0, 2.0, 3.0] # b is an array of floats
20+
c = ["a", "b", "c"] # c is an array of strings
2121
22-
// Arrays can be nested
23-
d = [[1, 2], [3, 4]] // d is an array of arrays of ints
22+
# Arrays can be nested
23+
d = [[1, 2], [3, 4]] # d is an array of arrays of ints
2424
25-
// Arrays can be empty
26-
e = [] // e is an empty array of unknown type
25+
# Arrays can be empty
26+
e = [] # e is an empty array of unknown type
2727
```
2828

2929
## Hashmaps
3030

3131
Hashmaps (or objects) are declared using the `{}` syntax.
3232
The type of the object is the type of the fields it contains.
3333

34-
```js linenums="1" title="objects.rn"
35-
// a is an object with fields x and y of type int
34+
```rn linenums="1" title="objects.rn"
35+
# a is an object with fields x and y of type int
3636
a = { x: 1, y: 2 };
37-
// b is an object with fields x and y of type float
37+
# b is an object with fields x and y of type float
3838
b = { x: 1.0, y: 2.0 };
39-
// c is an object with fields x and y of type string
39+
# c is an object with fields x and y of type string
4040
c = { x: "a", y: "b" };
4141
42-
// Objects can be nested
43-
// d is an object with fields x and w of type object
42+
# Objects can be nested
43+
# d is an object with fields x and w of type object
4444
d = { x: { y: 1, z: 2 }, w: { y: 3, z: 4 } };
4545
46-
// Objects can be empty
47-
// e is an empty object of unknown type
46+
# Objects can be empty
47+
# e is an empty object of unknown type
4848
e = {};
4949
```

docs/error-handling.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ In Radon, `try-catch` blocks are used for error handling. The `try` block
1010
contains the code that may throw an exception. The `catch` block contains
1111
the code that handles the exception.
1212

13-
```js linenums="1" title="exceptions.rn"
13+
```rn linenums="1" title="exceptions.rn"
1414
try {
15-
// code that may throw an exception (in this case, zero division)
15+
# code that may throw an exception (in this case, zero division)
1616
a = 1 / 0
1717
} catch as err {
18-
// code that handles the exception
18+
# code that handles the exception
1919
print("Exception caught: " + err)
2020
}
2121
```
@@ -30,12 +30,12 @@ Don't forget to use the `as` keyword to assign the exception to a variable.
3030
The variable can be used to get the exception message. If you don't want to
3131
use the exception message, you can omit the variable.
3232

33-
```js linenums="1" title="exceptions.rn"
33+
```rn linenums="1" title="exceptions.rn"
3434
try {
35-
// code that may throw an exception
35+
# code that may throw an exception
3636
a = 1 / 0
3737
} catch as _ {
38-
// code that handles the exception
38+
# code that handles the exception
3939
print("Exception caught")
4040
}
4141
```
@@ -52,7 +52,7 @@ In Radon, errors can be raised explicitly using the `raise` keyword. This is use
5252

5353
Radon has a standard `radiation` module for Error Types (you can type `radiation.errors` in the shell to view a list of available error types)
5454

55-
```js linenums="1" title="exceptions.rn"
55+
```rn linenums="1" title="exceptions.rn"
5656
import radiation
5757
5858
if 2 != 4 {
@@ -62,7 +62,7 @@ if 2 != 4 {
6262

6363
**Output:**
6464

65-
```py
65+
```rn
6666
Radiation (most recent call last):
6767
File <stdin>, line 2
6868
ValueError: 2 + 2 != 4
@@ -79,7 +79,7 @@ error message.
7979

8080
## Example
8181

82-
```js linenums="1" title="custom-error.rn"
82+
```rn linenums="1" title="custom-error.rn"
8383
fun CustomError(file) {
8484
return "Something went wrong in " + file
8585
}
@@ -89,7 +89,7 @@ raise CustomError("custom-error.rn")
8989

9090
**Output:**
9191

92-
```py
92+
```rn
9393
Radiation (most recent call last):
9494
File <stdin>, line 5
9595
FunctionError: Something went wrong in custom-error.rn

docs/file-handling.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ To manipulate files in Radon, we use built-in `File` class. We can create a new
3838
instance of `File` class by passing the file path to the constructor. We can
3939
then use the `read` method to read the contents of the file.
4040

41-
```py linenums="1" title="file-handling.rn"
41+
```rn linenums="1" title="file-handling.rn"
4242
file = File("file.txt")
4343
content = file.read()
4444
print(content)
4545
```
4646

4747
You can also read the file line by line using the `readline` method.
4848

49-
```py linenums="1" title="file-handling.rn"
49+
```rn linenums="1" title="file-handling.rn"
5050
file = File("file.txt")
5151
line = file.readline()
5252
print(line)
5353
```
5454

5555
You can also read all the lines of the file using the `readlines` method.
5656

57-
```py linenums="1" title="file-handling.rn"
57+
```rn linenums="1" title="file-handling.rn"
5858
file = File("file.txt")
5959
lines = file.readlines()
6060
print(lines)
@@ -65,7 +65,7 @@ print(lines)
6565
To write to a file, we use the `write` method. We can pass the content to the
6666
`write` method to write to the file.
6767

68-
```py linenums="1" title="file-handling.rn"
68+
```rn linenums="1" title="file-handling.rn"
6969
file = File("file.txt")
7070
file.write("Hello, World!")
7171
```
@@ -75,15 +75,15 @@ file.write("Hello, World!")
7575
After reading or writing to a file, it is important to close the file. We can
7676
use the `close` method to close the file.
7777

78-
```py linenums="1" title="file-handling.rn"
78+
```rn linenums="1" title="file-handling.rn"
7979
file = File("file.txt")
8080
# code that reads or writes to the file
8181
file.close()
8282
```
8383

8484
Check the file is closed or not using the `is_closed` method.
8585

86-
```py linenums="1" title="file-handling.rn"
86+
```rn linenums="1" title="file-handling.rn"
8787
file.is_closed()
8888
```
8989

docs/functions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ In Radon, there are three types of functions:
1515

1616
### Named functions
1717

18-
```js linenums="1" title="named_functions.rn"
18+
```rn linenums="1" title="named_functions.rn"
1919
fun add(a, b) {
2020
return a + b
2121
}
2222
```
2323

2424
### Anonymous functions
2525

26-
```js linenums="1" title="anonymous_functions.rn"
26+
```rn linenums="1" title="anonymous_functions.rn"
2727
add = fun (a, b) {
2828
return a + b
2929
}
3030
```
3131

3232
### One-liner functions
3333

34-
```js linenums="1" title="one_liner_functions.rn"
34+
```rn linenums="1" title="one_liner_functions.rn"
3535
fun add(a, b) -> a + b
3636
```
3737

@@ -40,7 +40,7 @@ fun add(a, b) -> a + b
4040
Calling a function is done by using the function name followed by the arguments
4141
in parentheses.
4242

43-
```py linenums="1" title="calling_functions.rn"
43+
```rn linenums="1" title="calling_functions.rn"
4444
add(1, 2) # Output: 3
4545
```
4646

@@ -54,7 +54,7 @@ The parameters are optional.
5454

5555
We can also leave out the parentheses if there are no parameters.
5656

57-
```py linenums="1" title="function_parameters.rn"
57+
```rn linenums="1" title="function_parameters.rn"
5858
fun say_hello(name) {
5959
print("Hello, " + name + "!")
6060
}
@@ -67,7 +67,7 @@ say_hello("World") # Output: Hello, World!
6767
Default parameters are used to assign a default value to a parameter. If the
6868
parameter is not passed, the default value is used.
6969

70-
```py linenums="1" title="default_parameters.rn"
70+
```rn linenums="1" title="default_parameters.rn"
7171
fun new_user(name="Guest") {
7272
print("Hello, " + name + "!")
7373
}

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Some of the features of Radon include:
5656

5757
## Login Logic
5858

59-
```js linenums="1" title="Login.rn"
59+
```rn linenums="1" title="Login.rn"
6060
# This is a Radon test file for the Radon Programming Language.
6161
6262
class Network {

0 commit comments

Comments
 (0)