1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::ops::Range;

use super::*;

#[derive(Debug, PartialEq, Clone)]
pub struct SchemaBlock<'a> {
  pub span_range: SpanRange,
  /// Input source content.
  pub input: &'a str,
  /// Overall description of the project. This is optional. The file must contain one or zero 'Project' block.
  pub project: Option<project::ProjectBlock>,
  /// Table block.
  pub tables: Vec<table::TableBlock>,
  /// TableGroup block.
  pub table_groups: Vec<table_group::TableGroupBlock>,
  /// Ref block.
  pub refs: Vec<refs::RefBlock>,
  /// Enums block.
  pub enums: Vec<enums::EnumBlock>,
}

impl<'a> SchemaBlock<'a> {
  pub fn new(input: &'a str, span_range: Range<usize>) -> Self {
    Self {
      span_range,
      input,
      project: Option::default(),
      tables: Vec::default(),
      table_groups: Vec::default(),
      refs: Vec::default(),
      enums: Vec::default(),
    }
  }

  pub fn print(&self) {
    println!("Project:");

    println!("{:?}\n----", self.project);

    println!("Tables:");

    self
      .tables
      .iter()
      .for_each(|table| println!("{:?}\n----", table));

    println!("TableGroups:");

    self
      .table_groups
      .iter()
      .for_each(|table| println!("{:?}\n----", table));

    println!("Refs:");

    self
      .refs
      .iter()
      .for_each(|table| println!("{:?}\n----", table));

    println!("Enums:");

    self
      .enums
      .iter()
      .for_each(|table| println!("{:?}\n----", table));
  }
}