Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1110389

Browse files
committed
[New Compiler] Fix failure to compile commands such as MenuMode when they are also block types
1 parent 5c5816f commit 1110389

4 files changed

Lines changed: 41 additions & 13 deletions

File tree

nvse/nvse/NVSELexer.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,6 @@ NVSEToken NVSELexer::GetNextToken(bool useStack) {
282282
if (_stricmp(identifier.c_str(), "false") == 0) return MakeToken(NVSETokenType::Bool, identifier, 0);
283283
if (_stricmp(identifier.c_str(), "null") == 0) return MakeToken(NVSETokenType::Number, identifier, 0);
284284

285-
// See if it is a begin block type
286-
for (auto& g_eventBlockCommandInfo : g_eventBlockCommandInfos) {
287-
if (!_stricmp(g_eventBlockCommandInfo.longName, identifier.c_str())) {
288-
return MakeToken(NVSETokenType::BlockType, identifier);
289-
}
290-
}
291-
292285
return MakeToken(NVSETokenType::Identifier, identifier);
293286
}
294287
}

nvse/nvse/NVSELexer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ enum class NVSETokenType {
1414
Fn,
1515
Return,
1616
For,
17-
BlockType,
1817
Name,
1918
Continue,
2019
Break,
@@ -90,7 +89,6 @@ static const char* TokenTypeStr[]{
9089
"Fn",
9190
"Return",
9291
"For",
93-
"Begin",
9492
"Name",
9593
"Continue",
9694
"Break",

nvse/nvse/NVSEParser.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::optional<NVSEScript> NVSEParser::Parse() {
7373
Expect(NVSETokenType::RightParen, "Expected ')'.");
7474
}
7575
// Get event or udf block
76-
else if (Peek(NVSETokenType::BlockType)) {
76+
else if (PeekBlockType()) {
7777
blocks.emplace_back(Begin());
7878
}
7979
else if (Match(NVSETokenType::Fn)) {
@@ -113,7 +113,8 @@ std::optional<NVSEScript> NVSEParser::Parse() {
113113
}
114114

115115
StmtPtr NVSEParser::Begin() {
116-
Match(NVSETokenType::BlockType);
116+
ExpectBlockType("Expected block type");
117+
117118
auto blockName = previousToken;
118119
auto blockNameStr = blockName.lexeme;
119120

@@ -936,6 +937,39 @@ bool NVSEParser::PeekType() const {
936937
Peek(NVSETokenType::ArrayType) || Peek(NVSETokenType::StringType);
937938
}
938939

940+
bool NVSEParser::PeekBlockType() const {
941+
if (!Peek(NVSETokenType::Identifier)) {
942+
return false;
943+
}
944+
945+
const auto identifier = currentToken.lexeme;
946+
for (const auto& g_eventBlockCommandInfo : g_eventBlockCommandInfos) {
947+
if (!_stricmp(g_eventBlockCommandInfo.longName, identifier.c_str())) {
948+
return true;
949+
}
950+
}
951+
952+
return false;
953+
}
954+
955+
NVSEToken NVSEParser::ExpectBlockType(const std::string &&message) {
956+
if (!PeekBlockType()) {
957+
Error(currentToken, message);
958+
return previousToken;
959+
}
960+
961+
const auto identifier = currentToken.lexeme;
962+
for (const auto& g_eventBlockCommandInfo : g_eventBlockCommandInfos) {
963+
if (!_stricmp(g_eventBlockCommandInfo.longName, identifier.c_str())) {
964+
Advance();
965+
return previousToken;
966+
}
967+
}
968+
969+
Error(currentToken, message);
970+
return previousToken;
971+
}
972+
939973
void NVSEParser::Error(std::string message) {
940974
panicMode = true;
941975
hadError = true;
@@ -973,7 +1007,6 @@ void NVSEParser::Synchronize() {
9731007
case NVSETokenType::For:
9741008
case NVSETokenType::Return:
9751009
case NVSETokenType::RightBrace:
976-
case NVSETokenType::BlockType:
9771010
panicMode = false;
9781011
return;
9791012
default: ;

nvse/nvse/NVSEParser.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class NVSEParser {
1515
public:
1616
NVSEParser(NVSELexer& tokenizer);
1717
std::optional<NVSEScript> Parse();
18-
StmtPtr Begin();
1918

2019
private:
2120
NVSELexer& lexer;
@@ -27,6 +26,7 @@ class NVSEParser {
2726
std::shared_ptr<FnDeclStmt> FnDecl();
2827
std::shared_ptr<VarDeclStmt> VarDecl(bool allowValue = true, bool allowOnlyOneVarDecl = false);
2928

29+
StmtPtr Begin();
3030
StmtPtr Statement();
3131
StmtPtr ExpressionStatement();
3232
StmtPtr ForStatement();
@@ -65,6 +65,10 @@ class NVSEParser {
6565
bool MatchesType();
6666
bool Peek(NVSETokenType type) const;
6767
bool PeekType() const;
68+
69+
bool PeekBlockType() const;
70+
NVSEToken ExpectBlockType(const std::string&& message);
71+
6872
void Error(std::string message);
6973
void Error(NVSEToken token, std::string message);
7074
NVSEToken Expect(NVSETokenType type, std::string message);

0 commit comments

Comments
 (0)