Skip to content

Commit

Permalink
a LOT of builtin stuff + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ImShyMike committed Jan 22, 2025
1 parent 3c5f687 commit f1c12af
Show file tree
Hide file tree
Showing 7 changed files with 650 additions and 143 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

Eryx is a decently fast and simple dynamically typed programming language similar to javascript/python.

> Why the name "Eryx"?
> The language was made using python which is [a family of snake](https://en.wikipedia.org/wiki/Pythonidae) and the name eryx is [a snake genus](https://en.wikipedia.org/wiki/Eryx_(snake)).
> Why the name "**Eryx**"?
> <br>The language was made using python which is [a family of snake](https://en.wikipedia.org/wiki/Pythonidae) and the name eryx is [a snake genus](https://en.wikipedia.org/wiki/Eryx_(snake)).
## Documentation

Full documentation is available at [https://ImShyMike.github.io/Eryx](https://ImShyMike.github.io/Eryx).

## Online IDE

An online IDE is hosted at [https://eryx-ide.shymike.tech](https://eryx-ide.shymike.tech). It utilizes the `eryx server` command but has file I/O, input(), exit() and importing disabled (using `--no-file-io`).
An online IDE is hosted at [https://eryx-ide.shymike.tech](https://eryx-ide.shymike.tech). It utilizes the `eryx server` command but has the `os` and `file` modules and `input()` and `exit()` functions disabled (using `--no-file-io`).

## Package Index

Expand Down
119 changes: 86 additions & 33 deletions docs/docs/language-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,96 @@ func add(x, y) {
print(add(1, 2)); # Output: 3
```
There are also many builtin functions:
## Builtin functions
* **print(** ... **)**: Print all values passed to it.
* **input(** text? **)**: Get user input as a string, optionally prompt with a message.
* **len(** item **)**: Get the length of a string, array, or object.
* **exit(** code? **)**: Exit the program, optionally with a status code.
* **str(** value? **)**: Convert a value to its string representation.
* **int(** value? **)**: Convert a value to an integer.
* **bool(** value? **)**: Convert a value to a boolean.
* **array(** ... or string **)**: Create a new array from the given values or turn a string into an array.
* **type(** value **)**: Get the type of the given value.
* **range(** start, end?, step? **)**: Generates an array from start to end with step.
!!! note "Values"
Values containing '?' are optional and '...' refers to any amount of arguments.
* **print(** ... **)**: Print all values passed to it
* **input(** text? **)**: Get user input as a string, optionally prompt with a message
* **len(** item **)**: Get the length of a string, array, or object
* **exit(** code? **)**: Exit the program, optionally with a status code
* **str(** value? **)**: Convert a value to its string representation
* **int(** value? **)**: Convert a value to an integer
* **bool(** value? **)**: Convert a value to a boolean
* **array(** ... or string **)**: Create a new array from the given values or turn a string into an array
* **type(** value **)**: Get the type of the given value
* **range(** start, end?, step? **)**: Generates an array from start to end with step
There are also many builtin modules.
They can be imported using `import` (without ".eryx")
Full list:
* **time**:
* **time()**: Get the current time in seconds since the Epoch
* **math**:
* **sum(** array **)**: Get the sum of an array of numbers
* **round(** number, n? **)**: Round a number to the n'th decimal place (default 0)
* **min(** array **)**: Get the minimum value from an array of numbers
* **max(** array **)**: Get the maximum value from an array of numbers
* **random()**: Get a random number between 0 and 1
* **pi**: The value for pi
* **file**:
* **read(** filename **)**: Read the contents of a file as a string
* **write(** filename, text **)**: Write to a file
* **append(** filename, text **)**: Append to the contents of a file
* **http**: (WIP)
* **get(** url **)**: Send a get request to a URL
* **post(** url, data **)**: Send a post request with JSON data as a string to a URL
## Builtin modules
Builtin modules can be imported using `import` (without ".eryx")
### math
* **log(** x, base? **)**: Get the logarithm of a number with the specified base.
* **sqrt(** x **)**: Get the square root of a number.
* **random()**: Get a random number between 0 and 1.
* **round(** x, digits? **)**: Round a number to the specified number of digits.
* **sum(** array **)**: Get the sum of an array of numbers.
* **min(** array **)**: Get the minimum value in an array of numbers.
* **max(** array **)**: Get the maximum value in an array of numbers.
* **abs(** x **)**: Get the absolute value of a number.
* **pow(** base, exponent **)**: Get the result of raising a base to an exponent.
* **log10(** x **)**: Get the base-10 logarithm of a number.
* **sin(** x **)**: Get the sine of a number.
* **cos(** x **)**: Get the cosine of a number.
* **tan(** x **)**: Get the tangent of a number.
* **asin(** x **)**: Get the arcsine of a number.
* **acos(** x **)**: Get the arccosine of a number.
* **atan(** x **)**: Get the arctangent of a number.
* **floor(** x **)**: Get the largest integer less than or equal to a number.
* **ceil(** x **)**: Get the smallest integer greater than or equal to a number.
* **factorial(** x **)**: Get the factorial of a number.
### file
* **read(** filename **)**: Read the contents of a file.
* **write(** filename, content **)**: Write content to a file.
* **append(** filename, content **)**: Append content to a file.
* **exists(** filename **)**: Check if a file exists.
* **delete(** filename **)**: Delete a file.
* **copy(** source, destination **)**: Copy a file.
* **move(** source, destination **)**: Move a file.
* **list(** directory **)**: List files in a directory.
* **size(** filename **)**: Get the size of a file.
### http
* **get(** url **)**: Make a GET request to a URL.
* **post(** url, data **)**: Make a POST request to a URL with data.
* **put(** url, data **)**: Make a PUT request to a URL with data.
* **delete(** url **)**: Make a DELETE request to a URL.
* **urlencode(** data **)**: URL-encode a string.
* **urldecode(** data **)**: URL-decode a string.
### time
* **time()**: Get the current time in seconds since the epoch.
* **sleep(** seconds **)**: Sleep for a specified number of seconds.
* **format(** time **)**: Format a time value as a string.
* **timezone_offset()**: Get the timezone offset in seconds.
### string
* **split(** string, separator **)**: Split a string by a separator.
* **join(** array, separator **)**: Join an array of strings with a separator.
* **replace(** string, search, replace **)**: Replace occurrences of a substring in a string.
* **contains(** string, search **)**: Check if a string contains a substring.
### array
* **push(** array, value **)**: Add a value to the end of an array.
* **pop(** array **)**: Remove and return the last value from an array.
* **shift(** array **)**: Remove and return the first value from an array.
* **unshift(** array, value **)**: Add a value to the beginning of an array.
* **sort(** array **)**: Sort an array of numbers.
### os
* **cwd()**: Get the current working directory.
* **chdir(** directory **)**: Change the current working directory.
* **env(** variable? **)**: Get the value of an environment variable or all environment variables if no variable is specified.
## Classes
Expand Down
2 changes: 1 addition & 1 deletion eryx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of the package."""

CURRENT_VERSION = "0.3.13"
CURRENT_VERSION = "0.4.0"
2 changes: 1 addition & 1 deletion eryx/frontend/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def tokenize(source_code: str) -> list[Token]:
if src[0] == "-":
if len(src) > 0 and (src[1].isdigit() or src[1].isalpha() or src[1] == "_"):
negative_num = True # Set negative number flag
src.pop(0)
src.pop(0)
else:
# If its not a negative number, its a "-" operator
tokens.append(Token(src.pop(0), TokenType.BINARY_OPERATOR, current_pos))
Expand Down
2 changes: 2 additions & 0 deletions eryx/frontend/syntax_highlighter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Module for lexer based syntax highlighting code."""

# This file is obsolete for now (may be used in the future)

from colorama import Fore, init

from eryx.frontend.lexer import TokenType, tokenize
Expand Down
Loading

0 comments on commit f1c12af

Please sign in to comment.