public void Test1() { var cmd = " "; var args = CommandToken.Parse(cmd).ToArray(); AreEqual(args, new CommandSpaceToken(0, 1)); Assert.AreEqual(cmd, CommandToken.ToString(args)); }
public void Test2() { var cmd = "show state"; var args = CommandToken.Parse(cmd).ToArray(); AreEqual(args, new CommandStringToken(0, "show"), new CommandSpaceToken(4, 2), new CommandStringToken(6, "state")); Assert.AreEqual(cmd, CommandToken.ToString(args)); }
public void Test5() { var cmd = "show \"123\\\"456\""; var args = CommandToken.Parse(cmd).ToArray(); AreEqual(args, new CommandStringToken(0, "show"), new CommandSpaceToken(4, 1), new CommandQuoteToken(5, '"'), new CommandStringToken(6, "123\\\"456"), new CommandQuoteToken(14, '"') ); Assert.AreEqual(cmd, CommandToken.ToString(args)); }
public void Test3() { var cmd = "show \"hello world\""; var args = CommandToken.Parse(cmd).ToArray(); AreEqual(args, new CommandStringToken(0, "show"), new CommandSpaceToken(4, 1), new CommandQuoteToken(5, '"'), new CommandStringToken(6, "hello world"), new CommandQuoteToken(17, '"') ); Assert.AreEqual(cmd, CommandToken.ToString(args)); }
public override string ToString() { if (!string.IsNullOrWhiteSpace(rawExpression)) { return(rawExpression); } var builder = new StringBuilder(); builder.Append(Token.ToString()); foreach (var operand in Operands) { builder.Append(" "); builder.Append(operand); } return(builder.ToString()); }
void emitSyntax(PropertyDecorator <string> input) { try { CommandInvocation _invocation = new CommandInvocation(input.Value); for (int _i = 0; _i < _invocation.Tokens.Count( ); _i++) { CommandToken _currentToken = _invocation.Tokens[_i]; if (_currentToken is Arg) { writeArg(_currentToken); } else if (_currentToken is Word) { _currentToken.ToString( ).ColorWrite(ConsoleColor.Yellow); } if (_i < _invocation.Tokens.Count( ) - 1) { Console.Write(" "); } } if (input.Value.EndsWith(" ")) { " ".ColorWrite(ConsoleColor.Black); } " ".ColorWrite(ConsoleColor.Black, ConsoleColor.Green); } catch (SyntaxErrorException) { input.Value.ColorWrite(ConsoleColor.Red); } catch (Exception) { input.Value.ColorWrite(ConsoleColor.Black, ConsoleColor.Red); } }