These functions will have their first users in upcoming commits.
Signed-off-by: Ben Pfaff <[email protected]>
---
ovn/lib/lex.c | 28 ++++++++++++++++++++++++++++
ovn/lib/lex.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/ovn/lib/lex.c b/ovn/lib/lex.c
index 73f0ca3..fe11b72 100644
--- a/ovn/lib/lex.c
+++ b/ovn/lib/lex.c
@@ -704,6 +704,21 @@ lexer_get(struct lexer *lexer)
return lexer->token.type;
}
+/* Returns the type of the next token that will be fetched by lexer_get(),
+ * without advancing 'lexer->token' to that token. */
+enum lex_type
+lexer_lookahead(const struct lexer *lexer)
+{
+ struct lex_token next;
+ enum lex_type type;
+ const char *start;
+
+ lex_token_parse(&next, lexer->input, &start);
+ type = next.type;
+ lex_token_destroy(&next);
+ return type;
+}
+
/* If 'lexer''s current token has the given 'type', advances 'lexer' to the
* next token and returns true. Otherwise returns false. */
bool
@@ -716,3 +731,16 @@ lexer_match(struct lexer *lexer, enum lex_type type)
return false;
}
}
+
+/* If 'lexer''s current token is the identifier given in 'id', advances 'lexer'
+ * to the next token and returns true. Otherwise returns false. */
+bool
+lexer_match_id(struct lexer *lexer, const char *id)
+{
+ if (lexer->token.type == LEX_T_ID && !strcmp(lexer->token.s, id)) {
+ lexer_get(lexer);
+ return true;
+ } else {
+ return false;
+ }
+}
diff --git a/ovn/lib/lex.h b/ovn/lib/lex.h
index 29e922c..df4db2d 100644
--- a/ovn/lib/lex.h
+++ b/ovn/lib/lex.h
@@ -105,6 +105,8 @@ void lexer_init(struct lexer *, const char *input);
void lexer_destroy(struct lexer *);
enum lex_type lexer_get(struct lexer *);
+enum lex_type lexer_lookahead(const struct lexer *);
bool lexer_match(struct lexer *, enum lex_type);
+bool lexer_match_id(struct lexer *, const char *id);
#endif /* ovn/lex.h */
--
1.7.10.4
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev