sml

SML { ❄ }

中文 EN

Chapter 11: Practical Translation Challenge

Chapter 11: Practical Translation Challenge

Just looking will make you forget, only by doing will you remember. This chapter does not provide a standard answer - we will give you the original configuration, and ask you** to handwrite the equivalent SML**, and then click “verify” to let the parser judge in real time.

These challenges deliberately chose common formats in engineering (Caddyfile/Docker compose/nginx), which are highly similar to SML’s “block+key value” thinking. Remember three things when translating:

  1. Block=Block: name { } is universal on both sides;

  2. Key value pairs: key value (Caddy/nginx) or key: value (YAML) both correspond to SML’s key: value;

  3. Array: SML uses [ a b c ] (comma can be omitted), YAML uses [a, b, c].

Here are three challenges with increasing difficulty. Write SML directly in the white background editor on the right side of each question, and any errors or missing fields will be immediately prompted.

Challenge 1: Caddyfile → SML

🔧 挑战 1 · Caddyfile → SML ★★☆
下面是一段 Caddyfile。请用 SML 表达等价配置:把站点块变成嵌套块,把 key value 变成 key: value。完成后点「验证」,系统会检查关键字段是否都正确翻译。验证逻辑是 JS 直接解析你的 SML 并断言结果。
原始材料(待翻译)
example.com {
    reverse_proxy localhost:8080
    tls internal
    encode gzip
}
你的 SML 答案(可编辑)
💡 提示:Caddyfile 的 `example.com { }` 块 == SML 的 `example.com { }` 嵌套块;`tls internal` == `tls: internal`。

Challenge 2: Docker compose → SML (high difficulty)

🔧 挑战 2 · docker-compose.yml → SML(高难度) ★★★
把下面 docker-compose 片段翻译成 SML。注意:YAML 的数组 [a, b] 在 SML 里写成 [ a b ];带连字符的键名(如 container_name)直接当裸词键即可。验证会检查 services.web 与 services.db 的关键字段。
原始材料(待翻译)
services:
  web:
    image: nginx:1.27
    ports:
      - "80:80"
    depends_on:
      - db
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
你的 SML 答案(可编辑)
💡 提示:SML 裸词里连字符 `-`、下划线 `_` 都是合法的键字符,所以 container_name / POSTGRES_PASSWORD 不用引号。

Challenge 3: nginx.conf → SML (high difficulty)

🔧 挑战 3 · nginx.conf → SML(高难度) ★★★
把下面 nginx server 块翻译成 SML。nginx 的 listen 80; == SML listen: 80location / { } 是嵌套块;proxy_pass http://app; 是带空格的值,需要引号。验证检查 server 块的关键指令。
原始材料(待翻译)
server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://app:3000;
    }
    location /api {
        proxy_pass http://api:4000;
    }
}
你的 SML 答案(可编辑)
💡 提示:proxy_pass 的值含空格和冒号,必须加引号:`proxy_pass: "http://app:3000"`。但 `server_name example.com` 的 example.com 是裸词即可。

Why did you do this

Translating other formats into SML can best test whether you truly understand that ‘SML is just a tree’. When you can intuitively map any configuration into an Block/Key/Array three piece set, you have already mastered the essence of SML.

Appendix: Comparison and Investigation