Skip to content

Commit

Permalink
修复一些情况下解析错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Funny-ppt committed Jan 25, 2024
1 parent 146a687 commit 5722230
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions InfrastSim/Script/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ private bool Match(TokenType type) {
return false;
}

private bool ConsumeNonContentLines() {
while (tokens.Current.Type == TokenType.NewLine || tokens.Current.Type == TokenType.Comment) {
tokens.MoveNext();
}
return tokens.Current.Type != TokenType.Final;
}

private Script ParseScript() {
tokens.Reset();

Expand All @@ -23,16 +30,14 @@ private Script ParseScript() {

var statements = new List<Statement>();
while (tokens.Current.Type != TokenType.Final) {
statements.Add(ParseStatement());
if (ConsumeNonContentLines()) {
statements.Add(ParseStatement());
}
}
return new(statements);
}

private Statement ParseStatement() {
while (tokens.Current.Type == TokenType.NewLine || tokens.Current.Type == TokenType.Comment) {
tokens.MoveNext();
}

var command = ParseCommand();
var parameters = new List<Parameter>();
while (tokens.Current.Type == TokenType.String) {
Expand Down

0 comments on commit 5722230

Please sign in to comment.