Initial commit: Oraset programming language with documentation
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
!! DateTime functions module
|
||||
|
||||
def datetime_now() {
|
||||
return time_now();
|
||||
}
|
||||
|
||||
def datetime_sleep(seconds) {
|
||||
return time_sleep(seconds);
|
||||
}
|
||||
|
||||
def datetime_format(timestamp, format) {
|
||||
// This is a placeholder for future implementation
|
||||
// In a real implementation, we would format the timestamp according to the format string
|
||||
return `Format: ${format}, Timestamp: ${timestamp}`;
|
||||
}
|
||||
|
||||
def datetime_parse(date_string, format) {
|
||||
// This is a placeholder for future implementation
|
||||
// In a real implementation, we would parse the date string according to the format string
|
||||
return `Parsed: ${date_string}, Format: ${format}`;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
!! Filesystem functions module
|
||||
|
||||
def filesystem_exists(path) {
|
||||
return file_exists(path);
|
||||
}
|
||||
|
||||
def filesystem_read(path) {
|
||||
return file_read(path);
|
||||
}
|
||||
|
||||
def filesystem_write(path, content) {
|
||||
return file_write(path, content);
|
||||
}
|
||||
|
||||
def filesystem_listdir(path) {
|
||||
// This is a placeholder for future implementation
|
||||
// In a real implementation, we would return a list of files in the directory
|
||||
return `listdir not implemented yet`;
|
||||
}
|
||||
|
||||
def filesystem_mkdir(path) {
|
||||
// This is a placeholder for future implementation
|
||||
// In a real implementation, we would create the directory
|
||||
return `mkdir not implemented yet`;
|
||||
}
|
||||
|
||||
def filesystem_remove(path) {
|
||||
// This is a placeholder for future implementation
|
||||
// In a real implementation, we would remove the file or directory
|
||||
return `remove not implemented yet`;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 数学工具插件
|
||||
|
||||
// 定义一些数学相关的函数
|
||||
def add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
def subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
def multiply(a, b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
def divide(a, b) {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
// 定义一个计算阶乘的函数
|
||||
def factorial(n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
}
|
||||
|
||||
show(`Math utilities module loaded`);
|
||||
@@ -0,0 +1,96 @@
|
||||
!! String manipulation functions module
|
||||
|
||||
import math
|
||||
|
||||
def string_length(s) {
|
||||
return len(s);
|
||||
}
|
||||
|
||||
def string_reverse(s) {
|
||||
let result = ``;
|
||||
let i = len(s);
|
||||
while (i > 0) {
|
||||
i = i - 1;
|
||||
result = result + substring(s, i, i + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
def string_startsWith(s, prefix) {
|
||||
if (len(prefix) > len(s)) {
|
||||
return 0;
|
||||
}
|
||||
return substring(s, 0, len(prefix)) == prefix ? 1 : 0;
|
||||
}
|
||||
|
||||
def string_endsWith(s, suffix) {
|
||||
if (len(suffix) > len(s)) {
|
||||
return 0;
|
||||
}
|
||||
let start = len(s) - len(suffix);
|
||||
return substring(s, start, len(s)) == suffix ? 1 : 0;
|
||||
}
|
||||
|
||||
def string_contains(s, substr) {
|
||||
if (len(substr) == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (len(substr) > len(s)) {
|
||||
return 0;
|
||||
}
|
||||
let i = 0;
|
||||
while (i <= len(s) - len(substr)) {
|
||||
if (substring(s, i, i + len(substr)) == substr) {
|
||||
return 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
def string_replace(s, old, new) {
|
||||
if (len(old) == 0) {
|
||||
return s;
|
||||
}
|
||||
let result = ``;
|
||||
let i = 0;
|
||||
while (i < len(s)) {
|
||||
if (substring(s, i, i + len(old)) == old) {
|
||||
result = result + new;
|
||||
i = i + len(old);
|
||||
} else {
|
||||
result = result + substring(s, i, i + 1);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
def string_toUpperCase(s) {
|
||||
return upper(s);
|
||||
}
|
||||
|
||||
def string_toLowerCase(s) {
|
||||
return lower(s);
|
||||
}
|
||||
|
||||
def string_trim(s) {
|
||||
let start = 0;
|
||||
while (start < len(s) && (substring(s, start, start + 1) == ` ` || substring(s, start, start + 1) == `\t` || substring(s, start, start + 1) == `\n` || substring(s, start, start + 1) == `\r`)) {
|
||||
start = start + 1;
|
||||
}
|
||||
let end = len(s) - 1;
|
||||
while (end >= start && (substring(s, end, end + 1) == ` ` || substring(s, end, end + 1) == `\t` || substring(s, end, end + 1) == `\n` || substring(s, end, end + 1) == `\r`)) {
|
||||
end = end - 1;
|
||||
}
|
||||
if (start > end) {
|
||||
return ``;
|
||||
}
|
||||
return substring(s, start, end + 1);
|
||||
}
|
||||
|
||||
def string_split(s, delimiter) {
|
||||
// This is a placeholder for future implementation
|
||||
// In a real implementation, we would return an array
|
||||
return `split not implemented yet`;
|
||||
}
|
||||
Reference in New Issue
Block a user