Merge branch 'master' of https://github.com/hyzboy/CMUtil
This commit is contained in:
commit
1710fd4ba8
@ -1 +1 @@
|
||||
Subproject commit ed3484270fe45140e2d8858426472404b1f0ae6a
|
||||
Subproject commit c0bfb97ddd8d3beb7912b877b6a4278148b2a0a4
|
@ -1 +1 @@
|
||||
Subproject commit a3c8642886b348d4f8fcb5384266c3a94ffe66b3
|
||||
Subproject commit 3beb37ea14aec1bdce1a6d542dc464d00f4a6cec
|
156
inc/hgl/util/Tokenizer/Tokenizer.h
Normal file
156
inc/hgl/util/Tokenizer/Tokenizer.h
Normal file
@ -0,0 +1,156 @@
|
||||
enum class TokenType
|
||||
{
|
||||
Unrecognized=0,
|
||||
|
||||
End,
|
||||
|
||||
WhiteSpace, // ' ','\t','\r','\n'
|
||||
OnelineComment, // //
|
||||
MultilineComment, // /* */
|
||||
|
||||
// Atoms
|
||||
Identifier, // abc123
|
||||
Integer, // 1234
|
||||
Float, // 12.34
|
||||
String, // "123"
|
||||
RawString, // """text"""
|
||||
|
||||
// Math operators
|
||||
Plus, // +
|
||||
Minus, // -
|
||||
Star, // *
|
||||
Slash, // /
|
||||
Percent, // %
|
||||
|
||||
Handle, // #
|
||||
At, // @
|
||||
|
||||
AddAssign, // +=
|
||||
SubAssign, // -=
|
||||
MulAssign, // *=
|
||||
DivAssign, // /=
|
||||
ModAssign, // %=
|
||||
|
||||
OrAssign, // |=
|
||||
AndAssign, // &=
|
||||
XorAssign, // ^=
|
||||
ShiftLeftAssign, // <<=
|
||||
ShiftRightAssign, // >>=
|
||||
|
||||
Inc, // ++
|
||||
Dec, // --
|
||||
|
||||
Dot, // .
|
||||
|
||||
// Statement tokens
|
||||
Assignment, // =
|
||||
EndStatement, // ;
|
||||
ListSeparator, // ,
|
||||
StartStatementBlock,// {
|
||||
EndStatementBlock, // }
|
||||
OpenParanthesis, // (
|
||||
CloseParanthesis, // )
|
||||
OpenBracket, // [
|
||||
CloseBracket, // ]
|
||||
Amp, // &
|
||||
|
||||
Not, // !
|
||||
Or, // ||
|
||||
And, // &&
|
||||
Xor, // ^^
|
||||
|
||||
// Bitwise operators
|
||||
BitOr, // |
|
||||
BitNot, // ~
|
||||
BitXor, // ^
|
||||
BitShiftLeft, // <<
|
||||
BitShiftRight, // >>
|
||||
|
||||
// Compare operators
|
||||
Equal, // ==
|
||||
NotEqual, // !=
|
||||
LessThan, // <
|
||||
GreaterThan, // >
|
||||
LessThanOrEqual, // <=
|
||||
GreaterThanOrEqual, // >=
|
||||
|
||||
Question, // ?
|
||||
Colon, // :
|
||||
};//
|
||||
|
||||
struct TokenWord
|
||||
{
|
||||
const char *word;
|
||||
uint work_size;
|
||||
uint token_type;
|
||||
};
|
||||
|
||||
constexpr TokenWord token_words[]=
|
||||
{
|
||||
#define DEFINE_TOKEN(str,type) {str,sizeof(str)-1,uint(TokenType::type)}
|
||||
|
||||
DEFINE_TOKEN("+", Plus),
|
||||
DEFINE_TOKEN("-", Minus),
|
||||
DEFINE_TOKEN("*", Star),
|
||||
DEFINE_TOKEN("/", Slash),
|
||||
DEFINE_TOKEN("%", Percent),
|
||||
DEFINE_TOKEN("=", Assignment),
|
||||
DEFINE_TOKEN(".", Dot),
|
||||
DEFINE_TOKEN("+=", AddAssign),
|
||||
DEFINE_TOKEN("-=", SubAssign),
|
||||
DEFINE_TOKEN("*=", MulAssign),
|
||||
DEFINE_TOKEN("/=", DivAssign),
|
||||
DEFINE_TOKEN("%=", ModAssign),
|
||||
DEFINE_TOKEN("|=", OrAssign),
|
||||
DEFINE_TOKEN("&=", AndAssign),
|
||||
DEFINE_TOKEN("^=", XorAssign),
|
||||
DEFINE_TOKEN("<<=", ShiftLeftAssign),
|
||||
DEFINE_TOKEN(">>=", ShiftRightAssign),
|
||||
DEFINE_TOKEN("|", BitOr),
|
||||
DEFINE_TOKEN("~", BitNot),
|
||||
DEFINE_TOKEN("^", BitXor),
|
||||
DEFINE_TOKEN("<<", BitShiftLeft),
|
||||
DEFINE_TOKEN(">>", BitShiftRight),
|
||||
DEFINE_TOKEN(";", EndStatement),
|
||||
DEFINE_TOKEN(",", ListSeparator),
|
||||
DEFINE_TOKEN("{", StartStatementBlock),
|
||||
DEFINE_TOKEN(")", EndStatementBlock),
|
||||
DEFINE_TOKEN("(", OpenParanthesis),
|
||||
DEFINE_TOKEN(")", CloseParanthesis),
|
||||
DEFINE_TOKEN("[", OpenBracket),
|
||||
DEFINE_TOKEN("]", CloseBracket),
|
||||
DEFINE_TOKEN("?", Question),
|
||||
DEFINE_TOKEN(":", Colon),
|
||||
DEFINE_TOKEN("==", Equal),
|
||||
DEFINE_TOKEN("!=", NotEqual),
|
||||
DEFINE_TOKEN("<", LessThan),
|
||||
DEFINE_TOKEN(">", GreaterThan),
|
||||
DEFINE_TOKEN("<=", LessThanOrEqual),
|
||||
DEFINE_TOKEN(">=", GreaterThanOrEqual),
|
||||
DEFINE_TOKEN("++", Inc),
|
||||
DEFINE_TOKEN("--", Dec),
|
||||
DEFINE_TOKEN("&", Amp),
|
||||
DEFINE_TOKEN("!", Not),
|
||||
DEFINE_TOKEN("||", Or),
|
||||
DEFINE_TOKEN("&&", And),
|
||||
DEFINE_TOKEN("^^", Xor),
|
||||
DEFINE_TOKEN("#", Handle),
|
||||
DEFINE_TOKEN("@", At)
|
||||
|
||||
#undef DEFINE_TOKEN
|
||||
};
|
||||
|
||||
constexpr uint TokenWordsNumber =sizeof(token_words)/sizeof(TokenWord);
|
||||
constexpr char WhiteSpaces[] =" \t\r\n";
|
||||
constexpr uint WhiteSpacesNumber =sizeof(WhiteSpaces)-1;
|
||||
|
||||
/**
|
||||
* 通用词法解析器
|
||||
*/
|
||||
class Tokenizer
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
};//class Tokenizer
|
@ -8,4 +8,6 @@ macro(CMUtilSetup source_path)
|
||||
set(CMUTIL_ROOT_3RDPTY_PATH ${source_path}/3rdpty)
|
||||
|
||||
include_directories(${CMUTIL_ROOT_INCLUDE_PATH})
|
||||
include_directories(${CMUTIL_ROOT_3RDPTY_PATH}/jsoncpp/include)
|
||||
endmacro()
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace hgl
|
||||
Json::CharReaderBuilder builder;
|
||||
Json::CharReader *reader=builder.newCharReader();
|
||||
|
||||
Json::String errs;
|
||||
JSONCPP_STRING errs;
|
||||
|
||||
const bool result=reader->parse(txt,txt+size,&root,&errs);
|
||||
|
||||
@ -75,7 +75,7 @@ namespace hgl
|
||||
int SaveJson(Json::Value &root,const OSString &filename,OSString &error_info)
|
||||
{
|
||||
UTF8String txt;
|
||||
|
||||
|
||||
if(!JsonToString(root,txt,error_info))
|
||||
return(false);
|
||||
|
||||
@ -83,7 +83,7 @@ namespace hgl
|
||||
|
||||
if(result!=txt.Length())
|
||||
{
|
||||
error_info=OS_TEXT("[ERROR][SaveJson] Save file failed, only write ")+OSString(result)+OS_TEXT("/")+OSString(txt.Length());
|
||||
error_info=OS_TEXT("[ERROR][SaveJson] Save file failed, only write ")+OSString::valueOf(result)+OS_TEXT("/")+OSString::valueOf(txt.Length());
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//取名为XMLParseClass是为了避免与expat的xmlparse.c编译造成obj冲突
|
||||
//取名为XMLParseClass是为了避免与expat的xmlparse.c编译造成obj冲突
|
||||
|
||||
#include<hgl/util/xml/XMLParse.h>
|
||||
#include<hgl/io/FileInputStream.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user