Tree-sitter grammar for ArkTS (HarmonyOS development language)
Project description
ArkTS Tree-sitter 解析器
这是一个为华为ArkTS语言开发的Tree-sitter语法解析器,支持ArkTS语言的完整语法特性,包括装饰器、组件化语法、状态管理等核心特性。
特性支持
✅ 已实现特性
- 基础TypeScript语法兼容
- 装饰器语法(@Component、@State、@Prop、@Link等)
- struct组件定义
- build()方法和UI描述语法
- 导入/导出声明
- 接口和类型定义
- 基础表达式和语句
🚧 开发中特性
- 完整的UI组件调用语法
- ForEach循环语法
- 条件渲染语法
- 高级装饰器支持(@Builder、@Styles等)
- 错误恢复机制优化
📋 计划实现特性
- 模块系统扩展
- 泛型语法完整支持
- 性能优化
- 更多语言绑定
安装使用
Node.js
npm install tree-sitter-arkts-open
const Parser = require('tree-sitter');
const ArkTS = require('tree-sitter-arkts');
const parser = new Parser();
parser.setLanguage(ArkTS);
const sourceCode = `
@Component
struct HelloWorld {
@State message: string = 'Hello'
build() {
Text(this.message)
}
}
`;
const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());
Python
pip install tree-sitter-arkts-open
import tree_sitter_arkts as arkts
from tree_sitter import Language, Parser
ARKTS_LANGUAGE = Language(arkts.language())
parser = Parser(ARKTS_LANGUAGE)
source_code = '''
@Component
struct MyComponent {
build() {
Text('Hello ArkTS')
}
}
'''
tree = parser.parse(bytes(source_code, 'utf8'))
print(tree.root_node)
语法支持示例
组件定义
@Component
struct MyComponent {
@State count: number = 0;
@Prop title: string = 'Default';
build() {
Column() {
Text(this.title)
Button('Click')
.onClick(() => {
this.count++
})
}
}
}
状态管理
@Component
struct StateExample {
@State private items: string[] = [];
@Link shared: boolean;
build() {
List() {
ForEach(this.items, (item: string) => {
ListItem() {
Text(item)
}
})
}
}
}
开发
构建解析器
tree-sitter generate
测试
tree-sitter test
解析文件
tree-sitter parse example.ets
语言绑定
本解析器支持多种编程语言绑定:
- Node.js:
bindings/node/ - Python:
bindings/python/ - Rust:
bindings/rust/ - Go:
bindings/go/ - Swift:
bindings/swift/
贡献
欢迎提交Issues和Pull Requests!
开发环境
- Tree-sitter CLI 0.25.3+
- Node.js 18+
- 支持的构建工具链
测试用例
测试用例位于 test/ 目录,包含:
- 基础组件语法测试
- 装饰器语法测试
- 状态管理语法测试
- 错误恢复测试
许可证
MIT License
相关链接
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_arkts_open-0.1.2.tar.gz.
File metadata
- Download URL: tree_sitter_arkts_open-0.1.2.tar.gz
- Upload date:
- Size: 104.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9872d44432b970d8dda65a9a389a1d134370c5678f4509c53e2924f150555d5
|
|
| MD5 |
cafac375f76da91544c9f7799a30d3f8
|
|
| BLAKE2b-256 |
ba6e058d7c79cf965f62588d628055601a230955530ad329a585fc70ae2599a3
|
Provenance
The following attestation bundles were made for tree_sitter_arkts_open-0.1.2.tar.gz:
Publisher:
publish.yml on Million-mo/tree-sitter-arkts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_arkts_open-0.1.2.tar.gz -
Subject digest:
d9872d44432b970d8dda65a9a389a1d134370c5678f4509c53e2924f150555d5 - Sigstore transparency entry: 611969784
- Sigstore integration time:
-
Permalink:
Million-mo/tree-sitter-arkts@93cbb0d386f23ea0b3ef9b20518f97f07c593ad0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Million-mo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@93cbb0d386f23ea0b3ef9b20518f97f07c593ad0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_arkts_open-0.1.2-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tree_sitter_arkts_open-0.1.2-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 71.1 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c0a2a2d7879e25614f212161abacec9f5110cd58ad4c6cb0f9b640d430eee83
|
|
| MD5 |
a2b9acfa60f183f5ce9720fb3f05f3b0
|
|
| BLAKE2b-256 |
6076148e91ad31c2d005f4f8bbed7043ab6a7c071274c0ba2fd8f26cb9e3017d
|
Provenance
The following attestation bundles were made for tree_sitter_arkts_open-0.1.2-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on Million-mo/tree-sitter-arkts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_arkts_open-0.1.2-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
6c0a2a2d7879e25614f212161abacec9f5110cd58ad4c6cb0f9b640d430eee83 - Sigstore transparency entry: 611969788
- Sigstore integration time:
-
Permalink:
Million-mo/tree-sitter-arkts@93cbb0d386f23ea0b3ef9b20518f97f07c593ad0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Million-mo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@93cbb0d386f23ea0b3ef9b20518f97f07c593ad0 -
Trigger Event:
push
-
Statement type: