Browse Source

replaced boolean trap parameter in the base lexer

jp9000 12 years ago
parent
commit
ed388fc82e
5 changed files with 18 additions and 11 deletions
  1. 1 1
      libobs/util/cf-lexer.c
  2. 8 7
      libobs/util/config-file.c
  3. 2 1
      libobs/util/lexer.c
  4. 6 1
      libobs/util/lexer.h
  5. 1 1
      libobs/util/text-lookup.c

+ 1 - 1
libobs/util/cf-lexer.c

@@ -335,7 +335,7 @@ static bool cf_lexer_nexttoken(struct cf_lexer *lex, struct cf_token *out_token)
 	base_token_clear(&start_token);
 	cf_token_clear(out_token);
 
-	while (lexer_getbasetoken(&lex->base_lexer, &token, false)) {
+	while (lexer_getbasetoken(&lex->base_lexer, &token, PARSE_WHITESPACE)) {
 		/* reclassify underscore as alpha for alnum tokens */
 		if (*token.text.array == '_')
 			token.type = BASETOKEN_ALPHA;

+ 8 - 7
libobs/util/config-file.c

@@ -101,7 +101,7 @@ static bool config_parse_string(struct lexer *lex, struct strref *ref,
 	struct base_token token;
 	base_token_clear(&token);
 
-	while (lexer_getbasetoken(lex, &token, false)) {
+	while (lexer_getbasetoken(lex, &token, PARSE_WHITESPACE)) {
 		if (end) {
 			if (*token.text.array == end) {
 				success = true;
@@ -138,11 +138,11 @@ static void config_parse_section(struct config_section *section,
 {
 	struct base_token token;
 
-	while (lexer_getbasetoken(lex, &token, false)) {
+	while (lexer_getbasetoken(lex, &token, PARSE_WHITESPACE)) {
 		struct strref name, value;
 
 		while (token.type == BASETOKEN_WHITESPACE) {
-			if (!lexer_getbasetoken(lex, &token, false))
+			if (!lexer_getbasetoken(lex, &token, PARSE_WHITESPACE))
 				return;
 		}
 
@@ -150,7 +150,7 @@ static void config_parse_section(struct config_section *section,
 			if (*token.text.array == '#') {
 				do {
 					if (!lexer_getbasetoken(lex, &token,
-					                        false))
+							PARSE_WHITESPACE))
 						return;
 				} while (!is_newline(*token.text.array));
 
@@ -198,17 +198,18 @@ static int config_parse(struct darray *sections, const char *file,
 
 	base_token_clear(&token);
 
-	while (lexer_getbasetoken(&lex, &token, false)) {
+	while (lexer_getbasetoken(&lex, &token, PARSE_WHITESPACE)) {
 		struct config_section *section;
 
 		while (token.type == BASETOKEN_WHITESPACE) {
-			if (!lexer_getbasetoken(&lex, &token, false))
+			if (!lexer_getbasetoken(&lex, &token, PARSE_WHITESPACE))
 				goto complete;
 		}
 
 		if (*token.text.array != '[') {
 			while (!is_newline(*token.text.array)) {
-				if (!lexer_getbasetoken(&lex, &token, false))
+				if (!lexer_getbasetoken(&lex, &token,
+							PARSE_WHITESPACE))
 					goto complete;
 			}
 

+ 2 - 1
libobs/util/lexer.c

@@ -250,11 +250,12 @@ static inline enum base_token_type get_char_token_type(const char ch)
 }
 
 bool lexer_getbasetoken(struct lexer *lex, struct base_token *token,
-		bool ignore_whitespace)
+		enum ignore_whitespace iws)
 {
 	const char *offset = lex->offset;
 	const char *token_start = NULL;
 	enum base_token_type type = BASETOKEN_NONE;
+	bool ignore_whitespace = (iws == IGNORE_WHITESPACE);
 
 	if (!offset)
 		return false;

+ 6 - 1
libobs/util/lexer.h

@@ -280,8 +280,13 @@ static inline void lexer_reset(struct lexer *lex)
 	lex->offset = lex->text;
 }
 
+enum ignore_whitespace {
+	PARSE_WHITESPACE,
+	IGNORE_WHITESPACE
+};
+
 EXPORT bool lexer_getbasetoken(struct lexer *lex, struct base_token *t,
-		bool ignore_whitespace);
+		enum ignore_whitespace iws);
 
 EXPORT void lexer_getstroffset(const struct lexer *lex, const char *str,
 		uint32_t *row, uint32_t *col);

+ 1 - 1
libobs/util/text-lookup.c

@@ -216,7 +216,7 @@ static bool lookup_gettoken(struct lexer *lex, struct strref *str)
 	base_token_clear(&temp);
 	strref_clear(str);
 
-	while (lexer_getbasetoken(lex, &temp, false)) {
+	while (lexer_getbasetoken(lex, &temp, PARSE_WHITESPACE)) {
 		char ch = *temp.text.array;
 
 		if (!str->array) {