==================
Nested procedure: phantom indent must not close the outer block
==================

@outer():
    @inner():
        hello
            deeper
    = `1`

---

(source_file
  (procedure_def
    (identifier)
    (block
      (procedure_def
        (identifier)
        (block
          (template_line
            (template_expr
              (text_segment)))
          (template_line
            (template_expr
              (text_segment)))))
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Nested procedure: two phantom indents must not close the outer block
==================

@outer():
    @inner():
        hello
            deeper
                deepest
    = `1`

---

(source_file
  (procedure_def
    (identifier)
    (block
      (procedure_def
        (identifier)
        (block
          (template_line
            (template_expr
              (text_segment)))
          (template_line
            (template_expr
              (text_segment)))
          (template_line
            (template_expr
              (text_segment)))))
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Template deeper line then return at block indent
==================

@f():
    hello
        deeper text
    = `1`

---

(source_file
  (procedure_def
    (identifier)
    (block
      (template_line
        (template_expr
          (text_segment)))
      (template_line
        (template_expr
          (text_segment)))
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Embedded NUL in a comment line
==================

@f():
    # comment junk
    = `1`

---

(source_file
  (procedure_def
    (identifier)
    (block
      (line_comment)
      (template_line
        (template_expr
          (text_segment)))
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Embedded NUL in a fenced Python block
==================

```
x = 1 
y = 2
```
= done

---

(source_file
  (python_block
    (ERROR
      (identifier))
    code: (python_code))
  (return_stmt
    value: (template_expr
      (text_segment))))
==================
Error recovery: unterminated fence must not swallow the rest of the file
==================

@f():
    [x] = `1` @@@ ```
    swallowed 1
    swallowed 2
    ```
    = `2`

---

(source_file
  (procedure_def
    name: (identifier)
    body: (block
      (variable_init_stmt
        (binding_target
          name: (identifier))
        (ERROR
          (inline_python_expr
            code: (python_inline_body)))
        rhs: (inline_python_expr
          code: (python_inline_body))))))
==================
CRLF fenced Python block
==================

```
import x
```

= done

---

(source_file
  (python_block
    (python_code))
  (return_stmt
    (template_expr
      (text_segment))))

==================
CRLF fenced Python block inside a procedure
==================

@f():
    ```
    import x
    ```
    = done

---

(source_file
  (procedure_def
    (identifier)
    (block
      (python_block
        (python_code))
      (return_stmt
        (template_expr
          (text_segment))))))

==================
CRLF line continuation stays one text segment
==================

@f():
    foo \
    bar

---

(source_file
  (procedure_def
    (identifier)
    (block
      (template_line
        (template_expr
          (text_segment))))))

==================
CRLF condition colon matches the LF parse
==================

> if: some text:
  > show: yes

---

(source_file
  (ERROR
    (condition_text_segment))
  (show_stmt
    value: (template_expr
      (text_segment))))
==================
Inline hash comment after a model value
==================

> model: haiku # fast
@f():
    = `1`

---

(source_file
  (model_directive
    (model_plain_value)
    (line_comment))
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Inline hash comment after an effort value
==================

> effort: low # cheap
@f():
    = `1`

---

(source_file
  (effort_directive
    (effort_plain_value)
    (line_comment))
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Inline hash comment after an approval value
==================

> approval: auto # note
@f():
    = `1`

---

(source_file
  (approval_directive
    (approval_plain_value)
    (line_comment))
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Block comment: #### headings do not swallow code
==================

#### Section 1
@g():
    = `1`
#### Section 2
@h():
    = `2`

---

(source_file
  (line_comment)
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body)))))
  (line_comment)
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Block comment: ### with text is an ordinary comment
==================

### Section 1
@g():
    = `1`
### Section 2
@h():
    = `2`

---

(source_file
  (line_comment)
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body)))))
  (line_comment)
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Block comment: proper ### fence still works
==================

###
@g():
    = `1`
###
@h():
    = `2`

---

(source_file
  (block_comment)
  (procedure_def
    (identifier)
    (block
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Profile directive inside a procedure
==================

@f():
    > profile: reviewer:
        > model: haiku
    = `1`

---

(source_file
  (procedure_def
    (identifier)
    (block
      (profile_directive
        (identifier)
        (profile_body
          (model_directive
            (model_plain_value))))
      (return_stmt
        (inline_python_expr
          (python_inline_body))))))

==================
Literal[01] is rejected (leading zero)
==================

~T(x: Literal[01])
@f():
    = `1`

---

(source_file
  (type_def
    name: (identifier)
    fields: (type_field_list
      (type_field
        name: (identifier)
        type: (type_expr
          (type_apply
            name: (identifier)
            (ERROR
              (type_arg
                (type_number)))
            args: (type_arg
              (type_number)))))))
  (procedure_def
    name: (identifier)
    body: (block
      (return_stmt
        value: (inline_python_expr
          code: (python_inline_body))))))

==================
Stray closer in template is an error: = text >
==================

= text >

---

(source_file
  (return_stmt
    value: (template_expr
      (text_segment))
    (ERROR)))

==================
Stray closer in template is an error: = text ]
==================

= text ]

---

(source_file
  (return_stmt
    value: (template_expr
      (text_segment))
    (ERROR)))

==================
Hyphenated use-directive name is an error: > use: my-profile
==================

> use: my-profile

---

(source_file
  (use_directive
    name: (identifier)
    (ERROR)))
==================
NUL in fenced Python source is an error (return block)
==================

= ```
return " "
```

---

(source_file
  (return_block_stmt
    (ERROR
      (identifier))
    code: (python_code)))

==================
NUL in fenced Python source is an error (top-level block)
==================

```
value = " "
```
= ok

---

(source_file
  (python_block
    (ERROR
      (identifier))
    code: (python_code))
  (return_stmt
    value: (template_expr
      (text_segment))))

==================
NUL in fenced Python source is an error (binding block)
==================

[value: str] = ```
return " "
```

---

(source_file
  (variable_init_block_stmt
    (binding_target
      name: (identifier)
      type: (type_expr
        (type_ref
          name: (identifier))))
    (ERROR
      (identifier))
    code: (python_code)))

==================
NUL in inline Python source is an error
==================

= `" "`

---

(source_file
  (ERROR
    (python_inline_body)))
==================
Double NUL in fenced Python source is an error
==================

= ```
return "  "
```

---

(source_file
  (return_block_stmt
    (ERROR
      (identifier))
    code: (python_code)))
