1 /* Copyright (c) 2009, 2010 Nicira Networks
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef OVSDB_PARSER_H
17 #define OVSDB_PARSER_H 1
26 char *name; /* Used only in error messages. */
27 struct svec used; /* Already-parsed names from 'object'. */
28 const struct json *json; /* JSON object being parsed. */
29 struct ovsdb_error *error; /* Error signaled, if any. */
32 /* Check that the JSON types make the bitwise tricks below work OK. */
33 BUILD_ASSERT_DECL(JSON_NULL >= 0 && JSON_NULL < 10);
34 BUILD_ASSERT_DECL(JSON_FALSE >= 0 && JSON_FALSE < 10);
35 BUILD_ASSERT_DECL(JSON_TRUE >= 0 && JSON_TRUE < 10);
36 BUILD_ASSERT_DECL(JSON_OBJECT >= 0 && JSON_OBJECT < 10);
37 BUILD_ASSERT_DECL(JSON_ARRAY >= 0 && JSON_ARRAY < 10);
38 BUILD_ASSERT_DECL(JSON_INTEGER >= 0 && JSON_INTEGER < 10);
39 BUILD_ASSERT_DECL(JSON_REAL >= 0 && JSON_REAL < 10);
40 BUILD_ASSERT_DECL(JSON_STRING >= 0 && JSON_STRING < 10);
41 BUILD_ASSERT_DECL(JSON_N_TYPES == 8);
43 enum ovsdb_parser_types {
44 OP_NULL = 1 << JSON_NULL, /* null */
45 OP_FALSE = 1 << JSON_FALSE, /* false */
46 OP_TRUE = 1 << JSON_TRUE, /* true */
47 OP_OBJECT = 1 << JSON_OBJECT, /* {"a": b, "c": d, ...} */
48 OP_ARRAY = 1 << JSON_ARRAY, /* [1, 2, 3, ...] */
49 OP_INTEGER = 1 << JSON_INTEGER, /* 123. */
50 OP_NONINTEGER = 1 << JSON_REAL, /* 123.456. */
51 OP_STRING = 1 << JSON_STRING, /* "..." */
53 OP_BOOLEAN = OP_FALSE | OP_TRUE,
54 OP_NUMBER = OP_INTEGER | OP_NONINTEGER,
56 OP_ID = 1 << JSON_N_TYPES, /* "[_a-zA-Z][_a-zA-Z0-9]*" */
57 OP_OPTIONAL = 1 << (JSON_N_TYPES + 1) /* no value at all */
60 void ovsdb_parser_init(struct ovsdb_parser *, const struct json *,
61 const char *name, ...)
63 const struct json *ovsdb_parser_member(struct ovsdb_parser *, const char *name,
64 enum ovsdb_parser_types);
66 void ovsdb_parser_raise_error(struct ovsdb_parser *parser,
67 const char *format, ...)
69 bool ovsdb_parser_has_error(const struct ovsdb_parser *);
70 struct ovsdb_error *ovsdb_parser_get_error(const struct ovsdb_parser *);
71 struct ovsdb_error *ovsdb_parser_finish(struct ovsdb_parser *)
73 void ovsdb_parser_destroy(struct ovsdb_parser *);
75 bool ovsdb_parser_is_id(const char *string);
77 #endif /* ovsdb-parser.h */