diff --git a/Core/ProfitTrailer/StrategyHelper.cs b/Core/ProfitTrailer/StrategyHelper.cs index 3a7442c..997c124 100644 --- a/Core/ProfitTrailer/StrategyHelper.cs +++ b/Core/ProfitTrailer/StrategyHelper.cs @@ -9,205 +9,6 @@ using System.Text.RegularExpressions; namespace Core.ProfitTrailer { - public class OperandToken : Token - { - } - public class OrToken : OperandToken - { - } - - public class AndToken : OperandToken - { - } - - public class BooleanValueToken : Token - { - } - - public class FalseToken : BooleanValueToken - { - } - - public class TrueToken : BooleanValueToken - { - } - - public class ParenthesisToken : Token - { - } - - public class ClosedParenthesisToken : ParenthesisToken - { - } - - public class OpenParenthesisToken : ParenthesisToken - { - } - - public class NegationToken : Token - { - } - - public abstract class Token - { - } - - public class Tokenizer - { - private readonly StringReader _reader; - private string _text; - - public Tokenizer(string text) - { - _text = text; - _reader = new StringReader(text); - } - - public IEnumerable Tokenize() - { - var tokens = new List(); - while (_reader.Peek() != -1) - { - while (Char.IsWhiteSpace((char)_reader.Peek())) - { - _reader.Read(); - } - - if (_reader.Peek() == -1) - break; - - var c = (char)_reader.Peek(); - switch (c) - { - case '!': - tokens.Add(new NegationToken()); - _reader.Read(); - break; - case '(': - tokens.Add(new OpenParenthesisToken()); - _reader.Read(); - break; - case ')': - tokens.Add(new ClosedParenthesisToken()); - _reader.Read(); - break; - default: - if (Char.IsLetter(c)) - { - var token = ParseKeyword(); - tokens.Add(token); - } - else - { - var remainingText = _reader.ReadToEnd() ?? string.Empty; - throw new Exception(string.Format("Unknown grammar found at position {0} : '{1}'", _text.Length - remainingText.Length, remainingText)); - } - break; - } - } - return tokens; - } - - private Token ParseKeyword() - { - var text = new StringBuilder(); - while (Char.IsLetter((char)_reader.Peek())) - { - text.Append((char)_reader.Read()); - } - - var potentialKeyword = text.ToString().ToLower(); - - switch (potentialKeyword) - { - case "true": - return new TrueToken(); - case "false": - return new FalseToken(); - case "and": - return new AndToken(); - case "or": - return new OrToken(); - default: - throw new Exception("Expected keyword (True, False, and, or) but found " + potentialKeyword); - } - } - } - public class Parser - { - private readonly IEnumerator _tokens; - - public Parser(IEnumerable tokens) - { - _tokens = tokens.GetEnumerator(); - _tokens.MoveNext(); - } - - public bool Parse() - { - while (_tokens.Current != null) - { - var isNegated = _tokens.Current is NegationToken; - if (isNegated) - _tokens.MoveNext(); - - var boolean = ParseBoolean(); - if (isNegated) - boolean = !boolean; - - while (_tokens.Current is OperandToken) - { - var operand = _tokens.Current; - if (!_tokens.MoveNext()) - { - throw new Exception("Missing expression after operand"); - } - var nextBoolean = ParseBoolean(); - - if (operand is AndToken) - boolean = boolean && nextBoolean; - else - boolean = boolean || nextBoolean; - } - return boolean; - } - throw new Exception("Empty expression"); - } - - private bool ParseBoolean() - { - if (_tokens.Current is BooleanValueToken) - { - var current = _tokens.Current; - _tokens.MoveNext(); - - if (current is TrueToken) - return true; - - return false; - } - if (_tokens.Current is OpenParenthesisToken) - { - _tokens.MoveNext(); - - var expInPars = Parse(); - - if (!(_tokens.Current is ClosedParenthesisToken)) - throw new Exception("Expecting Closing Parenthesis"); - - _tokens.MoveNext(); - - return expInPars; - } - if (_tokens.Current is ClosedParenthesisToken) - throw new Exception("Unexpected Closed Parenthesis"); - - // since its not a BooleanConstant or Expression in parenthesis, it must be a expression again - var val = Parse(); - return val; - } - } - public static class StrategyHelper { public static string GetStrategyShortcut(string strategyName, bool onlyValidStrategies) @@ -597,21 +398,19 @@ namespace Core.ProfitTrailer strategyText += ""; } else if (strategy.Name.Contains("STATS")) - // avoid parsing advanced buy stats + // Avoid displaying advanced buy stats and completed level formulas { strategy.Name = ""; } else if (strategy.Name.Contains("FORMULA")) - // Parse Various PT Formulas + // Avoid displaying formula details { if (strategy.Name.Contains("LEVEL")) - // level X { string level = strategy.Name.Substring(5, 1); strategyText += "L " + level + " "; } else - // standard formula { strategyText += "FORM "; } diff --git a/PTMagic/Program.cs b/PTMagic/Program.cs index 2489c1c..cb5a388 100644 --- a/PTMagic/Program.cs +++ b/PTMagic/Program.cs @@ -6,7 +6,7 @@ using Core.Helper; using Microsoft.Extensions.DependencyInjection; -[assembly: AssemblyVersion("2.4.4")] +[assembly: AssemblyVersion("2.4.5")] [assembly: AssemblyProduct("PT Magic")] namespace PTMagic