~vladh/peony

peony/src/peony_parser.hpp -rw-r--r-- 1.8 KiB
7fc9922bVlad-Stefan Harbuz changes shaders namespace into class a month ago
                                                                                
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
69
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

#pragma once

#include "types.hpp"

namespace peony_parser {
  constexpr uint32 MAX_N_FILE_ENTRIES = 128;
  constexpr uint32 MAX_N_ENTRY_PROPS = 32;
  constexpr uint32 MAX_N_ARRAY_VALUES = 8;
  constexpr uint32 MAX_TOKEN_LENGTH = 128;

  constexpr const char TOKEN_SPACE = ' ';
  constexpr const char TOKEN_NEWLINE = '\n';
  constexpr const char TOKEN_EQUALS = '=';
  constexpr const char TOKEN_HEADER_START = '>';
  constexpr const char TOKEN_ARRAY_START = '[';
  constexpr const char TOKEN_ARRAY_END = ']';
  constexpr const char TOKEN_OBJECT_START = '{';
  constexpr const char TOKEN_OBJECT_END = '}';
  constexpr const char TOKEN_TUPLE_START = '(';
  constexpr const char TOKEN_TUPLE_END = ')';
  constexpr const char TOKEN_ELEMENT_SEPARATOR = ',';
  constexpr const char TOKEN_COMMENT_START = ';';

  enum class PeonyFilePropValueType {
    unknown, string, boolean, number, vec2, vec3, vec4
  };

  struct PeonyFilePropValue {
    PeonyFilePropValueType type;
    union {
      char string_value[MAX_TOKEN_LENGTH];
      bool32 boolean_value;
      real32 number_value;
      v2 vec2_value;
      v3 vec3_value;
      v4 vec4_value;
    };
  };

  struct PeonyFileProp {
    char name[MAX_TOKEN_LENGTH];
    PeonyFilePropValue values[MAX_N_ARRAY_VALUES];
    uint32 n_values;
  };

  struct PeonyFileEntry {
    char name[MAX_TOKEN_LENGTH];
    PeonyFileProp props[MAX_N_ENTRY_PROPS];
    uint32 n_props;
  };

  struct PeonyFile {
    PeonyFileEntry entries[MAX_N_FILE_ENTRIES];
    uint32 n_entries;
  };

  bool32 parse_file(PeonyFile *pf, char const *path);
}

using peony_parser::PeonyFileEntry,
  peony_parser::PeonyFileProp,
  peony_parser::PeonyFilePropValue,
  peony_parser::PeonyFile;