Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
4cd0936c
Commit
4cd0936c
authored
Nov 21, 2016
by
Francis Dupont
Committed by
Tomek Mrugalski
Nov 29, 2016
Browse files
[5014] Syntactic contexts almost done
parent
6d0171d0
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp6/dhcp6.dox
View file @
4cd0936c
...
...
@@ -225,16 +225,16 @@ MapElement object, but does not remove it.
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
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
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,
host reservations, options or basically any other elements. For example, to add
the ability to parse only pools, the following could be added:
@code
start: TOPLEVEL_
DHCP6 syntax_
map
| TOPLEVEL_
GENERIC_JSON
map
2
start: TOPLEVEL_
GENERIC_JSON
map
2
| TOPLEVEL_
DHCP6 syntax_
map
| TOPLEVEL_POOL pool_entry;
@endcode
...
...
src/bin/dhcp6/dhcp6_lexer.ll
View file @
4cd0936c
This diff is collapsed.
Click to expand it.
src/bin/dhcp6/dhcp6_parser.yy
View file @
4cd0936c
This diff is collapsed.
Click to expand it.
src/bin/dhcp6/parser_context.cc
View file @
4cd0936c
...
...
@@ -89,5 +89,24 @@ Parser6Context::fatal (const std::string& 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
();
}
};
};
src/bin/dhcp6/parser_context.h
View file @
4cd0936c
...
...
@@ -37,8 +37,8 @@ public:
/// @brief Defines currently support the content supported
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
;
/// @brief Default constructor.
...
...
@@ -95,12 +95,58 @@ public:
/// Used by YY_FATAL_ERROR macro so required to be static.
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:
/// @brief Flag determining scanner debugging.
bool
trace_scanning_
;
/// @brief Flag determing parser debugging.
bool
trace_parsing_
;
/// @brief Syntactic context stack
std
::
vector
<
ParserContext
>
cstack_
;
};
};
// end of isc::eval namespace
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment