Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_arkts_open-0.1.4.tar.gz (177.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_arkts_open-0.1.4-cp310-abi3-win_amd64.whl (80.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_arkts_open-0.1.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (93.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_11_0_arm64.whl (80.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_10_9_x86_64.whl (75.3 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_arkts_open-0.1.4.tar.gz.

File metadata

  • Download URL: tree_sitter_arkts_open-0.1.4.tar.gz
  • Upload date:
  • Size: 177.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree_sitter_arkts_open-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5441a70ffbe4759982a00e308d1bc7e0575bfa84f00776f1cc218087370565f8
MD5 2a7e74d044cccd47ae9e7c4657719c00
BLAKE2b-256 3c5938b069039ceab82aeab62094becca23e55f6d2de53b24dacbaea757c2e7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_arkts_open-0.1.4.tar.gz:

Publisher: publish.yml on Million-mo/tree-sitter-arkts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_arkts_open-0.1.4-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_arkts_open-0.1.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6047bd447cdfcd3e4ffd241a60cc121433adb3e743701ddc5e4cacda40cd5c2c
MD5 5c26924b47301d2d560b83d292867436
BLAKE2b-256 b47b3d2d9a320a18ea97fa9dcfb94da5e5678ecc7b394bf7816ef60badec6431

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_arkts_open-0.1.4-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on Million-mo/tree-sitter-arkts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_arkts_open-0.1.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_arkts_open-0.1.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 106e1d9ffe8c261e453b2472516306b3061c69dcc2d339cd0636732ac7cdf6fd
MD5 5b55322e91a931b21c5ca1d81f96b935
BLAKE2b-256 6c0b7f1ab848c08db2cc6c4ce2591d10596454c3ec8a03132371cdd47b187973

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_arkts_open-0.1.4-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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 08ea92f1bbfa2ea5ba9fc695467c8105e8cd1cee7b7a280759be81495d352b1c
MD5 a95bb67c7d6178e21e4f2ac6f4abf415
BLAKE2b-256 3743e6b385365bd7d4d7b9eeecd19a7bc2d5263f75c449e9c7a7df80804f68f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on Million-mo/tree-sitter-arkts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 89ef92fe95501e91e25db457840db1cb5426ceff3a73bb76922bc81fa5bd33c3
MD5 518b59e1b1d8404ffafb1693c863d9b9
BLAKE2b-256 967e4fd667c91e0770fff3c34d59f2e5cbebb905ffa92f26ebd8c108bfaa7932

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_arkts_open-0.1.4-cp310-abi3-macosx_10_9_x86_64.whl:

Publisher: publish.yml on Million-mo/tree-sitter-arkts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page