Commit 7b0d7c25 authored by Francis Dupont's avatar Francis Dupont

[5036] Improved parser and include files

parent a3ca4ab1
......@@ -295,7 +295,7 @@ unknown_map_entry: STRING COLON {
const std::string& keyword = $1;
error(@1,
"got unexpected keyword \"" + keyword + "\" in " + where + " map.");
}
};
// This defines the top-level { } that holds Dhcp6, Dhcp4, DhcpDdns or Logging
......@@ -620,10 +620,12 @@ sub_hooks_library: LCURLY_BRACKET {
hooks_params: hooks_param
| hooks_params COMMA hooks_param
| unknown_map_entry
;
hooks_param: library
| parameters;
| parameters
;
library: LIBRARY {
ctx.enter(ctx.NO_KEYWORD);
......@@ -638,7 +640,7 @@ parameters: PARAMETERS {
} COLON value {
ctx.stack_.back()->set("parameters", $4);
ctx.leave();
}
};
// --- expired-leases-processing ------------------------
expired_leases_processing: EXPIRED_LEASES_PROCESSING {
......@@ -661,7 +663,7 @@ expired_leases_params: expired_leases_param
expired_leases_param: STRING COLON INTEGER {
ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set($1, value);
}
};
// --- subnet6 ------------------------------------------
// This defines subnet6 as a list of maps.
......@@ -1107,12 +1109,12 @@ pd_prefix: PREFIX {
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("prefix", prf);
ctx.leave();
}
};
pd_prefix_len: PREFIX_LEN COLON INTEGER {
ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("prefix-len", prf);
}
};
excluded_prefix: EXCLUDED_PREFIX {
ctx.enter(ctx.NO_KEYWORD);
......@@ -1120,17 +1122,17 @@ excluded_prefix: EXCLUDED_PREFIX {
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("excluded-prefix", prf);
ctx.leave();
}
};
excluded_prefix_len: EXCLUDED_PREFIX_LEN COLON INTEGER {
ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("excluded-prefix-len", prf);
}
};
pd_delegated_len: DELEGATED_LEN COLON INTEGER {
ElementPtr deleg(new IntElement($3, ctx.loc2pos(@3)));
ctx.stack_.back()->set("delegated-len", deleg);
}
};
// --- end of pd-pools ---------------------------------------
......@@ -1230,7 +1232,7 @@ hostname: HOSTNAME {
ElementPtr host(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("hostname", host);
ctx.leave();
}
};
reservation_client_classes: CLIENT_CLASSES {
ElementPtr c(new ListElement(ctx.loc2pos(@1)));
......@@ -1310,7 +1312,7 @@ client_class_test: TEST {
ElementPtr test(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("test", test);
ctx.leave();
}
};
// --- end of client classes ---------------------------------
......
......@@ -39,13 +39,14 @@ public:
/// @brief Defines currently supported scopes
///
/// Dhcp6Parser is able to parse several types of scope. Usually, when it
/// parses a config file, it expects the data to have a map with Dhcp6 in it
/// and all the parameters within that Dhcp6 map. However, sometimes the
/// parser is expected to parse only a subset of that information. For example,
/// it may be asked to parse a structure that is host-reservation only, without
/// the global 'Dhcp6' or 'reservations' around it. In such case the parser
/// is being told to start parsing as SUBPARSER_HOST_RESERVATION6.
/// Dhcp6Parser is able to parse several types of scope. Usually,
/// when it parses a config file, it expects the data to have a map
/// with Dhcp6 in it and all the parameters within that Dhcp6 map.
/// However, sometimes the parser is expected to parse only a subset
/// of that information. For example, it may be asked to parse
/// a structure that is host-reservation only, without the global
/// 'Dhcp6' or 'reservations' around it. In such case the parser
/// is being told to start parsing as PARSER_HOST_RESERVATION6.
typedef enum {
/// This parser will parse the content as generic JSON.
PARSER_JSON,
......@@ -60,15 +61,15 @@ public:
/// contents of it.
SUBPARSER_DHCP6,
/// This will parse the input as interfaces content.
PARSER_INTERFACES,
/// This will parse the input as Subnet6 content.
PARSER_SUBNET6,
/// This will parse the input as pool6 content.
PARSER_POOL6,
/// This will parse the input as interfaces content.
PARSER_INTERFACES,
/// This will parse the input as pd-pool content.
PARSER_PD_POOL,
......@@ -95,15 +96,24 @@ public:
std::vector<isc::data::ElementPtr> stack_;
/// @brief Method called before scanning starts on a string.
///
/// @param str string to be parsed
/// @param parser_type specifies expected content
void scanStringBegin(const std::string& str, ParserType type);
/// @brief Method called before scanning starts on a file.
void scanFileBegin(FILE * f, const std::string& filename, ParserType type);
///
/// @param f stdio FILE pointer
/// @param filename file to be parsed
/// @param parser_type specifies expected content
void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
/// @brief Method called after the last tokens are scanned.
void scanEnd();
/// @brief Divert input to an include file.
///
/// @param filename file to be included
void includeFile(const std::string& filename);
/// @brief Run the parser on the string specified.
......@@ -136,25 +146,33 @@ public:
///
/// @param loc location within the parsed file when experienced a problem.
/// @param what string explaining the nature of the error.
/// @throw Dhcp6ParseError
void error(const isc::dhcp::location& loc, const std::string& what);
/// @brief Error handler
///
/// This is a simplified error reporting tool for possible future
/// cases when the Dhcp6Parser is not able to handle the packet.
///
/// @param what string explaining the nature of the error.
/// @throw Dhcp6ParseError
void error(const std::string& what);
/// @brief Fatal error handler
///
/// This is for should not happen but fatal errors.
/// Used by YY_FATAL_ERROR macro so required to be static.
///
/// @param what string explaining the nature of the error.
/// @throw Dhcp6ParseError
static void fatal(const std::string& what);
/// @brief Converts bison's position to one understandable by isc::data::Element
///
/// Convert a bison location into an element position
/// (take the begin, the end is lost)
/// @brief loc location in bison format
///
/// @param loc location in bison format
/// @return Position in format accepted by Element
isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
......@@ -178,12 +196,12 @@ public:
/// Used while parsing Dhcp6/interfaces structures.
INTERFACES_CONFIG,
/// Used while parsing Dhcp6/hosts-database structures.
HOSTS_DATABASE,
/// Used while parsing Dhcp6/lease-database structures.
LEASE_DATABASE,
/// Used while parsing Dhcp6/hosts-database structures.
HOSTS_DATABASE,
/// Used while parsing Dhcp6/mac-sources structures.
MAC_SOURCES,
......@@ -275,13 +293,17 @@ public:
/// will return STRING token if in JSON mode or RENEW_TIMER if
/// in DHCP6 mode. Finally, the stntactic context allows the
/// error message to be more descriptive.
///
/// @param ctx the syntactic context to enter into
void enter(const ParserContext& ctx);
/// @brief Leave a syntactic context
///
/// @throw isc::Unexpected if unbalanced
void leave();
/// @brief Get the syntactix context name
///
/// @return printable name of the context.
const std::string contextName();
......@@ -296,6 +318,8 @@ public:
std::vector<ParserContext> cstack_;
/// @brief Common part of parseXXX
///
/// @return Element structure representing parsed text.
isc::data::ConstElementPtr parseCommon();
};
......
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