sml

SML { ❄ }

Downloads Questions, bug reports, or just to say hi: sal@mail.swebase.cn 中文 EN

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

🔧 Challenge 1: Caddyfile → SML ★★☆
Below is a Caddyfile. Please use SML to express equivalent configuration: Change the site block to a nested block, and change key value to key: value. After completion, click 'Verify' and the system will check if all key fields are translated correctly. The verification logic is JS directly parsing your SML and asserting the result.
Source material (to translate)
example.com {
    reverse_proxy localhost:8080
    tls internal
    encode gzip
}
Your SML answer (editable)
💡 Hint: `example.com { }` block of Caddyfile==`example.com { }` nested block of SML; `tls internal` == `tls: internal`。

Challenge 2: Docker compose → SML (high difficulty)

🔧 Challenge 2: Docker-compose.yml → SML (High Difficulty) ★★★
Translate the docker compose fragment below into SML. Note that the array [a, b] of : YAML is written as [ a b ] in SML; The key names with hyphens (such as container_name) can be directly used as bare word keys. Verification will check the key fields of services.web and services.db.
Source material (to translate)
services:
  web:
    image: nginx:1.27
    ports:
      - "80:80"
    depends_on:
      - db
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
Your SML answer (editable)
💡 Hint: The hyphens `-` and underscores `_` in SML bare words are legal key characters, so container_name/POSTGRES-PASSWORD does not use quotation marks.

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

🔧 Challenge 3: nginx.conf → SML (High Difficulty) ★★★
Translate the nginx server block below into SML. Nginx's listen 80; == SML listen: 80; location/{ } are nested blocks; proxy_pass http://app; is a value with spaces and requires quotation marks. Verify the key instructions for checking the server block.
Source material (to translate)
server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://app:3000;
    }
    location /api {
        proxy_pass http://api:4000;
    }
}
Your SML answer (editable)
💡 Hint: The value of proxy passed contains spaces and colons, and must be enclosed in quotation marks: `proxy_pass: "http://app:3000"`. But the example.com of `server_name example.com` can be bare words.

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