2015-06-05 04:09:08 -07:00
|
|
|
/*
|
2015-06-05 21:47:23 -07:00
|
|
|
Copyright (c) 2015 Benjamin Moir <bennyboy.private@hotmail.com.au>
|
2015-06-05 04:09:08 -07:00
|
|
|
Copyright (c) 2015 Marrub <marrub@greyserv.net>
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LOVETOKEN_LT_H
|
|
|
|
#define LOVETOKEN_LT_H
|
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
/*
|
|
|
|
* Includes
|
|
|
|
*/
|
|
|
|
|
2015-06-05 08:14:35 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
/*
|
|
|
|
* Definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
// [marrub] This can be changed if you have either a lot of very
|
|
|
|
// long strings, or a lot of very small strings, for optimization.
|
2015-08-27 06:14:32 -07:00
|
|
|
#define TOKEN_STR_BLOCK_LENGTH 4096
|
2015-06-05 04:09:08 -07:00
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
// [marrub] When using in FFI, remove this from the declarations.
|
2015-06-06 08:05:13 -07:00
|
|
|
// Also make sure to redefine this if your platform is not supported.
|
|
|
|
// (OSX shouldn't need this at all)
|
2015-07-29 05:30:16 -07:00
|
|
|
#ifndef LT_NO_EXPORT
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define LT_DLLEXPORT __declspec(dllexport)
|
|
|
|
#define LT_EXPORT
|
|
|
|
#elif defined(_GCC)
|
|
|
|
#define LT_EXPORT __attribute__((visibility("default")))
|
|
|
|
#define LT_DLLEXPORT
|
|
|
|
#else
|
|
|
|
#define LT_EXPORT
|
|
|
|
#define LT_DLLEXPORT
|
|
|
|
#endif
|
2015-06-06 08:05:13 -07:00
|
|
|
#else
|
|
|
|
#define LT_EXPORT
|
2015-07-29 05:30:16 -07:00
|
|
|
#define LT_DLLEXPORT
|
2015-06-06 08:05:13 -07:00
|
|
|
#endif
|
2015-06-05 04:09:08 -07:00
|
|
|
|
2015-06-11 06:42:36 -07:00
|
|
|
#ifdef __GDCC__
|
2015-07-26 02:36:36 -07:00
|
|
|
#define LT_NO_ICONV
|
2015-06-11 06:42:36 -07:00
|
|
|
#endif
|
|
|
|
|
2015-07-29 04:59:25 -07:00
|
|
|
#define LT_TRUE 1
|
|
|
|
#define LT_FALSE 0
|
|
|
|
|
2015-08-31 07:39:05 -07:00
|
|
|
#define LT_PARSE_NONE 0
|
|
|
|
#define LT_PARSE_FILE 1
|
|
|
|
#define LT_PARSE_STR 2
|
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
enum
|
|
|
|
{
|
2015-06-07 05:02:33 -07:00
|
|
|
TOK_Colon, TOK_Comma, TOK_Div, TOK_Mod, TOK_Mul,
|
|
|
|
TOK_Query, TOK_BraceO, TOK_BraceC, TOK_BrackO, TOK_BrackC,
|
|
|
|
TOK_ParenO, TOK_ParenC, TOK_LnEnd, TOK_Add2, TOK_Add,
|
|
|
|
TOK_And2, TOK_And, TOK_CmpGE, TOK_ShR, TOK_CmpGT,
|
|
|
|
TOK_CmpLE, TOK_ShL, TOK_CmpNE, TOK_CmpLT, TOK_CmpEQ,
|
|
|
|
TOK_Equal, TOK_Not, TOK_OrI2, TOK_OrI, TOK_OrX2,
|
|
|
|
TOK_OrX, TOK_Sub2, TOK_Sub, TOK_String, TOK_Charac,
|
|
|
|
TOK_Number, TOK_Identi, TOK_EOF, TOK_ChrSeq, TOK_Comment,
|
|
|
|
TOK_Period, TOK_Arrow, TOK_Sigil, TOK_Hash, TOK_BlkCmtO,
|
|
|
|
TOK_BlkCmtC,TOK_Exp, TOK_NstCmtO,TOK_NstCmtC, TOK_Semicl
|
2015-06-05 10:38:34 -07:00
|
|
|
};
|
|
|
|
|
2015-06-06 05:12:58 -07:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LTERR_SYNTAX,
|
2015-06-06 18:53:22 -07:00
|
|
|
LTERR_UNKNOWN_OPERATION,
|
|
|
|
LTERR_NOMEMORY
|
2015-06-06 05:12:58 -07:00
|
|
|
};
|
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
/*
|
|
|
|
* Types
|
|
|
|
*/
|
|
|
|
|
2015-07-29 05:30:16 -07:00
|
|
|
typedef int LT_BOOL;
|
|
|
|
|
2015-06-05 04:09:08 -07:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_BOOL escapeChars;
|
|
|
|
LT_BOOL stripInvalid;
|
2015-07-26 02:36:36 -07:00
|
|
|
#ifndef LT_NO_ICONV
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_BOOL doConvert;
|
2015-06-05 08:14:35 -07:00
|
|
|
const char *fromCode;
|
|
|
|
const char *toCode;
|
2015-06-11 06:42:36 -07:00
|
|
|
#endif
|
2015-06-06 07:13:54 -07:00
|
|
|
const char *stringChars;
|
|
|
|
const char *charChars;
|
2015-06-07 00:46:36 -07:00
|
|
|
} LT_Config;
|
2015-06-05 04:09:08 -07:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-06-11 06:05:23 -07:00
|
|
|
const char *token;
|
2015-06-05 04:09:08 -07:00
|
|
|
char *string;
|
2015-08-17 10:42:31 -07:00
|
|
|
unsigned strlen;
|
2015-06-05 04:09:08 -07:00
|
|
|
int pos;
|
|
|
|
} LT_Token;
|
|
|
|
|
2015-06-05 08:14:35 -07:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_BOOL failure;
|
2015-06-05 08:14:35 -07:00
|
|
|
const char *str;
|
|
|
|
} LT_AssertInfo;
|
2015-06-05 04:09:08 -07:00
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
typedef struct LT_GarbageList_s
|
|
|
|
{
|
|
|
|
struct LT_GarbageList_s *next;
|
|
|
|
void *ptr;
|
|
|
|
} LT_GarbageList; // [marrub] Don't include this into FFI declarations.
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions
|
|
|
|
*/
|
|
|
|
|
2015-07-26 03:07:14 -07:00
|
|
|
#ifdef __cplusplus
|
2015-08-17 10:42:31 -07:00
|
|
|
extern "C"
|
|
|
|
{
|
2015-07-26 03:07:14 -07:00
|
|
|
#endif
|
|
|
|
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_Init(LT_Config initCfg);
|
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_SetConfig(LT_Config newCfg);
|
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_Quit(void);
|
2015-06-07 00:46:36 -07:00
|
|
|
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_Assert(LT_BOOL assertion, const char *fmt, ...);
|
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_Error(int type); // [marrub] C use ONLY
|
|
|
|
LT_DLLEXPORT LT_AssertInfo LT_EXPORT LT_CheckAssert(void);
|
2015-06-05 04:09:08 -07:00
|
|
|
|
2015-06-11 06:42:36 -07:00
|
|
|
#ifndef __GDCC__
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_OpenFile(const char *filePath);
|
2015-06-11 06:42:36 -07:00
|
|
|
#else
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_OpenFile(__str filePath);
|
2015-06-11 06:42:36 -07:00
|
|
|
#endif
|
2015-08-31 07:39:05 -07:00
|
|
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_OpenString(const char *str);
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_SetPos(int newPos);
|
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_CloseFile(void);
|
2015-08-31 07:39:05 -07:00
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_CloseString(void);
|
2015-07-29 05:30:16 -07:00
|
|
|
|
|
|
|
LT_DLLEXPORT char *LT_EXPORT LT_ReadNumber(void);
|
2015-08-17 10:42:31 -07:00
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_ReadString(LT_Token *tk, char term);
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT char *LT_EXPORT LT_Escaper(char *str, size_t pos, char escape);
|
|
|
|
LT_DLLEXPORT LT_Token LT_EXPORT LT_GetToken(void);
|
2015-08-24 04:10:25 -07:00
|
|
|
LT_DLLEXPORT char *LT_EXPORT LT_ReadLiteral(void);
|
2015-07-29 05:30:16 -07:00
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_SkipWhite(void);
|
2015-08-24 04:10:25 -07:00
|
|
|
LT_DLLEXPORT void LT_EXPORT LT_SkipWhite2(void);
|
2015-06-05 04:09:08 -07:00
|
|
|
|
2015-07-26 03:07:14 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-05 10:38:34 -07:00
|
|
|
/*
|
|
|
|
* Variables
|
|
|
|
* Don't include these into FFI declarations.
|
|
|
|
*/
|
2015-06-05 04:09:08 -07:00
|
|
|
|
2015-07-26 03:07:14 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" const char *LT_EXPORT LT_TkNames[];
|
|
|
|
#else
|
2015-06-11 06:05:23 -07:00
|
|
|
extern const char *LT_EXPORT LT_TkNames[];
|
2015-07-26 03:07:14 -07:00
|
|
|
#endif
|
2015-06-05 04:09:08 -07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|