Commit 4cd0936c authored by Francis Dupont's avatar Francis Dupont Committed by Tomek Mrugalski

[5014] Syntactic contexts almost done

parent 6d0171d0
...@@ -225,16 +225,16 @@ MapElement object, but does not remove it. ...@@ -225,16 +225,16 @@ MapElement object, but does not remove it.
One another important capability required is the ability to parse not only the One another important capability required is the ability to parse not only the
whole configuration, but a subset of it. This is done by introducing articifical whole configuration, but a subset of it. This is done by introducing articifical
tokens (TOPLEVEL_DHCP6 and TOPLEVEL_GENERIC_JSON). The Parse6Context::parse() method tokens (TOPLEVEL_GENERIC_JSON and TOPLEVEL_DHCP6). The Parse6Context::parse() method
takes one parameter that specifies, whether the data to be parsed is expected takes one parameter that specifies, whether the data to be parsed is expected
to have the whole configuration (DHCP6) or a generic JSON. This is only a to have a generic JSON or the whole configuration (DHCP6). This is only a
proof-of-concept, but similar approach can be implemented to parse only subnets, proof-of-concept, but similar approach can be implemented to parse only subnets,
host reservations, options or basically any other elements. For example, to add host reservations, options or basically any other elements. For example, to add
the ability to parse only pools, the following could be added: the ability to parse only pools, the following could be added:
@code @code
start: TOPLEVEL_DHCP6 syntax_map start: TOPLEVEL_GENERIC_JSON map2
| TOPLEVEL_GENERIC_JSON map2 | TOPLEVEL_DHCP6 syntax_map
| TOPLEVEL_POOL pool_entry; | TOPLEVEL_POOL pool_entry;
@endcode @endcode
......
This diff is collapsed.
This diff is collapsed.
...@@ -89,5 +89,24 @@ Parser6Context::fatal (const std::string& what) ...@@ -89,5 +89,24 @@ Parser6Context::fatal (const std::string& what)
isc_throw(Unexpected, what); isc_throw(Unexpected, what);
} }
void
Parser6Context::enter(const ParserContext& ctx)
{
cstack_.push_back(ctx_);
ctx_ = ctx;
}
void
Parser6Context::leave()
{
#if 1
if (cstack_.empty()) {
fatal("unbalanced syntactic context");
}
#endif
ctx_ = cstack_.back();
cstack_.pop_back();
}
}; };
}; };
...@@ -37,8 +37,8 @@ public: ...@@ -37,8 +37,8 @@ public:
/// @brief Defines currently support the content supported /// @brief Defines currently support the content supported
typedef enum { typedef enum {
PARSER_DHCP6, // This will parse the content as DHCP6 config PARSER_GENERIC_JSON, // This will parse the content as generic JSON
PARSER_GENERIC_JSON // This will parse the content as generic JSON PARSER_DHCP6 // This will parse the content as DHCP6 config
} ParserType; } ParserType;
/// @brief Default constructor. /// @brief Default constructor.
...@@ -95,12 +95,58 @@ public: ...@@ -95,12 +95,58 @@ public:
/// Used by YY_FATAL_ERROR macro so required to be static. /// Used by YY_FATAL_ERROR macro so required to be static.
static void fatal(const std::string& what); static void fatal(const std::string& what);
/// @brief Defines syntactic contexts for lexical tie-ins
typedef enum {
/// at toplevel
NO_KEYWORD,
CONFIG,
/// in config
DHCP6,
// not yet DHCP4,
// not yet DHCP_DDNS,
LOGGING,
/// Dhcp6
INTERFACES_CONFIG,
DATABASE,
MAC_SOURCES,
HOST_RESERVATION_IDENTIFIERS,
HOOKS_LIBRARIES,
SUBNET6,
OPTION_DATA,
CLIENT_CLASSES,
SERVER_ID,
DHCP_DDNS,
/// subnet6
POOLS,
PD_POOLS,
RESERVATIONS,
/// client-classes
CLIENT_CLASS,
/// Logging
LOGGERS,
/// loggers
OUTPUT_OPTIONS
} ParserContext;
/// @brief Current syntactic context
ParserContext ctx_;
/// @brief Enter a new syntactic context
void enter(const ParserContext& ctx);
/// @brief Leave a syntactic context
/// @throw isc::Unexpected if unbalanced
void leave();
private: private:
/// @brief Flag determining scanner debugging. /// @brief Flag determining scanner debugging.
bool trace_scanning_; bool trace_scanning_;
/// @brief Flag determing parser debugging. /// @brief Flag determing parser debugging.
bool trace_parsing_; bool trace_parsing_;
/// @brief Syntactic context stack
std::vector<ParserContext> cstack_;
}; };
}; // end of isc::eval namespace }; // end of isc::eval namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment