mirror of https://github.com/x64dbg/btparser
formatting
This commit is contained in:
parent
90eed9913a
commit
d5034cf6d6
|
@ -51,7 +51,7 @@ namespace StringUtils
|
||||||
case '\"':
|
case '\"':
|
||||||
return "\\\"";
|
return "\\\"";
|
||||||
default:
|
default:
|
||||||
if(!isprint(ch)) //unknown unprintable character
|
if(!isprint(ch)) //unknown unprintable character
|
||||||
sprintf_s(buf, "\\x%02X", ch);
|
sprintf_s(buf, "\\x%02X", ch);
|
||||||
else
|
else
|
||||||
*buf = ch;
|
*buf = ch;
|
||||||
|
|
|
@ -126,11 +126,11 @@ Lexer::Token Lexer::getToken()
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
nextChar();
|
nextChar();
|
||||||
if(mLastChar == EOF) //end of file
|
if(mLastChar == EOF) //end of file
|
||||||
return reportError("unexpected end of file in character literal (1)");
|
return reportError("unexpected end of file in character literal (1)");
|
||||||
if(mLastChar == '\r' || mLastChar == '\n')
|
if(mLastChar == '\r' || mLastChar == '\n')
|
||||||
return reportError("unexpected newline in character literal (1)");
|
return reportError("unexpected newline in character literal (1)");
|
||||||
if(mLastChar == '\'') //end of character literal
|
if(mLastChar == '\'') //end of character literal
|
||||||
{
|
{
|
||||||
if(charLit.length() != 1)
|
if(charLit.length() != 1)
|
||||||
return reportError(StringUtils::sprintf("invalid character literal '%s'", charLit.c_str()));
|
return reportError(StringUtils::sprintf("invalid character literal '%s'", charLit.c_str()));
|
||||||
|
@ -138,7 +138,7 @@ Lexer::Token Lexer::getToken()
|
||||||
nextChar();
|
nextChar();
|
||||||
return tok_charlit;
|
return tok_charlit;
|
||||||
}
|
}
|
||||||
if(mLastChar == '\\') //escape sequence
|
if(mLastChar == '\\') //escape sequence
|
||||||
{
|
{
|
||||||
nextChar();
|
nextChar();
|
||||||
if(mLastChar == EOF)
|
if(mLastChar == EOF)
|
||||||
|
@ -163,7 +163,7 @@ Lexer::Token Lexer::getToken()
|
||||||
mLastChar = '\v';
|
mLastChar = '\v';
|
||||||
else if(mLastChar == '0')
|
else if(mLastChar == '0')
|
||||||
mLastChar = '\0';
|
mLastChar = '\0';
|
||||||
else if(mLastChar == 'x') //\xHH
|
else if(mLastChar == 'x') //\xHH
|
||||||
{
|
{
|
||||||
auto ch1 = nextChar();
|
auto ch1 = nextChar();
|
||||||
auto ch2 = nextChar();
|
auto ch2 = nextChar();
|
||||||
|
@ -195,16 +195,16 @@ Lexer::Token Lexer::getToken()
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
nextChar();
|
nextChar();
|
||||||
if(mLastChar == EOF) //end of file
|
if(mLastChar == EOF) //end of file
|
||||||
return reportError("unexpected end of file in string literal (1)");
|
return reportError("unexpected end of file in string literal (1)");
|
||||||
if(mLastChar == '\r' || mLastChar == '\n')
|
if(mLastChar == '\r' || mLastChar == '\n')
|
||||||
return reportError("unexpected newline in string literal (1)");
|
return reportError("unexpected newline in string literal (1)");
|
||||||
if(mLastChar == '\"') //end of string literal
|
if(mLastChar == '\"') //end of string literal
|
||||||
{
|
{
|
||||||
nextChar();
|
nextChar();
|
||||||
return tok_stringlit;
|
return tok_stringlit;
|
||||||
}
|
}
|
||||||
if(mLastChar == '\\') //escape sequence
|
if(mLastChar == '\\') //escape sequence
|
||||||
{
|
{
|
||||||
nextChar();
|
nextChar();
|
||||||
if(mLastChar == EOF)
|
if(mLastChar == EOF)
|
||||||
|
@ -229,7 +229,7 @@ Lexer::Token Lexer::getToken()
|
||||||
mLastChar = '\v';
|
mLastChar = '\v';
|
||||||
else if(mLastChar == '0')
|
else if(mLastChar == '0')
|
||||||
mLastChar = '\0';
|
mLastChar = '\0';
|
||||||
else if(mLastChar == 'x') //\xHH
|
else if(mLastChar == 'x') //\xHH
|
||||||
{
|
{
|
||||||
auto ch1 = nextChar();
|
auto ch1 = nextChar();
|
||||||
auto ch2 = nextChar();
|
auto ch2 = nextChar();
|
||||||
|
@ -255,11 +255,11 @@ Lexer::Token Lexer::getToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
//identifier/keyword
|
//identifier/keyword
|
||||||
if(isalpha(mLastChar) || mLastChar == '_') //[a-zA-Z_]
|
if(isalpha(mLastChar) || mLastChar == '_') //[a-zA-Z_]
|
||||||
{
|
{
|
||||||
mState.IdentifierStr = mLastChar;
|
mState.IdentifierStr = mLastChar;
|
||||||
nextChar();
|
nextChar();
|
||||||
while(isalnum(mLastChar) || mLastChar == '_') //[0-9a-zA-Z_]
|
while(isalnum(mLastChar) || mLastChar == '_') //[0-9a-zA-Z_]
|
||||||
{
|
{
|
||||||
appendCh(mState.IdentifierStr, mLastChar);
|
appendCh(mState.IdentifierStr, mLastChar);
|
||||||
nextChar();
|
nextChar();
|
||||||
|
@ -274,15 +274,15 @@ Lexer::Token Lexer::getToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
//hex numbers
|
//hex numbers
|
||||||
if(mLastChar == '0' && peekChar() == 'x') //0x
|
if(mLastChar == '0' && peekChar() == 'x') //0x
|
||||||
{
|
{
|
||||||
nextChar(); //consume the 'x'
|
nextChar(); //consume the 'x'
|
||||||
mNumStr.clear();
|
mNumStr.clear();
|
||||||
|
|
||||||
while(isxdigit(nextChar())) //[0-9a-fA-F]*
|
while(isxdigit(nextChar())) //[0-9a-fA-F]*
|
||||||
appendCh(mNumStr, mLastChar);
|
appendCh(mNumStr, mLastChar);
|
||||||
|
|
||||||
if(!mNumStr.length()) //check for error condition
|
if(!mNumStr.length()) //check for error condition
|
||||||
return reportError("no hex digits after \"0x\" prefix");
|
return reportError("no hex digits after \"0x\" prefix");
|
||||||
|
|
||||||
auto error = convertNumber(mNumStr.c_str(), mState.NumberVal, 16);
|
auto error = convertNumber(mNumStr.c_str(), mState.NumberVal, 16);
|
||||||
|
@ -291,11 +291,11 @@ Lexer::Token Lexer::getToken()
|
||||||
mIsHexNumberVal = true;
|
mIsHexNumberVal = true;
|
||||||
return tok_number;
|
return tok_number;
|
||||||
}
|
}
|
||||||
if(isdigit(mLastChar)) //[0-9]
|
if(isdigit(mLastChar)) //[0-9]
|
||||||
{
|
{
|
||||||
mNumStr = mLastChar;
|
mNumStr = mLastChar;
|
||||||
|
|
||||||
while(isdigit(nextChar())) //[0-9]*
|
while(isdigit(nextChar())) //[0-9]*
|
||||||
mNumStr += mLastChar;
|
mNumStr += mLastChar;
|
||||||
|
|
||||||
auto error = convertNumber(mNumStr.c_str(), mState.NumberVal, 10);
|
auto error = convertNumber(mNumStr.c_str(), mState.NumberVal, 10);
|
||||||
|
@ -306,7 +306,7 @@ Lexer::Token Lexer::getToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
//comments
|
//comments
|
||||||
if(mLastChar == '/' && peekChar() == '/') //line comment
|
if(mLastChar == '/' && peekChar() == '/') //line comment
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -318,7 +318,7 @@ Lexer::Token Lexer::getToken()
|
||||||
|
|
||||||
return getToken(); //interpret the next line
|
return getToken(); //interpret the next line
|
||||||
}
|
}
|
||||||
if(mLastChar == '/' && peekChar() == '*') //block comment
|
if(mLastChar == '/' && peekChar() == '*') //block comment
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,7 @@ Lexer::Token Lexer::getToken()
|
||||||
}
|
}
|
||||||
while(!(mLastChar == EOF || mLastChar == '*' && peekChar() == '/'));
|
while(!(mLastChar == EOF || mLastChar == '*' && peekChar() == '/'));
|
||||||
|
|
||||||
if(mLastChar == EOF) //unexpected end of file
|
if(mLastChar == EOF) //unexpected end of file
|
||||||
{
|
{
|
||||||
mState.LineIndex++;
|
mState.LineIndex++;
|
||||||
return reportError("unexpected end of file in block comment");
|
return reportError("unexpected end of file in block comment");
|
||||||
|
|
|
@ -88,13 +88,13 @@ uptr<Stat> Parser::ParseStat()
|
||||||
|
|
||||||
uptr<Block> Parser::ParseBlock()
|
uptr<Block> Parser::ParseBlock()
|
||||||
{
|
{
|
||||||
if(CurToken.Token != Lexer::tok_bropen) //'{'
|
if(CurToken.Token != Lexer::tok_bropen) //'{'
|
||||||
return nullptr;
|
return nullptr;
|
||||||
NextToken();
|
NextToken();
|
||||||
|
|
||||||
vector<uptr<StatDecl>> statDecls;
|
vector<uptr<StatDecl>> statDecls;
|
||||||
|
|
||||||
if(CurToken.Token == Lexer::tok_brclose) //'}'
|
if(CurToken.Token == Lexer::tok_brclose) //'}'
|
||||||
{
|
{
|
||||||
NextToken();
|
NextToken();
|
||||||
return make_uptr<Block>(move(statDecls));
|
return make_uptr<Block>(move(statDecls));
|
||||||
|
@ -138,7 +138,7 @@ uptr<Decl> Parser::ParseDecl()
|
||||||
|
|
||||||
uptr<BuiltinVar> Parser::ParseBuiltinVar()
|
uptr<BuiltinVar> Parser::ParseBuiltinVar()
|
||||||
{
|
{
|
||||||
if(CurToken.Token == Lexer::tok_uint) //TODO: properly handle types
|
if(CurToken.Token == Lexer::tok_uint) //TODO: properly handle types
|
||||||
{
|
{
|
||||||
auto type = CurToken.Token;
|
auto type = CurToken.Token;
|
||||||
NextToken();
|
NextToken();
|
||||||
|
|
Loading…
Reference in New Issue