Xiaoqinli

Other

AST-First transpiler for AI agents 鈥?write structured .xql.json, compile to Go/Rust/TypeScript/Kotlin/Swift/Python with type safety, effect inference, and capability checks

Install

openclaw skills install xiaoqinli

Xiaoqinli (XQL) 鈥?AST-First Transpiler

AI agents write structured .xql.json (JSON AST) directly 鈥?no parser needed, no syntax errors possible. The compiler validates types, effects, and capabilities at compile time, then emits idiomatic source code in 6 languages.

Install

# From source (requires Go 1.23+)
git clone https://github.com/Freecode100Year/xiaoqinli.git
cd xiaoqinli && go build -o xql .

# Move to PATH
# Linux/macOS: sudo mv xql /usr/local/bin/
# Windows: move xql.exe to a directory in %PATH%

Usage

# Validate AST
xql validate --file program.xql.json

# Compile to target language
xql compile --file program.xql.json --target go
xql compile --file program.xql.json --target rust --out main.rs
xql compile --file program.xql.json --target ts --out main.ts
xql compile --file program.xql.json --target kotlin --out Main.kt
xql compile --file program.xql.json --target swift --out main.swift
xql compile --file program.xql.json --target py --out main.py

.xql.json AST Format

Every node has a "kind" field. Top-level must be "Program" with "declarations" array.

Type System

KindGoRustTypeScriptKotlinSwiftPython
Intinti64numberLongIntint
Floatfloat64f64numberDoubleDoublefloat
StringstringStringstringStringStringstr
BoolboolboolbooleanBooleanBoolbool
Void(none)(none)voidUnit(none)None
Array[]TVec<T>T[]List<T>[T]list[T]
Option*TOption<T>T | nullT?T?Optional[T]
Result(T, error)Result<T, E>鈥?鈥?鈥?鈥?

Node Kinds

Declarations:

  • Program 鈥?top-level, contains declarations[]
  • FunctionDecl 鈥?name, params[], returnType, effects[], grant[], body[]

Statements:

  • VarDecl 鈥?name, type, value
  • AssignStmt 鈥?target, value
  • ReturnStmt 鈥?value (optional)
  • IfStmt 鈥?cond, then[], else[]
  • WhileStmt 鈥?cond, body[]
  • ExprStmt 鈥?expr

Expressions:

  • Literal 鈥?valueType (String/Int/Float/Bool), value
  • Ident 鈥?name
  • BinaryExpr 鈥?op (+, -, *, /, %, ==, !=, <, >, <=, >=, &&, ||), left, right
  • UnaryExpr 鈥?op (!, -), operand
  • CallExpr 鈥?callee (string), args[]
  • MemberExpr 鈥?object, field

Built-in Functions

NameEffectDescription
printlnstatePrint with newline
printfstateFormatted print
sprintfpureFormatted string build

Safety Annotations

  • effects: ["pure"] 鈥?compiler verifies no side effects (transitive)
  • effects: ["state"] / ["network"] / ["filesystem"] 鈥?declare side effects
  • grant: ["io", "network"] 鈥?capability declaration; callee must be subset of caller

Example

{
  "kind": "Program",
  "declarations": [
    {
      "kind": "FunctionDecl",
      "name": "greet",
      "params": [{"name": "name", "type": {"kind": "String"}}],
      "returnType": {"kind": "String"},
      "effects": ["pure"],
      "grant": [],
      "body": [{
        "kind": "ReturnStmt",
        "value": {
          "kind": "BinaryExpr", "op": "+",
          "left": {"kind": "Literal", "valueType": "String", "value": "Hello, "},
          "right": {"kind": "Ident", "name": "name"}
        }
      }]
    },
    {
      "kind": "FunctionDecl",
      "name": "main",
      "params": [],
      "returnType": {"kind": "Void"},
      "effects": ["state"],
      "grant": ["io"],
      "body": [{
        "kind": "ExprStmt",
        "expr": {
          "kind": "CallExpr", "callee": "println",
          "args": [{
            "kind": "CallExpr", "callee": "greet",
            "args": [{"kind": "Literal", "valueType": "String", "value": "World"}]
          }]
        }
      }]
    }
  ]
}

Compiles to Go:

package main

import "fmt"

func greet(name string) string {
    return "Hello, " + name
}

func main() {
    fmt.Println(greet("World"))
}

Three Static Checks

CheckWhat it doesError codes
Type checkValidates types, function signatures, return types, argument countsXQL_E2xx
Effect inferenceInfers side effects transitively through call chainsXQL_E2xx
Capability checkEnforces @grant 鈥?callee capabilities must be subset of caller'sXQL_E3xx

Error Codes

RangeCategory
XQL_E1xxParse / AST errors
XQL_E2xxType / effect errors
XQL_E3xxCapability errors
XQL_E4xxCodegen errors

Workflow

  1. Write .xql.json AST file
  2. Run xql validate --file program.xql.json to check
  3. Run xql compile --file program.xql.json --target go --out main.go to generate source
  4. Build with target language toolchain (e.g., go build -o app.exe main.go)

Source

https://github.com/Freecode100Year/xiaoqinli