[ovs-dev] [PATCH 02/10] lex: Make lexer_force_match() work for LEX_T_END.
Ben Pfaff
blp at ovn.org
Fri Jan 20 17:16:24 UTC 2017
Without this change, lexer_force_match(lex, LEX_T_END) mostly works, except
that in the failure case it emits an error that says "expecting `$'",
which is a surprising error message.
Arguably, lexer_force_end() could be removed entirely, but I don't see a
real problem with the existing arrangement.
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
include/ovn/lex.h | 4 ++--
ovn/lib/lex.c | 13 +++++++++----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/include/ovn/lex.h b/include/ovn/lex.h
index 0876d1b..afa4a23 100644
--- a/include/ovn/lex.h
+++ b/include/ovn/lex.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -139,7 +139,7 @@ bool lexer_is_int(const struct lexer *);
bool lexer_get_int(struct lexer *, int *value);
bool lexer_force_int(struct lexer *, int *value);
-void lexer_force_end(struct lexer *);
+bool lexer_force_end(struct lexer *);
void lexer_error(struct lexer *, const char *message, ...)
OVS_PRINTF_FORMAT(2, 3);
diff --git a/ovn/lib/lex.c b/ovn/lib/lex.c
index d64ce83..4b504cb 100644
--- a/ovn/lib/lex.c
+++ b/ovn/lib/lex.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -856,7 +856,9 @@ lexer_match(struct lexer *lexer, enum lex_type type)
bool
lexer_force_match(struct lexer *lexer, enum lex_type t)
{
- if (lexer_match(lexer, t)) {
+ if (t == LEX_T_END) {
+ return lexer_force_end(lexer);
+ } else if (lexer_match(lexer, t)) {
return true;
} else {
struct lex_token token = { .type = t };
@@ -915,11 +917,14 @@ lexer_force_int(struct lexer *lexer, int *value)
return ok;
}
-void
+bool
lexer_force_end(struct lexer *lexer)
{
- if (lexer->token.type != LEX_T_END) {
+ if (lexer->token.type == LEX_T_END) {
+ return true;
+ } else {
lexer_syntax_error(lexer, "expecting end of input");
+ return false;
}
}
--
2.10.2
More information about the dev
mailing list