aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tokenizer.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-07-25 23:05:47 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-07-25 23:05:47 -0700
commit618896c0436e6ca70feb2fa317b34171cc4e1a81 (patch)
tree4f6d8130f52fe7c9523e034ab85fe3b49fd0ea0b /src/tokenizer.h
parent0dbd83ffaf571dce9b1e8449c28e3ae0040d4e75 (diff)
Early reworking of tokenizer interface
Diffstat (limited to 'src/tokenizer.h')
-rw-r--r--src/tokenizer.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/tokenizer.h b/src/tokenizer.h
index f5f0455d..14e648fd 100644
--- a/src/tokenizer.h
+++ b/src/tokenizer.h
@@ -36,6 +36,7 @@ enum token_type
*/
enum tokenizer_error
{
+ TOK_ERROR_NONE,
TOK_UNTERMINATED_QUOTE,
TOK_UNTERMINATED_SUBSHELL,
TOK_UNTERMINATED_ESCAPE,
@@ -67,6 +68,26 @@ enum tokenizer_error
typedef unsigned int tok_flags_t;
+struct tok_t
+{
+ /* The text of the token, or an error message for type error */
+ wcstring text;
+
+ /* The type of the token */
+ token_type type;
+
+ /* Offset of the token */
+ size_t offset;
+
+ /* Length of the token */
+ size_t length;
+
+ /* If an error, this is the error code */
+ enum tokenizer_error error;
+
+ tok_t() : type(TOK_NONE), offset(-1), length(-1), error(TOK_ERROR_NONE) {}
+};
+
/**
The tokenizer struct.
*/
@@ -93,7 +114,7 @@ struct tokenizer_t
/** Whether all blank lines are returned */
bool show_blank_lines;
/** Last error */
- int error;
+ tokenizer_error error;
/* Whether we are squashing errors */
bool squash_errors;
@@ -112,6 +133,9 @@ struct tokenizer_t
*/
tokenizer_t(const wchar_t *b, tok_flags_t flags);
+
+ /** Returns the next token by reference. Returns true if we got one, false if we're at the end. */
+ bool next(struct tok_t *result);
};
/**