//1// gravity_lexer.h2// gravity3//4// Created by Marco Bambini on 30/08/14.5// Copyright (c) 2014 CreoLabs. All rights reserved.6//78#ifndef __GRAVITY_LEXER__9#define __GRAVITY_LEXER__1011#include "gravity_delegate.h"12#include "gravity_token.h"13#include "debug_macros.h"1415/*16Lexer is built in such a way that no memory allocations are necessary during usage17(except for the gravity_lexer_t opaque datatype allocated within gravity_lexer_create).1819Example:20gravity_lexer *lexer = gravity_lexer_create(...);21while (gravity_lexer_next(lexer)) {22// do something here23}24gravity_lexer_free(lexer);2526gravity_lexer_next (and gravity_lexer_peek) returns an int token (gtoken_t)27which represents what has been currently scanned. When EOF is reached TOK_EOF is28returned (with value 0) and the while loop exits.2930In order to have token details, gravity_lexer_token must be called.31In case of a scan error TOK_ERROR is returned and error details can be extracted32from the token itself. In order to be able to not allocate any memory during33tokenization STRINGs and NUMBERs are just sanity checked but not converted.34It is parser responsability to perform the right conversion.3536*/3738// opaque datatype39typedef struct gravity_lexer_t gravity_lexer_t;4041// public functions42gravity_lexer_t *gravity_lexer_create (const char *source, size_t len, uint32_t fileid, bool is_static);43void gravity_lexer_setdelegate (gravity_lexer_t *lexer, gravity_delegate_t *delegate);44void gravity_lexer_free (gravity_lexer_t *lexer);4546gtoken_t gravity_lexer_peek (gravity_lexer_t *lexer);47gtoken_t gravity_lexer_next (gravity_lexer_t *lexer);48gtoken_s gravity_lexer_token (gravity_lexer_t *lexer);49gtoken_s gravity_lexer_token_next (gravity_lexer_t *lexer);50gtoken_t gravity_lexer_token_type (gravity_lexer_t *lexer);51void gravity_lexer_token_dump (gtoken_s token);5253#if GRAVITY_LEXER_DEGUB54void gravity_lexer_debug (gravity_lexer_t *lexer);55#endif5657#endif585960