==================
Use declaration - simple
==================

use schema::core::Item;

---

(source_file
  (declaration
    (use_declaration
      (path_segments
        (identifier)
        (identifier)
        (identifier)))))

==================
Use declaration - grouped import
==================

use schema::core::{Item1, Item2, Item3};

---

(source_file
  (declaration
    (use_declaration
      (path_segments
        (identifier)
        (identifier))
      (identifier)
      (identifier)
      (identifier))))

==================
Use declaration - wildcard
==================

use schema::beings::*;

---

(source_file
  (declaration
    (use_declaration
      (path_segments
        (identifier)
        (identifier)))))

==================
Character - full featured
==================

character Alice: Human from Curious {
    age: 7
    height: 4.2
    name: "Alice Liddell"
    curious: true
    age_range: 5..10

    ---backstory
    A curious young girl.
    ---
}

---

(source_file
  (declaration
    (character_declaration
      name: (identifier)
      species: (identifier)
      template: (template_clause (identifier))
      body: (character_body
        (field
          name: (dotted_path (identifier))
          value: (value (integer)))
        (field
          name: (dotted_path (identifier))
          value: (value (float)))
        (field
          name: (dotted_path (identifier))
          value: (value (string)))
        (field
          name: (dotted_path (identifier))
          value: (value (boolean)))
        (field
          name: (dotted_path (identifier))
          value: (value (range (integer) (integer))))
        (field
          (prose_block
            marker: (prose_marker)
            tag: (identifier)
            content: (prose_content)
            end: (prose_marker)))))))

==================
Template with includes
==================

template BaseCharacter strict {
    include Physical
    include Mental

    age: 0
    name: ""
}

---

(source_file
  (declaration
    (template_declaration
      name: (identifier)
      body: (template_body
        (include (identifier))
        (include (identifier))
        (field
          name: (dotted_path (identifier))
          value: (value (integer)))
        (field
          name: (dotted_path (identifier))
          value: (value (string)))))))

==================
Life arc with states and transitions
==================

life_arc Journey {
    ---description
    The character's journey.
    ---

    state young {
        on enter {
            age: 5
        }

        on age >= 18 -> adult
    }

    state adult {
        on retire is true -> retired
    }

    state retired {
    }
}

---

(source_file
  (declaration
    (life_arc_declaration
      name: (identifier)
      (field
        (prose_block
          marker: (prose_marker)
          tag: (identifier)
          content: (prose_content)
          end: (prose_marker)))
      (state_block
        name: (identifier)
        body: (state_body
          (on_enter
            (block
              (field
                name: (dotted_path (identifier))
                value: (value (integer)))))
          (transition
            condition: (expression
              (comparison
                (expression (primary_expression (path (path_segments (identifier)))))
                (expression (primary_expression (integer)))))
            target: (identifier))))
      (state_block
        name: (identifier)
        body: (state_body
          (transition
            condition: (expression
              (comparison
                (expression (primary_expression (path (path_segments (identifier)))))
                (expression (primary_expression (boolean)))))
            target: (identifier))))
      (state_block
        name: (identifier)
        body: (state_body)))))

==================
Institution
==================

institution Wonderland {
    type: "fantasy_realm"
    ruler: "Queen of Hearts"
}

---

(source_file
  (declaration
    (institution_declaration
      name: (identifier)
      body: (block
        (field
          name: (dotted_path (identifier))
          value: (value (string)))
        (field
          name: (dotted_path (identifier))
          value: (value (string)))))))

==================
Location
==================

location TeaParty {
    description: "A mad tea party"
    capacity: 10
}

---

(source_file
  (declaration
    (location_declaration
      name: (identifier)
      body: (block
        (field
          name: (dotted_path (identifier))
          value: (value (string)))
        (field
          name: (dotted_path (identifier))
          value: (value (integer)))))))

==================
Species with includes
==================

species Cat {
    include Mammal

    purrs: true
    lives: 9
}

---

(source_file
  (declaration
    (species_declaration
      name: (identifier)
      body: (species_body
        (include (identifier))
        (species_field
          name: (identifier)
          value: (boolean))
        (species_field
          name: (identifier)
          value: (integer))))))

==================
Enum declaration
==================

enum EmotionalState {
    happy, sad, angry, confused, curious
}

---

(source_file
  (declaration
    (enum_declaration
      name: (identifier)
      (identifier)
      (identifier)
      (identifier)
      (identifier)
      (identifier))))

==================
Override syntax
==================

character SpecialAlice {
    base: @Alice {
        remove backstory
        append age_category: "child"
        curious: false
    }
}

---

(source_file
  (declaration
    (character_declaration
      name: (identifier)
      body: (character_body
        (field
          name: (dotted_path (identifier))
          value: (value
            (override
              (path (path_segments (identifier)))
              (override_op (identifier))
              (override_op
                (field
                  name: (dotted_path (identifier))
                  value: (value (string))))
              (override_op
                (field
                  name: (dotted_path (identifier))
                  value: (value (boolean)))))))))))

==================
Complex expressions in conditions
==================

life_arc ComplexLogic {
    state test {
        on self.age > 18 and other.trust >= 0.5 -> trusted
        on not self.valid or self.expired is true -> invalid
    }

    state trusted {
    }

    state invalid {
    }
}

---

(source_file
  (declaration
    (life_arc_declaration
      name: (identifier)
      (state_block
        name: (identifier)
        body: (state_body
          (transition
            condition: (expression
              (and_expression
                (expression
                  (comparison
                    (expression
                      (field_access
                        (expression (primary_expression))
                        (identifier)))
                    (expression (primary_expression (integer)))))
                (expression
                  (comparison
                    (expression
                      (field_access
                        (expression (primary_expression))
                        (identifier)))
                    (expression (primary_expression (float)))))))
            target: (identifier))
          (transition
            condition: (expression
              (or_expression
                (expression
                  (not_expression
                    (expression
                      (field_access
                        (expression (primary_expression))
                        (identifier)))))
                (expression
                  (comparison
                    (expression
                      (field_access
                        (expression (primary_expression))
                        (identifier)))
                    (expression (primary_expression (boolean)))))))
            target: (identifier))))
      (state_block
        name: (identifier)
        body: (state_body))
      (state_block
        name: (identifier)
        body: (state_body)))))

==================
List and object values
==================

character DataRich {
    tags: ["smart", "brave", "curious"]
    stats: {
        strength: 10
        intelligence: 15
    }
    matrix: [[1, 2], [3, 4]]
}

---

(source_file
  (declaration
    (character_declaration
      name: (identifier)
      body: (character_body
        (field
          name: (dotted_path (identifier))
          value: (value
            (list
              (value (string))
              (value (string))
              (value (string)))))
        (field
          name: (dotted_path (identifier))
          value: (value
            (object
              (block
                (field
                  name: (dotted_path (identifier))
                  value: (value (integer)))
                (field
                  name: (dotted_path (identifier))
                  value: (value (integer)))))))
        (field
          name: (dotted_path (identifier))
          value: (value
            (list
              (value
                (list
                  (value (integer))
                  (value (integer))))
              (value
                (list
                  (value (integer))
                  (value (integer)))))))))))

==================
Dotted field paths
==================

character Nested {
    appearance.hair.color: "blonde"
    stats.mental.intelligence: 15
}

---

(source_file
  (declaration
    (character_declaration
      name: (identifier)
      body: (character_body
        (field
          name: (dotted_path
            (identifier)
            (identifier)
            (identifier))
          value: (value (string)))
        (field
          name: (dotted_path
            (identifier)
            (identifier)
            (identifier))
          value: (value (integer)))))))
