@@ -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
115115StmtPtr 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+
939973void 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 : ;
0 commit comments