==================
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
      name: (identifier)
      species: (identifier)
      template: (template_clause (identifier))
      body: (block
        (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
      name: (identifier)
      (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
      name: (identifier)
      (field
        (prose_block
          marker: (prose_marker)
          tag: (identifier)
          content: (prose_content)
          end: (prose_marker)))
      (arc_state
        name: (identifier)
        (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)))
      (arc_state
        name: (identifier)
        (transition
          condition: (expression
            (comparison
              (expression (primary_expression (path (path_segments (identifier)))))
              (expression (primary_expression (boolean)))))
          target: (identifier)))
      (arc_state
        name: (identifier)))))

==================
Schedule with time blocks
==================

schedule DailyRoutine {
    08:00 -> 09:00: breakfast {
        location: kitchen
    }

    09:00 -> 12:00: work {
        duration: 3h
    }
}

---

(source_file
  (declaration
    (schedule
      name: (identifier)
      (schedule_block
        start: (time)
        end: (time)
        activity: (identifier)
        (block
          (field
            name: (dotted_path (identifier))
            value: (value (path (path_segments (identifier)))))))
      (schedule_block
        start: (time)
        end: (time)
        activity: (identifier)
        (block
          (field
            name: (dotted_path (identifier))
            value: (value (duration))))))))

==================
Behavior tree - all node types
==================

behavior GuardBehavior {
    ? {
        patrol
        > {
            detect_threat
            alert(priority: high, "Guard duty")
        }
        * {
            watch
        }
        @base::behaviors::Idle
    }
}

---

(source_file
  (declaration
    (behavior
      name: (identifier)
      root: (behavior_node
        (selector_node
          (behavior_node (action_node (identifier)))
          (behavior_node
            (sequence_node
              (behavior_node (action_node (identifier)))
              (behavior_node
                (action_node
                  (identifier)
                  (action_param
                    (dotted_path (identifier))
                    (value (path (path_segments (identifier)))))
                  (action_param
                    (value (string)))))))
          (behavior_node
            (repeat_node
              (behavior_node (action_node (identifier)))))
          (behavior_node
            (subtree_node
              (path
                (path_segments
                  (identifier)
                  (identifier)
                  (identifier))))))))))

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

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

---

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

==================
Relationship with participants
==================

relationship Friendship {
    Alice {
        bond_strength: 5
    }

    WhiteRabbit as friend {
        trust: 0.8
    }

    Caterpillar
}

---

(source_file
  (declaration
    (relationship
      name: (identifier)
      (participant
        (path (path_segments (identifier)))
        (block
          (field
            name: (dotted_path (identifier))
            value: (value (integer)))))
      (participant
        (path (path_segments (identifier)))
        (identifier)
        (block
          (field
            name: (dotted_path (identifier))
            value: (value (float)))))
      (participant
        (path (path_segments (identifier)))))))

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

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

---

(source_file
  (declaration
    (location
      name: (identifier)
      (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
      name: (identifier)
      (include (identifier))
      (field
        name: (dotted_path (identifier))
        value: (value (boolean)))
      (field
        name: (dotted_path (identifier))
        value: (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
      name: (identifier)
      body: (block
        (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
      name: (identifier)
      (arc_state
        name: (identifier)
        (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)))
      (arc_state
        name: (identifier))
      (arc_state
        name: (identifier)))))

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

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

---

(source_file
  (declaration
    (character
      name: (identifier)
      body: (block
        (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
      name: (identifier)
      body: (block
        (field
          name: (dotted_path
            (identifier)
            (identifier)
            (identifier))
          value: (value (string)))
        (field
          name: (dotted_path
            (identifier)
            (identifier)
            (identifier))
          value: (value (integer)))))))
