==================
Plain template line with one output
==================

@hello(name):
  Hello, [greeting: str]!
  = <greeting>

---

(source_file
  (procedure_def
    name: (identifier)
    params: (param_list
      (param
        name: (identifier)))
    body: (block
      (template_line
        (template_expr
          (text_segment)
          (output_segment
            name: (identifier)
            type: (type_expr
              (type_ref
                name: (identifier))))
          (text_segment)))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Call segment with var argument
==================

@analyze(city):
  [country: str] = <get_country(<city>)>
  = <country>

---

(source_file
  (procedure_def
    name: (identifier)
    params: (param_list
      (param
        name: (identifier)))
    body: (block
      (variable_init_stmt
        (binding_target
          name: (identifier)
          type: (type_expr
            (type_ref
              name: (identifier))))
        rhs: (template_expr
          (call_segment
            name: (identifier)
            args: (call_arg_list
              (call_arg
                (template_arg
                  (input_segment
                    name: (identifier))))))))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Call with literal text argument and nested call
==================

@trip(start):
  [neighbor] = <get_neighbors(<get_country(<start>)>, Europe)>
  = <neighbor>

---

(source_file
  (procedure_def
    name: (identifier)
    params: (param_list
      (param
        name: (identifier)))
    body: (block
      (variable_init_stmt
        (binding_target
          name: (identifier))
        rhs: (template_expr
          (call_segment
            name: (identifier)
            args: (call_arg_list
              (call_arg
                (template_arg
                  (call_segment
                    name: (identifier)
                    args: (call_arg_list
                      (call_arg
                        (template_arg
                          (input_segment
                            name: (identifier))))))))
              (call_arg
                (template_arg
                  (text_in_call_segment)))))))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Call argument can be a mini template with output placeholder
==================

= <foo(apple is a [category])>

---

(source_file
  (return_stmt
    value: (template_expr
      (call_segment
        name: (identifier)
        args: (call_arg_list
          (call_arg
            (template_arg
              (text_in_call_segment)
              (output_segment
                name: (identifier)))))))))

==================
Python expression segment in template
==================

@show(x):
  Result is <`x * 2`>.
  = ok

---

(source_file
  (procedure_def
    name: (identifier)
    params: (param_list
      (param
        name: (identifier)))
    body: (block
      (template_line
        (template_expr
          (text_segment)
          (python_expr_segment
            (inline_python_expr
              code: (python_inline_body)))
          (text_segment)))
      (return_stmt
        value: (template_expr
          (text_segment))))))

==================
Bare Python expression segment in template
==================

@show():
  Review `"def add(a: int) -> int: return a"`.
  = ok

---

(source_file
  (procedure_def
    name: (identifier)
    body: (block
      (template_line
        (template_expr
          (text_segment)
          (inline_python_expr
            code: (python_inline_body))
          (text_segment)))
      (return_stmt
        value: (template_expr
          (text_segment))))))

==================
Output placeholder with no type annotation
==================

@guess():
  Pick a number: [n]
  = <n>

---

(source_file
  (procedure_def
    name: (identifier)
    body: (block
      (template_line
        (template_expr
          (text_segment)
          (output_segment
            name: (identifier))))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Assign target distinguishable from template line starting with output
==================

@dual():
  [a] = hello
  [b] world

---

(source_file
  (procedure_def
    name: (identifier)
    body: (block
      (variable_init_stmt
        (binding_target
          name: (identifier))
        rhs: (template_expr
          (text_segment)))
      (template_line
        (template_expr
          (output_segment
            name: (identifier))
          (text_segment))))))

==================
Escapes inside template text
==================

@esc():
  Use \<angle\> \[brackets\] \@at \= eq \, com
  = ok

---

(source_file
  (procedure_def
    name: (identifier)
    body: (block
      (template_line
        (template_expr
          (text_segment)))
      (return_stmt
        value: (template_expr
          (text_segment))))))

==================
Template prompt accepts mixed bare inline Python
==================

@demo(value: str) -> str:
  >> Prefix `value` suffix [answer]
  = <answer>

---

(source_file
  (procedure_def
    name: (identifier)
    params: (param_list
      (param
        name: (identifier)
        type: (type_expr
          (type_ref
            name: (identifier)))))
    return_type: (type_expr
      (type_ref
        name: (identifier)))
    body: (block
      (template_block_stmt
        head: (template_prompt_expr
          (text_segment)
          (inline_python_expr
            code: (python_inline_body))
          (text_segment)
          (output_segment
            name: (identifier))))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Trailing spaces after prompt and return are ignored
==================

@demo() -> str:
  >> Hello [answer]   
  = <answer>   

---

(source_file
  (procedure_def
    name: (identifier)
    return_type: (type_expr
      (type_ref
        name: (identifier)))
    body: (block
      (template_block_stmt
        head: (template_prompt_expr
          (text_segment)
          (output_segment
            name: (identifier))))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Template block with multiline continuation (>>)
==================

>> What's the [capital] of Turkey?
What's the [population: int] of <capital>?

---

(source_file
  (template_block_stmt
    head: (template_prompt_expr
      (text_segment)
      (output_segment
        name: (identifier))
      (text_segment))
    continuation: (template_prompt_expr
      (text_segment)
      (output_segment
        name: (identifier)
        type: (type_expr
          (type_ref
            name: (identifier))))
      (text_segment)
      (input_segment
        name: (identifier))
      (text_segment))))

==================
Template block continuation accepts bare inline Python
==================

@demo(value: str) -> str:
  >> Prefix
  `value`
  suffix
  = done

---

(source_file
  (procedure_def
    name: (identifier)
    params: (param_list
      (param
        name: (identifier)
        type: (type_expr
          (type_ref
            name: (identifier)))))
    return_type: (type_expr
      (type_ref
        name: (identifier)))
    body: (block
      (template_block_stmt
        head: (template_prompt_expr
          (text_segment))
        continuation: (template_prompt_expr
          (inline_python_expr
            code: (python_inline_body)))
        continuation: (template_prompt_expr
          (text_segment)))
      (return_stmt
        value: (template_expr
          (text_segment))))))

==================
Template block preserves a blank continuation row
==================

>> First paragraph [answer].

Second paragraph adds context.
= <answer>

---

(source_file
  (template_block_stmt
    head: (template_prompt_expr
      (text_segment)
      (output_segment
        name: (identifier))
      (text_segment))
    (template_blank_line)
    continuation: (template_prompt_expr
      (text_segment)))
  (return_stmt
    value: (template_expr
      (input_segment
        name: (identifier)))))

==================
Whitespace-only procedure line is blank
==================

@demo():
  >> Hello [answer]
  
  = <answer>

---

(source_file
  (procedure_def
    name: (identifier)
    body: (block
      (template_block_stmt
        head: (template_prompt_expr
          (text_segment)
          (output_segment
            name: (identifier))))
      (return_stmt
        value: (template_expr
          (input_segment
            name: (identifier)))))))

==================
Top-level variable initialization and top-level return
==================

[global_city: str] = Paris
= <global_city>

---

(source_file
  (variable_init_stmt
    (binding_target
      name: (identifier)
      type: (type_expr
        (type_ref
          name: (identifier))))
    rhs: (template_expr
      (text_segment)))
  (return_stmt
    value: (template_expr
      (input_segment
        name: (identifier)))))

==================
Top-level backtick-line statement (side effect)
==================

`print("hi")`

---

(source_file
  (backtick_line_stmt
    (inline_python_expr
      code: (python_inline_body))))
