此扩展为Visual Studio Code中的Alang编程语言提供全面的语言支持,包括语法高亮、代码片段、运行和编译功能等。
功能
语法高亮:为Alang代码提供语法高亮,包括:
英文关键字 (if, else, function 等)
中文关键字 (如果, 否则, 函数 等)
英文类型 (int, string, boolean 等)
中文类型 (整数, 字符串, 布尔 等)
字符串、注释、数字、函数和变量
中文标识符(变量名、函数名等)
代码片段:为常见的Alang构造提供便捷的代码片段:
func:创建函数定义
class:创建类定义
if:创建if语句
ifelse:创建if-else语句
for:创建for循环
while:创建while循环
log:创建console.log语句
main:创建英文主函数
主:创建中文主函数
运行和编译:支持运行和编译Alang文件:
alangc-build:使用 alangc build <file> 编译Alang文件
alangc-run:使用 alangc run <file> 运行Alang文件
alangc-buildAndRun:编译并运行Alang文件
启动图标:在主函数旁边显示绿色播放图标,点击可运行文件
语言配置:包括基本的语言配置,如:
注释语法(// 用于行注释,/* */ 用于块注释)
括号匹配和自动闭合对
Go语言风格的缩进和格式化
文件扩展名
Alang文件使用 .ala 扩展名。
命令
此扩展提供以下命令:
命令
描述
快捷键
Alang: Build (alangc build)
使用 alangc build <file> 编译Alang文件
右键编辑器 → 选择命令
Alang: Run (alangc run)
使用 alangc run <file> 运行Alang文件
右键编辑器 → 选择命令
Alang: Build and Run
编译并运行Alang文件
右键编辑器 → 选择命令
Alang代码示例
英文语法
// This is a test file for Alang language
// Test comments
/*
Multi-line comment
*/
// Test variables
const message = "Hello, Alang!";
let count = 10;
var flag = true;
// Test numbers
const pi = 3.14;
const answer = 42;
// Test functions
function greet(name) {
return "Hello, " + name + "!";
}
// Test class
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
sayHello() {
return "Hello, my name is " + this.name;
}
}
// Test if statement
if (count > 0) {
console.log("Count is positive");
} else {
console.log("Count is zero or negative");
}
// Test for loop
for (let i = 0; i < 5; i++) {
console.log("Iteration " + i);
}
// Test while loop
let i = 0;
while (i < 5) {
console.log("While iteration " + i);
i++;
}
// Test main function
function main() {
console.log("Hello from main function");
const result = greet("World");
console.log(result);
const person = new Person("Alice", 30);
console.log(person.sayHello());
}