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:
Block=Block:
name { }is universal on both sides;Key value pairs:
key value(Caddy/nginx) orkey: value(YAML) both correspond to SML’skey: value;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
key value 变成 key: value。完成后点「验证」,系统会检查关键字段是否都正确翻译。验证逻辑是 JS 直接解析你的 SML 并断言结果。example.com {
reverse_proxy localhost:8080
tls internal
encode gzip
}Challenge 2: Docker compose → SML (high difficulty)
[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: secretChallenge 3: nginx.conf → SML (high difficulty)
listen 80; == SML listen: 80;location / { } 是嵌套块;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;
}
}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.