aboutsummaryrefslogtreecommitdiffhomepage
path: root/tokenizer.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-21 17:48:35 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-21 17:48:35 -0800
commitf545fb2491d36e02dc6c4005ada86be8678bba78 (patch)
tree3237ef337b1723b24dc32618cc5e03360e30e13e /tokenizer.h
parente73be48d9622d06039926fd2ba4a4b68b675f34a (diff)
Work towards refactoring tokenizer to be a real object
Diffstat (limited to 'tokenizer.h')
-rw-r--r--tokenizer.h47
1 files changed, 23 insertions, 24 deletions
diff --git a/tokenizer.h b/tokenizer.h
index ae6b6ecc..4d4deacc 100644
--- a/tokenizer.h
+++ b/tokenizer.h
@@ -61,11 +61,12 @@ enum tokenizer_error
*/
#define TOK_SQUASH_ERRORS 4
+typedef unsigned int tok_flags_t;
/**
The tokenizer struct.
*/
-struct tokenizer
+struct tokenizer_t
{
/** A pointer into the original string, showing where the next token begins */
const wchar_t *buff;
@@ -100,62 +101,60 @@ struct tokenizer
/** Return the line number of the character at the given offset */
int line_number_of_character_at_offset(size_t offset);
-};
-
-/**
- Initialize the tokenizer. b is the string that is to be
- tokenized. It is not copied, and should not be freed by the caller
- until after the tokenizer is destroyed.
+ /**
+ Constructor for a tokenizer. b is the string that is to be
+ tokenized. It is not copied, and should not be freed by the caller
+ until after the tokenizer is destroyed.
- \param tok The tokenizer to initialize
- \param b The string to tokenize
- \param flags Flags to the tokenizer. Setting TOK_ACCEPT_UNFINISHED will cause the tokenizer
- to accept incomplete tokens, such as a subshell without a closing
- parenthesis, as a valid token. Setting TOK_SHOW_COMMENTS will return comments as tokens
+ \param b The string to tokenize
+ \param flags Flags to the tokenizer. Setting TOK_ACCEPT_UNFINISHED will cause the tokenizer
+ to accept incomplete tokens, such as a subshell without a closing
+ parenthesis, as a valid token. Setting TOK_SHOW_COMMENTS will return comments as tokens
-*/
-void tok_init(tokenizer *tok, const wchar_t *b, int flags);
+ */
+ tokenizer_t(const wchar_t *b, tok_flags_t flags);
+};
/**
Jump to the next token.
*/
-void tok_next(tokenizer *tok);
+void tok_next(tokenizer_t *tok);
/**
Returns the type of the last token. Must be one of the values in the token_type enum.
*/
-int tok_last_type(tokenizer *tok);
+int tok_last_type(tokenizer_t *tok);
/**
Returns the last token string. The string should not be freed by the caller.
*/
-wchar_t *tok_last(tokenizer *tok);
+wchar_t *tok_last(tokenizer_t *tok);
/**
Returns the type of quote from the last TOK_QSTRING
*/
-wchar_t tok_last_quote(tokenizer *tok);
+wchar_t tok_last_quote(tokenizer_t *tok);
/**
Returns true as long as there are more tokens left
*/
-int tok_has_next(tokenizer *tok);
+int tok_has_next(tokenizer_t *tok);
/**
Returns the position of the beginning of the current token in the original string
*/
-int tok_get_pos(tokenizer *tok);
+int tok_get_pos(tokenizer_t *tok);
/**
Destroy the tokenizer and free asociated memory
*/
-void tok_destroy(tokenizer *tok);
+void tok_destroy(tokenizer_t *tok);
/**
Returns the original string to tokenizer
*/
-const wchar_t *tok_string(tokenizer *tok);
+const wchar_t *tok_string(tokenizer_t *tok);
/**
@@ -178,7 +177,7 @@ bool tok_is_string_character(wchar_t c, bool is_first);
/**
Move tokenizer position
*/
-void tok_set_pos(tokenizer *tok, int pos);
+void tok_set_pos(tokenizer_t *tok, int pos);
/**
Returns a string description of the specified token type
@@ -188,7 +187,7 @@ const wchar_t *tok_get_desc(int type);
/**
Get tokenizer error type. Should only be called if tok_last_tope returns TOK_ERROR.
*/
-int tok_get_error(tokenizer *tok);
+int tok_get_error(tokenizer_t *tok);
#endif