Skip to content
 
 

Repository files navigation

GeoGebra Commands

A much more navigable command reference for GeoGebra. Published at https://deb-sandeep.github.io/GeogebraCommands/

GeoGebra Lint Engine

本项目还包含一个功能完整的 GeoGebra 脚本 Lint 引擎,提供词法分析、语法分析、代码检查和在线测试功能。

✨ 功能特性

  • 🔍 词法分析 (Lexer): 将 GeoGebra 脚本转换为 Token 流
  • 🌲 语法分析 (Parser): 将 Token 流解析为抽象语法树 (AST)
  • ⚙️ 规则引擎 (Rule Engine): 可扩展的代码检查规则系统
  • 类型检查: 验证命令参数数量和类型是否正确
  • 🚫 未知命令检测: 识别不存在的 GeoGebra 命令,提供拼写建议
  • 📚 命令规范: 支持 505+ GeoGebra 命令的完整签名
  • 🎯 Point 字面量支持: 支持 A = (0, 0, 3) 等元组语法
  • 🌐 Web 测试界面: 实时在线测试和 AST 可视化

🚀 快速开始

安装依赖

npm install

构建

# Node.js 环境构建
npm run build

# 浏览器环境构建(ES 模块)
npm run build:browser

命令行使用

# 分析文件
node scripts/cli.js tests/fixtures/example.ggb

# 分析内联代码
node scripts/cli.js -c "SetValue(a, 1)"

Web 测试界面

# Windows 一键启动
start-web-demo.bat

# 或手动启动
npm run build:browser
python -m http.server 8080
# 访问 http://localhost:8080/tests/web-demo.html

📊 支持的检查规则

1. no-unknown-command (错误级别)

检查命令是否在 GeoGebra 命令库中存在,提供拼写建议。

UnknownCommand(a, 1)  // ❌ 错误:未知的命令
SetValu(obj, 5)       // ❌ 错误:你是否想使用 SetValue?

2. correct-arg-types (警告级别)

检查命令参数数量和类型是否正确。

Distance(A)           // ⚠️ 警告:期望 2 个参数,收到 1 个
SetColor(P)           // ⚠️ 警告:期望 4 个参数,收到 1 个
SetColor(P, "red")    // ✅ 正确:支持字符串形式的颜色

📁 项目结构

GeogebraCommands/
├── src/                          # Lint 引擎源码
│   ├── index.ts                  # 主入口文件
│   ├── core/
│   │   ├── index.ts              # 核心模块导出
│   │   ├── parser/
│   │   │   ├── ast.d.ts          # AST 类型定义
│   │   │   ├── lexer.ts          # 词法分析器
│   │   │   └── parser.ts         # 语法分析器
│   │   ├── rules/                # Lint 规则
│   │   │   ├── rule.d.ts         # 规则接口定义
│   │   │   ├── rule-engine.ts    # 规则引擎
│   │   │   ├── no-unknown-command.ts  # 未知命令检测
│   │   │   └── correct-arg-types.ts   # 参数类型检查
│   │   └── specs/                # GeoGebra 命令规范
│   │       ├── commandSignatures.json # 505 个命令签名
│   │       └── spec-registry.ts  # 规范注册表
│   └── types/
│       └── linting.ts            # Linting 类型
├── scripts/
│   ├── cli.js                    # 命令行工具
│   └── convert-json.js           # JSON 转 TS 工具
├── tests/
│   ├── web-demo.html             # Web 测试界面
│   └── fixtures/
│       └── example.ggb           # 测试数据
├── content/                      # GeoGebra 命令参考文档
├── package.json
├── tsconfig.json
├── tsconfig.browser.json
└── start-web-demo.bat

🛠️ 技术栈

  • 语言: TypeScript 5.0+
  • 运行时: Node.js 18+
  • 模块系统: CommonJS (Node) / ES Modules (浏览器)

About

A more navigable command documentation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages