diff --git a/docs/arrays.md b/docs/arrays.md index 7ead592..357e2ee 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -12,7 +12,7 @@ - `arr_slice(array, start, end)` - returns the items from the specified start index to the specified end index -```py linenums="1" title="methods.rn" +```rn linenums="1" title="methods.rn" arr = [1, 2, 3, 4, 5] print(arr_len(arr)) # 5 @@ -39,7 +39,7 @@ print(arr_slice(arr, 0, 5)) # [1, 2, 3, 4, 5] - `+` (concatenation) - `*` (repetition) -```py linenums="1" title="operators.rn" +```rn linenums="1" title="operators.rn" arr1 = [1, 2, 3] arr2 = [4, 5, 6] @@ -62,7 +62,7 @@ print(arr1 * 2) # [1, 2, 3, 1, 2, 3] - `to_string()` - returns the string representation of the array - `is_array()` - returns `true` if the value is an array, otherwise `false` -```py linenums="1" title="array-standard-library.rn" +```rn linenums="1" title="array-standard-library.rn" import Array # Include the Array standard library # Create an array instance using the Array class diff --git a/docs/assets/radon-highlight.js b/docs/assets/radon-highlight.js new file mode 100644 index 0000000..6800dad --- /dev/null +++ b/docs/assets/radon-highlight.js @@ -0,0 +1,60 @@ +var script1 = document.createElement('script'); +script1.src = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/highlight.min.js'; +script1.defer = true; +script1.onload = function () { + hljs.registerLanguage('rn', function (hljs) { + return { + contains: [ + { + className: 'keyword', + begin: '\\b(class|fun|if|else|true|false|null)\\b' + }, + { + className: 'string', + begin: '"', end: '"', + contains: [ + { + className: 'escape', + begin: '\\\\.', end: hljs.IMMEDIATE_RE + } + ] + }, + { + className: 'number', + begin: '\\b\\d+\\b' + }, + { + className: 'special', + begin: '(?<=\\b(?:class|import|fun)\\s+)\\w+' + }, + { + className: 'special', + begin: '\_\_constructor\_\_|this' + }, + { + className: 'fncall', + begin: '(?<=\\b)(\\w+)\\s*\\(' + }, + { + className: 'fncall', + begin: '(\\)|\\()' + }, + { + className: 'comment', + begin: '#', + end: '\\n' + }, + { + className: 'identifier', + begin: '(\\w+)' + }, + { + className: 'operator', + begin: '(\\+|-|=|!|not|and\\^)' + } + ] + }; + }); + hljs.highlightAll(); +}; +document.head.appendChild(script1); \ No newline at end of file diff --git a/docs/classes.md b/docs/classes.md index 97b6fde..2dc9178 100644 --- a/docs/classes.md +++ b/docs/classes.md @@ -19,7 +19,7 @@ Let's start by creating a class. We can create a class using the `class` keyword. It is followed by the name of the class and the body of the class. The body of the class is enclosed in curly braces. -```py linenums="1" title="classes.rn" +```rn linenums="1" title="classes.rn" class Person { # Class body } @@ -31,7 +31,7 @@ Now that we have created a class, we can create an object. We can create an object by simply calling the class like as a function. It is followed by the name of the class and the arguments in parentheses. The arguments are optional. -```js linenums="1" title="objects.rn" +```rn linenums="1" title="objects.rn" person = Person() ``` @@ -43,7 +43,7 @@ to each instance of the class. They are declared using the `var` keyword. It is followed by the name of the field and the type of the field. The type of the field is optional. -```js linenums="1" title="fields.rn" +```rn linenums="1" title="fields.rn" class Person { name = "John" age = 20 @@ -57,7 +57,7 @@ class. They are called when an object is created. They are declared using the `fun` keyword. It is followed by the name (class name) of the constructor and the parameters in parentheses. The parameters are optional. -```js linenums="1" title="constructors.rn" +```rn linenums="1" title="constructors.rn" class Person { fun Person(name, age) { this.name = name @@ -75,7 +75,7 @@ define the behavior of the class. They are declared using the `fun` keyword. It is followed by the name of the method, the parameters in parentheses, and the return type. The parameters and the return type are optional. -```py linenums="1" title="methods.rn" +```rn linenums="1" title="methods.rn" class Person { fun __constructor__(name, age) { this.name = name diff --git a/docs/control-flow.md b/docs/control-flow.md index 4422509..49eec55 100644 --- a/docs/control-flow.md +++ b/docs/control-flow.md @@ -8,7 +8,7 @@ statement is used to execute code if the condition is false. The `elif` statement is used to execute code if the condition is false and another condition is true. The `else` statement is optional. -```js linenums="1" title="conditional-statements.rn" +```rn linenums="1" title="conditional-statements.rn" if true { print("true") @@ -17,7 +17,7 @@ if true { } ``` -```js linenums="1" title="conditional-statements.rn" +```rn linenums="1" title="conditional-statements.rn" if true { print("true") diff --git a/docs/data-types.md b/docs/data-types.md index 61a3938..8d23eaa 100644 --- a/docs/data-types.md +++ b/docs/data-types.md @@ -14,16 +14,16 @@ The basic types are: Arrays are declared using the `[]` syntax. The type of the array is the type of the elements it contains. -```js linenums="1" title="arrays.rn" -a = [1, 2, 3] // a is an array of ints -b = [1.0, 2.0, 3.0] // b is an array of floats -c = ["a", "b", "c"] // c is an array of strings +```rn linenums="1" title="arrays.rn" +a = [1, 2, 3] # a is an array of ints +b = [1.0, 2.0, 3.0] # b is an array of floats +c = ["a", "b", "c"] # c is an array of strings -// Arrays can be nested -d = [[1, 2], [3, 4]] // d is an array of arrays of ints +# Arrays can be nested +d = [[1, 2], [3, 4]] # d is an array of arrays of ints -// Arrays can be empty -e = [] // e is an empty array of unknown type +# Arrays can be empty +e = [] # e is an empty array of unknown type ``` ## Hashmaps @@ -31,19 +31,19 @@ e = [] // e is an empty array of unknown type Hashmaps (or objects) are declared using the `{}` syntax. The type of the object is the type of the fields it contains. -```js linenums="1" title="objects.rn" -// a is an object with fields x and y of type int +```rn linenums="1" title="objects.rn" +# a is an object with fields x and y of type int a = { x: 1, y: 2 }; -// b is an object with fields x and y of type float +# b is an object with fields x and y of type float b = { x: 1.0, y: 2.0 }; -// c is an object with fields x and y of type string +# c is an object with fields x and y of type string c = { x: "a", y: "b" }; -// Objects can be nested -// d is an object with fields x and w of type object +# Objects can be nested +# d is an object with fields x and w of type object d = { x: { y: 1, z: 2 }, w: { y: 3, z: 4 } }; -// Objects can be empty -// e is an empty object of unknown type +# Objects can be empty +# e is an empty object of unknown type e = {}; ``` diff --git a/docs/error-handling.md b/docs/error-handling.md index 01b6a8a..1d41433 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -10,12 +10,12 @@ In Radon, `try-catch` blocks are used for error handling. The `try` block contains the code that may throw an exception. The `catch` block contains the code that handles the exception. -```js linenums="1" title="exceptions.rn" +```rn linenums="1" title="exceptions.rn" try { - // code that may throw an exception (in this case, zero division) + # code that may throw an exception (in this case, zero division) a = 1 / 0 } catch as err { - // code that handles the exception + # code that handles the exception print("Exception caught: " + err) } ``` @@ -30,12 +30,12 @@ Don't forget to use the `as` keyword to assign the exception to a variable. The variable can be used to get the exception message. If you don't want to use the exception message, you can omit the variable. -```js linenums="1" title="exceptions.rn" +```rn linenums="1" title="exceptions.rn" try { - // code that may throw an exception + # code that may throw an exception a = 1 / 0 } catch as _ { - // code that handles the exception + # code that handles the exception print("Exception caught") } ``` @@ -52,7 +52,7 @@ In Radon, errors can be raised explicitly using the `raise` keyword. This is use 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) -```js linenums="1" title="exceptions.rn" +```rn linenums="1" title="exceptions.rn" import radiation if 2 != 4 { @@ -62,7 +62,7 @@ if 2 != 4 { **Output:** -```py +```rn Radiation (most recent call last): File , line 2 ValueError: 2 + 2 != 4 @@ -79,7 +79,7 @@ error message. ## Example -```js linenums="1" title="custom-error.rn" +```rn linenums="1" title="custom-error.rn" fun CustomError(file) { return "Something went wrong in " + file } @@ -89,7 +89,7 @@ raise CustomError("custom-error.rn") **Output:** -```py +```rn Radiation (most recent call last): File , line 5 FunctionError: Something went wrong in custom-error.rn diff --git a/docs/file-handling.md b/docs/file-handling.md index 5da802b..b53ff5b 100644 --- a/docs/file-handling.md +++ b/docs/file-handling.md @@ -38,7 +38,7 @@ To manipulate files in Radon, we use built-in `File` class. We can create a new instance of `File` class by passing the file path to the constructor. We can then use the `read` method to read the contents of the file. -```py linenums="1" title="file-handling.rn" +```rn linenums="1" title="file-handling.rn" file = File("file.txt") content = file.read() print(content) @@ -46,7 +46,7 @@ print(content) You can also read the file line by line using the `readline` method. -```py linenums="1" title="file-handling.rn" +```rn linenums="1" title="file-handling.rn" file = File("file.txt") line = file.readline() print(line) @@ -54,7 +54,7 @@ print(line) You can also read all the lines of the file using the `readlines` method. -```py linenums="1" title="file-handling.rn" +```rn linenums="1" title="file-handling.rn" file = File("file.txt") lines = file.readlines() print(lines) @@ -65,7 +65,7 @@ print(lines) To write to a file, we use the `write` method. We can pass the content to the `write` method to write to the file. -```py linenums="1" title="file-handling.rn" +```rn linenums="1" title="file-handling.rn" file = File("file.txt") file.write("Hello, World!") ``` @@ -75,7 +75,7 @@ file.write("Hello, World!") After reading or writing to a file, it is important to close the file. We can use the `close` method to close the file. -```py linenums="1" title="file-handling.rn" +```rn linenums="1" title="file-handling.rn" file = File("file.txt") # code that reads or writes to the file file.close() @@ -83,7 +83,7 @@ file.close() Check the file is closed or not using the `is_closed` method. -```py linenums="1" title="file-handling.rn" +```rn linenums="1" title="file-handling.rn" file.is_closed() ``` diff --git a/docs/functions.md b/docs/functions.md index 043f93d..f726af8 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -15,7 +15,7 @@ In Radon, there are three types of functions: ### Named functions -```js linenums="1" title="named_functions.rn" +```rn linenums="1" title="named_functions.rn" fun add(a, b) { return a + b } @@ -23,7 +23,7 @@ fun add(a, b) { ### Anonymous functions -```js linenums="1" title="anonymous_functions.rn" +```rn linenums="1" title="anonymous_functions.rn" add = fun (a, b) { return a + b } @@ -31,7 +31,7 @@ add = fun (a, b) { ### One-liner functions -```js linenums="1" title="one_liner_functions.rn" +```rn linenums="1" title="one_liner_functions.rn" fun add(a, b) -> a + b ``` @@ -40,7 +40,7 @@ fun add(a, b) -> a + b Calling a function is done by using the function name followed by the arguments in parentheses. -```py linenums="1" title="calling_functions.rn" +```rn linenums="1" title="calling_functions.rn" add(1, 2) # Output: 3 ``` @@ -54,7 +54,7 @@ The parameters are optional. We can also leave out the parentheses if there are no parameters. -```py linenums="1" title="function_parameters.rn" +```rn linenums="1" title="function_parameters.rn" fun say_hello(name) { print("Hello, " + name + "!") } @@ -67,7 +67,7 @@ say_hello("World") # Output: Hello, World! Default parameters are used to assign a default value to a parameter. If the parameter is not passed, the default value is used. -```py linenums="1" title="default_parameters.rn" +```rn linenums="1" title="default_parameters.rn" fun new_user(name="Guest") { print("Hello, " + name + "!") } diff --git a/docs/index.md b/docs/index.md index 034bb6e..32e16b8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -56,7 +56,7 @@ Some of the features of Radon include: ## Login Logic -```js linenums="1" title="Login.rn" +```rn linenums="1" title="Login.rn" # This is a Radon test file for the Radon Programming Language. class Network { diff --git a/docs/input-output.md b/docs/input-output.md index 40222d3..058648b 100644 --- a/docs/input-output.md +++ b/docs/input-output.md @@ -6,7 +6,7 @@ In Radon, we can print to the console using the `print` function. It is followed by the argument in parentheses. The argument are mandatory. It takes only one argument. We can concatenate data types using the `+` operator. -```py linenums="1" title="print.rn" +```rn linenums="1" title="print.rn" print("Hello" + ", " + "World!") # Output: Hello, World! ``` @@ -16,7 +16,7 @@ In Radon, we can take input from the console using the `input` function. It is followed by the argument in parentheses. The argument are mandatory. It takes only one argument. We can concatenate data types using the `+` operator. -```py linenums="1" title="input.rn" +```rn linenums="1" title="input.rn" name = input("Enter your name: ") print("Hello, " + name + "!") # Output: Hello, World! ``` diff --git a/docs/loops.md b/docs/loops.md index 98da8a3..59e8f6f 100644 --- a/docs/loops.md +++ b/docs/loops.md @@ -21,7 +21,7 @@ In for loop we have 2 varients. With range we can specify the start, end and step value. If step value is not provided then it will be 1. -```py +```rn linenums="1" title="for.rn" for i=0 to 10 { print(i) } @@ -29,7 +29,7 @@ for i=0 to 10 { **Output:** -```py +```bash 0 1 2 @@ -44,7 +44,7 @@ for i=0 to 10 { With step value. Here we are printing the even numbers. -```py +```rn linenums="1" title="for_step.rn" for i=0 to 10 step 2 { print(i) } @@ -52,7 +52,7 @@ for i=0 to 10 step 2 { **Output:** -```py +```bash 0 2 4 @@ -68,7 +68,7 @@ The loop will run for each element. Here we are using `Array` of elements. The loop will run for each element in the `Array`. -```py +```rn linenums="1" title="for_array.rn" for i in [1, 2, 3, 4, 5] { print(i) } @@ -76,7 +76,7 @@ for i in [1, 2, 3, 4, 5] { **Output** -```py +```bash 1 2 3 @@ -86,7 +86,7 @@ for i in [1, 2, 3, 4, 5] { Here we are using `String`. The loop will run for each character in the `String`. -```py +```rn linenums="1" title="for_string.rn" for i in "Hello" { print(i) } @@ -94,7 +94,7 @@ for i in "Hello" { **Output:** -```py +```bash H e l @@ -104,7 +104,7 @@ o Here we are using `HashMap`. The loop will run for each key in the `HashMap`. -```py +```rn linenums="1" title="for_hashmap.rn" hash = {"name": "John", "age": 30} for i in hash { print("Key: " + i) @@ -114,7 +114,7 @@ for i in hash { **Output:** -```py +```bash Key: name Value: John Key: age @@ -126,7 +126,7 @@ Value: 30 With while loop we can specify the condition. The loop will run until the condition is true. -```py +```rn linenums="1" title="while.rn" i = 0 while i < 5 { print(i) @@ -136,7 +136,7 @@ while i < 5 { **Output:** -```py +```bash 0 1 2 @@ -160,7 +160,7 @@ With `break` we can exit the loop. For loop example: -```py +```rn linenums="1" title="for_break.rn" for i=0 to 10 { if i == 5 { break @@ -171,7 +171,7 @@ for i=0 to 10 { **Output:** -```py +```bash 0 1 2 @@ -181,7 +181,7 @@ for i=0 to 10 { While loop example: -```py +```rn linenums="1" title="while_break.rn" i = 0 while i < 10 { if i == 5 { @@ -194,7 +194,7 @@ while i < 10 { **Output:** -```py +```bash 0 1 2 @@ -208,7 +208,7 @@ With `continue` we can skip the current iteration and move to the next iteration For loop example: -```py +```rn linenums="1" title="for_continue.rn" for i=0 to 5 { if i == 3 { continue @@ -219,7 +219,7 @@ for i=0 to 5 { **Output:** -```py +```bash 0 1 2 @@ -228,7 +228,7 @@ for i=0 to 5 { While loop example: -```py +```rn linenums="1" title="while_continue.rn" i = 0 while i < 5 { if i == 3 { @@ -242,7 +242,7 @@ while i < 5 { **Output:** -```py +```bash 0 1 2 diff --git a/docs/modules.md b/docs/modules.md index 68b5dff..fa7d654 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -16,7 +16,7 @@ is the name of the module. The name should have to be in Pascal Case `PascalCase The module have to implement the same name class as the file name. The class name should have to be in Pascal Case `PascalCase`. -```py linenums="1" title="Hello.rn" +```rn linenums="1" title="Hello.rn" class Hello { fun __constructor__() { print("Hello, World!") @@ -29,6 +29,6 @@ class Hello { A module is imported by using the `include` keyword. It is followed by the name of the module. The name of the module should have to be in Pascal Case `PascalCase`. -```py linenums="1" title="importing.rn" +```rn linenums="1" title="main.rn" import Hello ``` diff --git a/docs/quick-start.md b/docs/quick-start.md index 93c182a..43e7d77 100644 --- a/docs/quick-start.md +++ b/docs/quick-start.md @@ -18,6 +18,6 @@ The first program that most people write in a new language is the "Hello World" program. This program simply prints the words "Hello World" to the screen. Here is the "Hello World" program in Radon: -```py linenums="1" title="HelloWorld.rn" +```rn linenums="1" title="hello_world.rn" print("Hello World") ``` diff --git a/docs/strings.md b/docs/strings.md index 1073073..5b7deac 100644 --- a/docs/strings.md +++ b/docs/strings.md @@ -7,7 +7,7 @@ - `str_slice(string, start, end)` - returns the substring from the specified start index to the specified end index -```py linenums="1" title="methods.rn" +```rn linenums="1" title="methods.rn" str = "Hello, World!" print(str_len(str)) # 13 @@ -22,7 +22,7 @@ print(str_slice(str, 0, 5)) # Hello - `+` (concatenation) - `*` (repetition) -```py linenums="1" title="operators.rn" +```rn linenums="1" title="operators.rn" str = "Hello, World!" print(str + " " + "Hello, World!") # Hello, World! Hello, World! @@ -33,7 +33,7 @@ print(str * 2) # Hello, World!Hello, World! - `str()` - converts any value to a string -```py linenums="1" title="casting.rn" +```rn linenums="1" title="casting.rn" print(str(123)) # 123 print(str(123.456)) # 123.456 print(str(true)) # true @@ -44,7 +44,7 @@ print(str(false)) # false - `is_str()` - returns `true` if the value is a string, otherwise `false` -```py linenums="1" title="type-checking.rn" +```rn linenums="1" title="typechecks.rn" print(is_str("Hello, World!")) # true print(is_str(123)) # false print(is_str(123.456)) # false diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index e69de29..16deb93 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -0,0 +1,43 @@ +.hljs-keyword { + color: #007acc; + /* Brighter shade for keywords */ + font-style: italic; +} + +.hljs-string { + color: #d14; +} + +.hljs-number { + color: #c92c2c; +} + +.hljs-comment { + color: #6a737d; + /* Softer gray for comments */ + font-style: italic; +} + +.hljs-function { + color: #795da3; + font-weight: bold; +} + +.hljs-identifier { + color: #2a7bde; +} + +.hljs-operator { + color: #8b7f7f; + font-weight: bold; +} + +.hljs-special { + color: rgb(255, 187, 0); + font-weight: bold; +} + +.hljs-fncall { + color: #1c92d2; + font-weight: bold; +} \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index fa7315a..1e175e9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -100,6 +100,12 @@ copyright: Build with love for the community © 2023-2024 plugins: - search +extra_javascript: + - 'assets/radon-highlight.js' + +extra_css: + - 'assets/extra.css' + nav: - Overview: index.md - Installation: installation.md @@ -145,7 +151,6 @@ markdown_extensions: - pymdownx.highlight: anchor_linenums: true - line_spans: __span pygments_lang_class: true - pymdownx.inlinehilite - pymdownx.snippets