Skip to content

Commit

Permalink
Improved detection and logging for mismatched parens, other minor cha…
Browse files Browse the repository at this point in the history
…nges.
  • Loading branch information
homothetyhk committed Jun 18, 2022
1 parent 2da7ea7 commit b39c7a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions RandomizerCore/Logic/LogicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ public LogicInt GetVariable(int id)
return _variables[intVariableOffset - id];
}

public LogicInt GetVariable(string name)
{
if (_variableIndices.TryGetValue(name, out int index)) return _variables[intVariableOffset - index];
else if (VariableResolver.TryMatch(this, name, out LogicInt li))
{
index = intVariableOffset - _variables.Count;
_variableIndices.Add(name, index);
_variables.Add(li);
return li;
}
else return null;
}

public LogicItem GetItem(string name)
{
if (!_items.TryGetValue(name, out LogicItem item))
Expand Down
3 changes: 3 additions & 0 deletions RandomizerCore/StringLogic/Infix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public static List<LogicToken> Tokenize(string infix, ITokenSource tokenSource)
output.Add(tokenSource.GetComparisonToken(ComparerEnum[op], left, right));
}
break;
case "(":
case ")":
throw new ArgumentException($"Failed to tokenize infix {infix}: extra parens found after parsing.");
default:
{
output.Add(tokenSource.GetTermToken(postfix[j]));
Expand Down
2 changes: 1 addition & 1 deletion RandomizerCore/StringLogic/LogicClauseBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public LogicClauseBuilder(LogicClauseBuilder lcb)
public void OrWith(IEnumerable<LogicToken> ts)
{
Append(ts);
Append(OperatorToken.AND);
Append(OperatorToken.OR);
}

public void OrWith(TermToken t)
Expand Down

0 comments on commit b39c7a6

Please sign in to comment.