Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/json/token.h

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 14 окт. 2019 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_FMT_JSON_TOKEN_H_
23 #define LSP_PLUG_IN_FMT_JSON_TOKEN_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/runtime/LSPString.h>
27
28 namespace lsp
29 {
30 namespace json
31 {
32 /**
33 * Low-level JSON tokens
34 */
35 enum token_t
36 {
37 JT_UNKNOWN, // Unknown token
38 JT_ERROR, // Error occurred
39 JT_EOF, // End of input
40
41 JT_LQ_BRACE, // [
42 JT_RQ_BRACE, // ]
43 JT_LC_BRACE, // {
44 JT_RC_BRACE, // }
45 JT_COLON, // :
46 JT_COMMA, // ,
47 JT_SQ_STRING, // 'string'
48 JT_DQ_STRING, // "string"
49 JT_IDENTIFIER, // identifier
50 JT_TRUE, // true
51 JT_FALSE, // false
52 JT_NULL, // null
53 JT_RESERVED, // reserved word
54 JT_SL_COMMENT, // //comment
55 JT_ML_COMMENT, // /* comment */
56 JT_DECIMAL, // 1234
57 JT_HEXADECIMAL, // 0x1234
58 JT_DOUBLE, // 12.34, 1.234e+1
59 };
60
61 /**
62 * JSON versions
63 */
64 enum json_version_t
65 {
66 JSON_LEGACY = 0, //!< JSON_LEGACY legacy JSON, very strict verison
67 JSON_VERSION5 = 5000 //!< JSON_VERSION5 more user-friendly version
68 };
69
70 /**
71 * High-level JSON event types
72 */
73 enum event_type_t
74 {
75 JE_OBJECT_START, // Start of object - {
76 JE_OBJECT_END, // End of object - }
77 JE_ARRAY_START, // Start of array - [
78 JE_ARRAY_END, // End of array - ]
79 JE_PROPERTY, // Property - "key":
80 JE_STRING, // "String value"
81 JE_INTEGER, // Integer value - 123, 0x123
82 JE_DOUBLE, // Floating-point value
83 JE_BOOL, // Boolean value
84 JE_NULL, // Null value
85
86 JE_UNKNOWN = -1 // Unknown event
87 };
88
89 /**
90 * JSON event
91 */
92 typedef struct event_t
93 {
94 event_type_t type;
95 LSPString sValue;
96 union
97 {
98 bool bValue;
99 ssize_t iValue;
100 double fValue;
101 };
102 } event_t;
103
104 /**
105 * JSON serialization flags
106 */
107 typedef struct serial_flags_t
108 {
109 json_version_t version; // Json version
110 bool identifiers; // Prefer identifiers over strings (at least JSON5)
111 lsp_wchar_t ident; // Identation character
112 size_t padding; // Number of characters for identation
113 bool separator; // Add space separator after colons and commas in objects
114 bool multiline; // Use newline characters (multiline output)
115 const char *fmt_double; // Double value format, "%f" by default
116 } serial_flags_t;
117
118 /**
119 * Initialize default serialization flags
120 *
121 * @param dst object to initialize
122 */
123 void init_serial_flags(serial_flags_t *dst);
124
125 } /* namespace json */
126 } /* namespace lsp */
127
128 #endif /* LSP_PLUG_IN_FMT_JSON_TOKEN_H_ */