Oraset B-5: Clean repository with only C implementation
Build and Package Oraset / build (macos-latest) (push) Waiting to run
Build and Package Oraset / build (ubuntu-latest) (push) Waiting to run
Build and Package Oraset / build (windows-latest) (push) Waiting to run
Build and Package Oraset / release (push) Blocked by required conditions

This commit is contained in:
JGZ_YES
2026-07-23 13:27:04 +08:00
commit c30eb9b7ad
121 changed files with 33672 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
// 简化版文档列表 API
header('Content-Type: application/json; charset=utf-8');
// 禁用缓存
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
$md_dir = dirname(__FILE__) . '/md';
$version_file = dirname(dirname(__FILE__)) . '/download/version.txt';
// 获取版本号
$current_version = '4.0.1-BetaN(+AU)';
if (file_exists($version_file)) {
$current_version = trim(file_get_contents($version_file));
}
// 获取所有 md 文件
$articles = array();
if (is_dir($md_dir)) {
$files = glob($md_dir . '/*.md');
if ($files !== false) {
foreach ($files as $file) {
$name = basename($file, '.md');
$content = @file_get_contents($file);
$title = $name;
if ($content && preg_match('/^# (.+)$/m', $content, $matches)) {
$title = $matches[1];
}
$articles[] = array(
'name' => $name,
'title' => $title,
'desc' => ''
);
}
}
}
// 输出 JSON
echo json_encode(array(
'version' => $current_version,
'articles' => $articles
));
?>
+377
View File
@@ -0,0 +1,377 @@
<?php
/**
* Oraset 文档系统
* 自动识别 md 文件夹下的 md 文件并显示
* 支持 HTML 和 Markdown 语法
*
* 使用方式:
* index.php - 显示第一个可用文档
* index.php?doc=name - 显示指定文档
* index.php?list - 列出所有文档
* index.php?list-api - 输出 JSON 格式的文档列表
*/
// 配置
$md_dir = __DIR__ . '/md';
$css_path = '../css/style.css';
$version_file = dirname(__DIR__) . '/download/version.txt';
// 获取版本号
function get_version($version_file) {
if (file_exists($version_file)) {
return trim(file_get_contents($version_file));
}
return '4.0.1-BetaN(+AU)';
}
$current_version = get_version($version_file);
// 获取所有 md 文件列表
function get_articles_list($md_dir) {
$articles = [];
$files = glob($md_dir . '/*.md');
foreach ($files as $file) {
$name = basename($file, '.md');
$content = file_get_contents($file);
// 提取标题
$title = $name;
if (preg_match('/^# (.+)$/m', $content, $matches)) {
$title = $matches[1];
}
// 提取描述(第一段非标题、非代码块、非列表的内容)
$desc = '';
$lines = explode("\n", $content);
$in_code = false;
foreach ($lines as $line) {
$trimmed = trim($line);
// 跳过代码块
if (strpos($trimmed, '```') !== false) {
$in_code = !$in_code;
continue;
}
if ($in_code) {
continue;
}
// 跳过空行、标题、列表、太短的行
if ($trimmed === '' ||
preg_match('/^#/', $trimmed) ||
preg_match('/^-/', $trimmed) ||
strlen($trimmed) < 10) {
continue;
}
// 找到第一个有效描述,去除Markdown语法
$desc = $trimmed;
// 去除链接语法
$desc = preg_replace('/\[([^\]]+)\]\([^)]+\)/', '$1', $desc);
// 去除粗体/斜体
$desc = preg_replace('/\*+([^*]+)\*+/', '$1', $desc);
// 去除行内代码
$desc = preg_replace('/`([^`]+)`/', '$1', $desc);
if (strlen($desc) > 100) {
$desc = substr($desc, 0, 100) . '...';
}
break;
}
$articles[] = [
'name' => $name,
'title' => $title,
'desc' => $desc,
'file' => $file
];
}
return $articles;
}
// JSON API 模式
if (isset($_GET['list-api'])) {
header('Content-Type: application/json; charset=utf-8');
$articles = get_articles_list($md_dir);
echo json_encode([
'version' => $current_version,
'articles' => $articles
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
exit;
}
// Markdown 解析函数(改进版)
function parse_markdown($text, $version) {
// 替换版本号占位符
$text = str_replace('{{VERSION}}', $version, $text);
// 处理代码块(先处理,避免被其他规则干扰)
$text = preg_replace_callback('/```(\w*)\n(.*?)```/s', function($m) {
$lang = $m[1] ? ' class="language-' . htmlspecialchars($m[1]) . '"' : '';
return '<pre><code' . $lang . '>' . htmlspecialchars($m[2]) . '</code></pre>';
}, $text);
// 处理行内代码
$text = preg_replace('/`([^`]+)`/', '<code>$1</code>', $text);
// 处理标题
$text = preg_replace('/^### (.+)$/m', '<h3>$1</h3>', $text);
$text = preg_replace('/^## (.+)$/m', '<h2>$1</h2>', $text);
$text = preg_replace('/^# (.+)$/m', '<h1>$1</h1>', $text);
// 处理粗体和斜体
$text = preg_replace('/\*\*([^*]+)\*\*/', '<strong>$1</strong>', $text);
$text = preg_replace('/\*([^*]+)\*/', '<em>$1</em>', $text);
// 处理链接(支持 URL 中包含括号)
$text = preg_replace_callback('/\[([^\]]+)\]\(\s*([^)]*(?:\([^)]*\)[^)]*)*)\s*\)/', function($m) {
$link_text = $m[1];
$url = trim($m[2]);
return '<a href="' . htmlspecialchars($url, ENT_QUOTES, 'UTF-8') . '">' . $link_text . '</a>';
}, $text);
// 处理分隔线
$text = preg_replace('/^---$/m', '<hr>', $text);
// 处理无序列表
$lines = explode("\n", $text);
$result = [];
$in_list = false;
$in_code = false;
$in_paragraph = false;
foreach ($lines as $line) {
$trimmed = trim($line);
// 检查是否在代码块中
if (strpos($trimmed, '<pre>') !== false) {
$in_code = true;
}
if (strpos($trimmed, '</pre>') !== false) {
$in_code = false;
}
if ($in_code) {
$result[] = $line;
continue;
}
// 处理列表项
if (preg_match('/^- (.+)$/', $trimmed, $m)) {
if (!$in_list) {
$result[] = '<ul>';
$in_list = true;
}
$result[] = '<li>' . $m[1] . '</li>';
continue;
}
// 结束列表
if ($in_list && !preg_match('/^-/', $trimmed)) {
$result[] = '</ul>';
$in_list = false;
}
// 处理块元素(标题、hr、pre等)
if (preg_match('/^<(h[1-6]|hr|pre|ul|li)/', $trimmed) || $trimmed === '') {
if ($in_paragraph) {
$result[] = '</p>';
$in_paragraph = false;
}
$result[] = $line;
continue;
}
// 处理段落
if (!$in_paragraph && $trimmed !== '') {
$result[] = '<p>' . $trimmed;
$in_paragraph = true;
} else if ($in_paragraph && $trimmed !== '') {
$result[] = $trimmed;
}
}
// 结束未闭合的标签
if ($in_list) {
$result[] = '</ul>';
}
if ($in_paragraph) {
$result[] = '</p>';
}
return implode("\n", $result);
}
// 获取文章列表
$articles = get_articles_list($md_dir);
// 判断是否显示列表模式
$show_list = isset($_GET['list']);
// 获取请求的文档
$doc = isset($_GET['doc']) ? $_GET['doc'] : '';
// 安全处理:只允许字母、数字、下划线、连字符
$doc = preg_replace('/[^a-zA-Z0-9_-]/', '', $doc);
// 文件路径
$file_path = '';
if ($doc !== '') {
$file_path = $md_dir . '/' . $doc . '.md';
}
// 如果文件不存在,显示第一个可用文档
if ($file_path === '' || !file_exists($file_path)) {
if (count($articles) > 0) {
$file_path = $articles[0]['file'];
$doc = $articles[0]['name'];
} else {
// 没有文档时显示默认页面
$html_content = '<h1>Oraset 文档</h1><p>暂无文档。</p>';
$title = 'Oraset 文档';
$doc = '';
}
}
// 读取文档内容
if ($file_path !== '' && file_exists($file_path)) {
$content = file_get_contents($file_path);
// 先执行 PHP 代码
ob_start();
eval('?>' . $content . '<?php ');
$content = ob_get_clean();
// 替换版本号占位符 {{VERSION}}
$content = str_replace('{{VERSION}}', $current_version, $content);
$html_content = parse_markdown($content, $current_version);
// 提取当前文档标题
$title = 'Oraset 文档';
if (preg_match('/^# (.+)$/m', $content, $matches)) {
$title = $matches[1] . ' - Oraset';
}
}
// 如果是列表模式,生成列表 HTML
if ($show_list) {
$title = '文档列表 - Oraset';
$list_html = "<h1>文档列表</h1>\n<p>以下是所有可用的文档:</p>\n<ul class=\"doc-list\">";
foreach ($articles as $art) {
$list_html .= '<li>';
$list_html .= '<a href="?doc=' . htmlspecialchars($art['name']) . '">' . htmlspecialchars($art['title']) . '</a>';
if ($art['desc']) {
$list_html .= '<br><span class="doc-desc">' . htmlspecialchars($art['desc']) . '</span>';
}
$list_html .= '</li>';
}
$list_html .= '</ul>';
$html_content = $list_html;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($title); ?></title>
<link rel="stylesheet" href="<?php echo $css_path; ?>">
<style>
/* 文档系统额外样式 */
.doc-list {
list-style: none;
padding: 0;
}
.doc-list li {
padding: 12px 0;
border-bottom: 1px solid #eee;
}
.doc-list a {
font-size: 16px;
color: #0000ee;
text-decoration: underline;
}
.doc-desc {
color: #666;
font-size: 13px;
margin-top: 4px;
display: block;
}
.sidebar-loading {
color: #999;
font-style: italic;
}
</style>
</head>
<body>
<div class="layout">
<nav class="sidebar">
<div class="sidebar-section">
<div class="sidebar-section-title">Oraset</div>
<ul>
<li><a href="../index.php">首页</a></li>
<li><a href="../download.php">下载</a></li>
<li><a href="../releases.php">历史版本</a></li>
</ul>
</div>
<div class="sidebar-section">
<div class="sidebar-section-title">文档</div>
<ul>
<li><a href="?list" id="nav-list"<?php echo $show_list ? ' class="active"' : ''; ?>>文档列表</a></li>
</ul>
<ul id="doc-nav-list">
<li><span class="sidebar-loading">加载中...</span></li>
</ul>
</div>
</nav>
<main class="main">
<?php echo $html_content; ?>
</main>
</div>
<script>
// 获取当前文档名
var currentDoc = '<?php echo htmlspecialchars($doc); ?>';
var showList = <?php echo $show_list ? 'true' : 'false'; ?>;
// 加载文档列表
fetch('./api.php')
.then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(function(data) {
var navList = document.getElementById('doc-nav-list');
navList.innerHTML = '';
if (data.articles && data.articles.length > 0) {
data.articles.forEach(function(article) {
var li = document.createElement('li');
var a = document.createElement('a');
a.href = './?doc=' + article.name;
a.textContent = article.title;
if (!showList && article.name === currentDoc) {
a.className = 'active';
}
li.appendChild(a);
navList.appendChild(li);
});
} else {
navList.innerHTML = '<li><span class="sidebar-loading">暂无文档</span></li>';
}
})
.catch(function(error) {
console.error('Error loading document list:', error);
document.getElementById('doc-nav-list').innerHTML = '<li><span class="sidebar-loading">加载失败</span></li>';
});
</script>
</body>
</html>
+99
View File
@@ -0,0 +1,99 @@
# 入门指南
本指南将帮助您快速安装和配置 Oraset 编程语言 B-5 版本环境,并运行您的第一个程序。
## 安装 Oraset
### macOS
```bash
curl https://oraset.parlz.com/download/sh/install.sh | bash
```
### Linux
```bash
curl https://oraset.parlz.com/download/sh/install-linux.sh | bash
```
或手动下载 <a href="https://oraset.parlz.com/download/deb/Oraset-B5.deb" download="oraset.deb" >oraset.deb</a>,然后运行:
```bash
sudo dpkg -i oraset.deb
```
### Windows
下载 <a href="https://oraset.parlz.com/download/exe/Oraset-B5.exe" download="oraset.exe" >oraset.exe</a> 并添加到系统 PATH。
## 验证安装
```bash
oraset -v
```
应该显示:"B-5"
## 运行第一个程序
### 步骤 1:创建脚本文件
创建一个名为 `hello.ora` 的文件,内容如下:
```oraset
print("Hello, World!");
```
### 步骤 2:运行脚本
```bash
oraset hello.ora
```
输出:
```
Hello, World!
```
## 交互模式
Oraset B-5 支持 REPL 交互模式:
```bash
oraset -i
```
```bash
oraset --interactive
```
进入交互模式后,您可以直接输入代码并立即看到结果:
```
Oraset B-5 REPL
Type 'exit' or 'quit' to exit.
> var x = 10
> print(x)
10
> exit
```
## 常见问题
### Q: 命令找不到?
A: 确保 oraset 已添加到系统 PATH,并重新打开终端。
### Q: 如何退出交互模式?
A: 输入 `exit``quit` 即可退出。
### Q: 脚本执行完成后自动退出?
A: 是的,脚本执行完成后自动退出,无需手动操作。
---
Oraset Project &copy; 2026
+212
View File
@@ -0,0 +1,212 @@
# 语言参考
Oraset 编程语言 B-5 版本的完整语法参考文档,包含变量、数据类型、运算符和控制流等核心特性。
## 变量
### 声明变量
```oraset
var x = 10;
var name = "test";
var pi = 3.14;
var flag;
```
### 修改变量
```oraset
x = 20;
name = "new name";
```
### 复合赋值
```oraset
x += 5;
x -= 3;
x *= 2;
x /= 2;
x %= 3;
```
### 自增自减
```oraset
x++;
x--;
```
## 数据类型
- **数字**:整数和浮点数,如 `42``3.14`
- **字符串**:用双引号或单引号包围,如 `"Hello"``'World'`
- **数组**:用方括号定义,如 `[1, 2, 3]`
## 数组
### 创建数组
```oraset
var arr = [10, 20, 30, 40, 50];
var empty = array(5);
```
### 访问数组元素
```oraset
print(arr[0]);
arr[2] = 35;
```
### 数组长度
```oraset
var len = arrlen(arr);
```
## 运算符
### 算术运算符
```oraset
+ // 加法
- // 减法
* // 乘法
/ // 除法
% // 取模
```
### 比较运算符
```oraset
== // 等于
!= // 不等于
> // 大于
< // 小于
>= // 大于等于
<= // 小于等于
```
### 逻辑运算符
```oraset
&& // 逻辑与
|| // 逻辑或
! // 逻辑非
```
## 输出
### print 函数
```oraset
print("Hello"); // 输出并换行
print("No newline", "nel"); // 输出不换行
print("A", "B", 123); // 多个参数用空格分隔
print(arr); // 打印数组
```
## 控制流
### 条件语句
```oraset
if (x > 10) {
print("x is big");
} else {
print("x is small");
}
```
### 循环语句
```oraset
while (x < 100) {
print(x);
x++;
}
for (var i = 0; i < 10; i++) {
print(i);
}
```
### 函数定义
```oraset
function add(a, b) {
return a + b;
}
add(5, 3);
```
## 内置函数
### 数学函数
```oraset
abs(x) // 绝对值
sqrt(x) // 平方根
sin(x) // 正弦
cos(x) // 余弦
tan(x) // 正切
pow(x, y) // x的y次方
log(x) // 自然对数
floor(x) // 向下取整
ceil(x) // 向上取整
round(x) // 四舍五入
int(x) // 转为整数
float(x) // 转为浮点数
rand() // 0-1随机数
rand(n) // 0-n随机数
time() // 当前时间戳
```
### 字符串函数
```oraset
len(str) // 字符串长度
num(str) // 字符串转数字
str(num) // 数字转字符串
```
### 数组函数
```oraset
array(size) // 创建指定大小的数组
arrlen(arr) // 获取数组长度
```
### 输入函数
```oraset
input() // 读取用户输入
input("提示:") // 带提示的输入
```
## 文件配置
### sg 语法
```oraset
sg<nel>
print("All lines no newline");
print("Still same line");
```
`sg<nel>` 设置整个文件的 print 默认不换行。
## 注释
```oraset
# 单行注释
// 单行注释
/* 多行
注释 */
```
---
Oraset Project &copy; 2026
+133
View File
@@ -0,0 +1,133 @@
# 贪吃蛇游戏
这是一个用 Oraset B-5 编写的控制台贪吃蛇游戏!
## 游戏说明
使用方向键控制蛇的移动方向,吃食物得分。
## 运行方法
```bash
oraset examples/snake.ora
```
## 代码
```oraset
// snake.ora - 贪吃蛇游戏
// 使用 w/a/s/d 或方向键控制
// Oraset B-5 版本 - 使用数组存储蛇的位置
var width = 40;
var height = 20;
var speed = 150;
var game_over = 0;
var score = 0;
var snake_x = [10, 9, 8];
var snake_y = [10, 10, 10];
var snake_len = 3;
var food_x = 25;
var food_y = 10;
var direction = 1;
var next_direction = 1;
function generate_food() {
food_x = int(rand() * (width - 4)) + 2;
food_y = int(rand() * (height - 4)) + 2;
}
generate_food();
while (game_over == 0) {
direction = next_direction;
var new_head_x = snake_x[0];
var new_head_y = snake_y[0];
if (direction == 0) new_head_y--;
if (direction == 1) new_head_x++;
if (direction == 2) new_head_y++;
if (direction == 3) new_head_x--;
if (new_head_x <= 0 || new_head_x >= width - 1 ||
new_head_y <= 0 || new_head_y >= height - 1) {
game_over = 1;
break;
}
var i = 0;
while (i < snake_len) {
if (new_head_x == snake_x[i] && new_head_y == snake_y[i]) {
game_over = 1;
break;
}
i++;
}
if (game_over == 1) break;
if (new_head_x == food_x && new_head_y == food_y) {
score++;
snake_len++;
generate_food();
}
i = snake_len - 1;
while (i > 0) {
snake_x[i] = snake_x[i - 1];
snake_y[i] = snake_y[i - 1];
i--;
}
snake_x[0] = new_head_x;
snake_y[0] = new_head_y;
var y = 0;
while (y < height) {
var x = 0;
while (x < width) {
var is_snake = 0;
var is_food = 0;
i = 0;
while (i < snake_len) {
if (x == snake_x[i] && y == snake_y[i]) {
is_snake = 1;
break;
}
i++;
}
if (x == food_x && y == food_y) {
is_food = 1;
}
if (is_snake == 1) {
print("O", "nel");
} else if (is_food == 1) {
print("*", "nel");
} else if (x == 0 || x == width - 1 || y == 0 || y == height - 1) {
print("-", "nel");
} else {
print(" ", "nel");
}
x++;
}
print("");
y++;
}
print("分数:", score, " | 长度:", snake_len);
print("w=上 a=左 s=下 d=右");
}
print("游戏结束! 最终分数:", score);
```
## 注意事项
这个版本使用了 Oraset B-5 的数组功能,代码更加简洁高效。
蛇的身体现在存储在数组中,可以无限增长。
+220
View File
@@ -0,0 +1,220 @@
# 教程
通过实际示例学习 Oraset 编程语言 B-5 版本,从基础输出到循环和条件判断。
## 示例 1:基本输出
```oraset
// hello.ora
print("Welcome to Oraset B-5!");
print("This is my first program.");
```
输出:
```
Welcome to Oraset B-5!
This is my first program.
```
## 示例 2:变量和计算
```oraset
// calc.ora
var a = 10;
var b = 20;
var sum = a + b;
print("The sum is:", sum);
```
输出:
```
The sum is: 30
```
## 示例 3:条件判断
```oraset
// grade.ora
var score = 85;
if (score >= 60) {
print("Pass!");
} else {
print("Fail!");
}
```
输出:
```
Pass!
```
## 示例 4:循环
```oraset
// loop.ora
var i = 1;
while (i <= 5) {
print("Count:", i);
i++;
}
```
输出:
```
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
```
## 示例 5:不换行输出
```oraset
// inline.ora
print("Loading", "nel");
print(".");
print(".");
print(" Done!");
```
输出:
```
Loading...
Done!
```
## 示例 6:文件级配置
```oraset
// no_newline.ora
sg<nel>
print("All");
print("on");
print("same");
print("line");
```
输出:
```
Allonsameline
```
## 示例 7:数组
```oraset
// array.ora
var arr = [10, 20, 30, 40, 50];
print("Array:", arr);
print("First element:", arr[0]);
print("Array length:", arrlen(arr));
arr[2] = 35;
print("Modified array:", arr);
```
输出:
```
Array: [10, 20, 30, 40, 50]
First element: 10
Array length: 5
Modified array: [10, 20, 35, 40, 50]
```
## 示例 8:复合赋值
```oraset
// compound.ora
var x = 10;
x += 5;
print("x += 5:", x);
x *= 2;
print("x *= 2:", x);
x -= 3;
print("x -= 3:", x);
```
输出:
```
x += 5: 15
x *= 2: 30
x -= 3: 27
```
## 示例 9:函数
```oraset
// function.ora
function add(a, b) {
return a + b;
}
function multiply(a, b) {
return a * b;
}
var result = add(5, 3);
print("5 + 3 =", result);
result = multiply(4, 6);
print("4 * 6 =", result);
```
输出:
```
5 + 3 = 8
4 * 6 = 24
```
## 示例 10:数学函数
```oraset
// math.ora
var pi = 3.14159;
print("sin(pi/2) =", sin(pi/2));
print("sqrt(16) =", sqrt(16));
print("abs(-42) =", abs(-42));
print("pow(2, 8) =", pow(2, 8));
print("rand() =", rand());
```
输出:
```
sin(pi/2) = 1
sqrt(16) = 4
abs(-42) = 42
pow(2, 8) = 256
rand() = 0.123456
```
## 练习题
### 练习 1
编写一个程序,计算 1 到 10 的和。
### 练习 2
编写一个程序,判断一个数是奇数还是偶数。
### 练习 3
编写一个程序,输出 99 乘法表的一行。
### 练习 4
编写一个程序,使用数组存储 5 个数字,然后计算它们的平均值。
---
Oraset Project &copy; 2026