[web] Updated README.md

This commit is contained in:
Sidi Liang 2024-11-09 14:14:45 +08:00
parent 8e7074fd25
commit c8869080c6
No known key found for this signature in database
GPG Key ID: 9785F5EECFFA5311
3 changed files with 108 additions and 7 deletions

View File

@ -23,6 +23,7 @@
* [__Trace Back Info__](#trace-back-info) * [__Trace Back Info__](#trace-back-info)
* [__Debugger__](#debugger) * [__Debugger__](#debugger)
* [__REPL__](#repl) * [__REPL__](#repl)
* [__Web Interface__](#web-interface)
__Contact us if having great ideas to share!__ __Contact us if having great ideas to share!__
@ -121,7 +122,7 @@ runtime.windows.set_utf8_output();
![error](./doc/gif/error.gif) ![error](./doc/gif/error.gif)
<details><summary>Must use `var` to define variables</summary> <details><summary>Must use `var` to define variables</summary>
This interpreter uses more strict syntax to make sure it is easier for you to program and debug. This interpreter uses more strict syntax to make sure it is easier for you to program and debug.
And flightgear's nasal interpreter also has the same rule. And flightgear's nasal interpreter also has the same rule.
@ -146,13 +147,13 @@ If you forget to add the keyword `var`, you will get this:
```javascript ```javascript
code: undefined symbol "i" code: undefined symbol "i"
--> test.nas:1:9 --> test.nas:1:9
| |
1 | foreach(i; [0, 1, 2, 3]) 1 | foreach(i; [0, 1, 2, 3])
| ^ undefined symbol "i" | ^ undefined symbol "i"
code: undefined symbol "i" code: undefined symbol "i"
--> test.nas:2:11 --> test.nas:2:11
| |
2 | print(i) 2 | print(i)
| ^ undefined symbol "i" | ^ undefined symbol "i"
``` ```
@ -441,5 +442,51 @@ Nasal REPL interpreter version 11.1 (Nov 1 2023 23:37:30)
>>> use std.json; >>> use std.json;
{stringify:func(..) {..},parse:func(..) {..}} {stringify:func(..) {..},parse:func(..) {..}}
>>> >>>
``` ```
## __Web Interface__
A web-based interface is now available for trying out Nasal code directly in your browser. It includes both a code editor and an interactive REPL (WIP).
### Web Code Editor
- Syntax highlighting using CodeMirror
- Error highlighting and formatting
- Example programs
- Execution time display option
- Configurable execution time limits
- Notice: The security of the online interpreter is not well tested, please use it with sandbox mechanism or other security measures.
### Web REPL
- ** IMPORTANT: The time limit in REPL is not correctly implemented yet. Thus this REPL web binding is not considered finished. Do not use it in production before it's fixed. **
- Interactive command-line style interface in browser
- Multi-line input support with proper prompts (`>>>` and `...`)
- Command history navigation
- Error handling with formatted error messages
- Example snippets for quick testing
### Running the Web Interface
1. Build the Nasal shared library:
```bash
cmake -DBUILD_SHARED_LIBS=ON .
make nasal-web
```
2. Set up and run the web application:
For the code editor:
```bash
cd nasal-web-app
npm install
node server.js
```
Visit `http://127.0.0.1:3000/`
For the REPL:
```bash
cd nasal-web-app
npm install
node server_repl.js
```
Visit `http://127.0.0.1:3001/repl.html`

View File

@ -26,9 +26,8 @@
__如果有好的意见或建议欢迎联系我们!__ __如果有好的意见或建议欢迎联系我们!__
* __lhk101lhk101@qq.com__ (ValKmjolnir) - __lhk101lhk101@qq.com__ (ValKmjolnir)
- __sidi.liang@gmail.com__ (Sidi)
* __sidi.liang@gmail.com__ (Sidi)
## __简介__ ## __简介__
@ -428,3 +427,57 @@ Nasal REPL interpreter version 11.1 (Nov 1 2023 23:37:30)
>>> >>>
``` ```
## __Web 界面__
现已提供基于 Web 的库以及示例界面,您可以直接在浏览器中编写和运行 Nasal 代码。该界面包括代码编辑器和交互式 REPL未完成
### __Web 代码编辑器__
- **语法高亮:** 使用 CodeMirror 提供增强的编码体验。
- **错误高亮和格式化:** 清晰显示语法和运行时错误。
- **示例程序:** 预加载的示例,帮助您快速上手。
- **执行时间显示选项:** 可选择查看代码执行所需时间。
- **可配置的执行时间限制:** 设置时间限制以防止代码长时间运行。
- **提示:** 在线解释器的安全性尚未得到广泛测试,建议配合沙盒机制等安全措施使用。
### __Web REPL__
- **重要提示:** REPL 中的代码执行时间限制尚未正确实现。此 REPL 库目前不稳定,请勿在生产环境中使用。
- **交互式命令行界面:** 在浏览器中体验熟悉的 REPL 环境。
- **多行输入支持:** 使用 `>>>``...` 提示符无缝输入多行代码。
- **命令历史导航:** 使用箭头键轻松浏览命令历史。
- **格式化的错误处理:** 接收清晰且格式化的错误消息,助力调试。
- **快速测试的示例代码片段:** 访问并运行示例代码片段,快速测试功能。
### __运行 Web 界面__
1. **构建 Nasal 共享库:**
```bash
cmake -DBUILD_SHARED_LIBS=ON .
make nasal-web
```
2. **设置并运行 Web 应用:**
**代码编辑器:**
```bash
cd nasal-web-app
npm install
node server.js
```
在浏览器中访问 `http://127.0.0.1:3000/` 以使用代码编辑器。
**REPL:**
```bash
cd nasal-web-app
npm install
node server_repl.js
```
在浏览器中访问 `http://127.0.0.1:3001/repl.html` 以使用 REPL 界面。
---

1
package.json Normal file
View File

@ -0,0 +1 @@
{}