2016-10-20 16:55:35 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
2017-03-12 13:34:21 -07:00
|
|
|
// Copyright © 2016-2017 Project Golan
|
2016-10-20 16:55:35 -07:00
|
|
|
//
|
2017-03-12 13:34:21 -07:00
|
|
|
// See "LICENSE.lithos3" for more information.
|
2016-10-20 16:55:35 -07:00
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Tokenizer.
|
|
|
|
//
|
|
|
|
// If an x-macro is defined, the file will give info about token names.
|
|
|
|
// Format: (name)
|
|
|
|
// name - Name of the token.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-03-12 13:55:50 -07:00
|
|
|
#include "Lth_libinfo.h"
|
|
|
|
|
2016-10-20 16:55:35 -07:00
|
|
|
#if defined(Lth_X)
|
|
|
|
|
|
|
|
Lth_X(ChrSeq)
|
|
|
|
Lth_X(Identi)
|
|
|
|
Lth_X(Number)
|
|
|
|
Lth_X(Space )
|
|
|
|
Lth_X(String)
|
|
|
|
|
2016-11-20 21:58:32 -08:00
|
|
|
Lth_X(Minus ) // -
|
2016-10-20 16:55:35 -07:00
|
|
|
Lth_X(Dot ) // .
|
|
|
|
Lth_X(Equals) // =
|
|
|
|
Lth_X(Semico) // ;
|
|
|
|
|
|
|
|
Lth_X(BrackO) // [
|
|
|
|
Lth_X(BrackC) // ]
|
2017-04-24 03:17:53 -07:00
|
|
|
Lth_X(BraceO) // {
|
|
|
|
Lth_X(BraceC) // }
|
2016-10-20 16:55:35 -07:00
|
|
|
|
|
|
|
Lth_X(LnEnd ) // \n
|
|
|
|
|
|
|
|
#undef Lth_X
|
|
|
|
|
2017-03-12 13:55:50 -07:00
|
|
|
#elif !defined(lithos3__Lth_token_h) && !LITHOS3_NO_TOKEN
|
2016-10-20 16:55:35 -07:00
|
|
|
#define lithos3__Lth_token_h
|
|
|
|
|
2017-03-12 13:34:21 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-10-20 16:55:35 -07:00
|
|
|
#define Lth_TokenSet(out, tok) \
|
|
|
|
((out)->str = NULL, (out)->type = Lth_TOK_##tok)
|
|
|
|
|
|
|
|
#define Lth_TokenCleanup(out) \
|
|
|
|
((out).str != NULL ? free((out).str) : ((void)0))
|
|
|
|
|
|
|
|
|
2017-04-24 03:17:07 -07:00
|
|
|
// Extern Functions ----------------------------------------------------------|
|
|
|
|
|
|
|
|
void Lth_TokenGet(FILE *fp, struct Lth_Token *out);
|
|
|
|
|
|
|
|
|
2016-10-20 16:55:35 -07:00
|
|
|
// Type Definitions ----------------------------------------------------------|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lth_TokenType
|
|
|
|
//
|
|
|
|
typedef enum Lth_TokenType
|
|
|
|
{
|
|
|
|
Lth_TOK_None,
|
|
|
|
#define Lth_X(name) Lth_TOK_##name,
|
|
|
|
#include "Lth_token.h"
|
|
|
|
Lth_TOK_EOF,
|
|
|
|
Lth_TOK_Max
|
|
|
|
} Lth_TokenType;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Lth_Token
|
|
|
|
//
|
|
|
|
typedef struct Lth_Token
|
|
|
|
{
|
2017-04-24 03:17:07 -07:00
|
|
|
__prop get {call: Lth_TokenGet(__arg, this)}
|
|
|
|
|
2016-10-20 16:55:35 -07:00
|
|
|
Lth_TokenType type;
|
|
|
|
char *str;
|
|
|
|
} Lth_Token;
|
|
|
|
|
|
|
|
|
|
|
|
// Extern Functions ----------------------------------------------------------|
|
|
|
|
|
|
|
|
char const *Lth_TokenName(Lth_TokenType type);
|
|
|
|
|
|
|
|
#endif//lithos3__Lth_token_h
|