public ImageCommitCommand(CommandToken token) { Index = token.Index; Transition = (TransitionType)token.Params[0]; StepCount = token.Params[1]; StepDuration = token.Params[2]; }
private void AddSmoothCubicBezierCurve(CommandToken commandToken) { var point2 = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); var end = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); if (_previousControlPoint != null) { _previousControlPoint = MirrorControlPoint((Point)_previousControlPoint, _currentPoint); } if (_isOpen == null) { CreateFigure(); } _geometryContext.CubicBezierTo(_previousControlPoint ?? _currentPoint, point2, end); _previousControlPoint = point2; _currentPoint = end; }
public SpriteCommand(CommandToken token) { Index = token.Index; Action = (SpriteAction)token.Params[0]; Position = token.Params[1]; SpriteIndex = token.Params[2]; }
public List <CommandToken> Parse() { _baseNote = null; _tokens = new List <CommandToken>(); for (int index = 0; index < Notes.Count;) { Notes[index].PitchCorrectionUnits = (int)Math.Round(Notes[index].PitchCorrection * BaseInterval); if (_baseNote == null) { _baseNote = Notes[index]; index++; continue; } CommandToken commandToken = ParseCommand(ref index); if (commandToken != null) { _tokens.Add(commandToken); } } return(_tokens); }
private void AddArc(CommandToken commandToken) { var size = commandToken.ReadSize(); var rotationAngle = commandToken.ReadDouble(); var isLargeArc = commandToken.ReadBool(); var sweepDirection = commandToken.ReadBool() ? SweepDirection.Clockwise : SweepDirection.CounterClockwise; var end = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); if (_isOpen == null) { CreateFigure(); } _geometryContext.ArcTo(end, size, rotationAngle, isLargeArc, sweepDirection); _currentPoint = end; _previousControlPoint = null; }
internal static T[] ToArrayAsync(SqlDataReader Reader, CancellationToken CancellationToken) { int size = 64; int index = 0; T[] items = new T[size]; CommandToken <T> token = new CommandToken <T>(Reader.GetSchemaTable()); if (!CallBackDataSetters.TryGetValue(token, out Func <SqlDataReader, T> SetCallBackData)) { CallBackDataSetters.Add(token, SetCallBackData = token.GenerateCallBackDataSetter()); } while (Reader.ReadAsync(CancellationToken).Result) { T item = SetCallBackData(Reader); items[index++] = item; if (index == size) { size *= 2; T[] new_items = new T[size]; Array.Copy(items, 0, new_items, 0, items.Length); items = new_items; } } T[] result_items = new T[index]; Array.Copy(items, 0, result_items, 0, index); items = result_items; return(items); }
/// <summary> /// Split a command line into enumerable /// https://stackoverflow.com/a/24829691 /// </summary> /// <param name="commandLine">Command line</param> /// <returns>Return the ienumerable result</returns> public static IEnumerable <CommandToken> SplitCommandLine(this string commandLine) { var inQuotes = false; var isEscaping = false; var reslist = commandLine.Split((c) => { if (c == '\\' && !isEscaping) { isEscaping = true; return(false); } if (c == '\"' && !isEscaping) { inQuotes = !inQuotes; } isEscaping = false; return(!inQuotes && char.IsWhiteSpace(c) /*c == ' '*/); }); foreach (var(Value, Index) in reslist) { var cmd = new CommandToken(Value, Index, Value.Length); if (string.IsNullOrEmpty(cmd.Value)) { continue; } yield return(cmd); } }
private void AddCubicBezierCurve(CommandToken commandToken) { var point1 = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); var point2 = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); _previousControlPoint = point2; var point3 = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); if (_isOpen == null) { CreateFigure(); } _geometryContext.CubicBezierTo(point1, point2, point3); _currentPoint = point3; }
public GreaterEqualsCommand(CommandToken token) { Index = token.Index; ResultVariable = token.Params[0]; LhsVariable = token.Params[1]; RhsVariable = token.Params[2]; }
public AddCommand(CommandToken token) { Index = token.Index; ResultVariable = token.Params[0]; LhsVariable = token.Params[1]; RhsVariable = token.Params[2]; }
private void AddMove(CommandToken commandToken) { var currentPoint = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); _currentPoint = currentPoint; CreateFigure(); if (!commandToken.HasImplicitCommands) { return; } while (commandToken.HasImplicitCommands) { AddLine(commandToken); if (commandToken.IsRelative) { continue; } _currentPoint = currentPoint; CreateFigure(); } }
IEnumerable <PromptCommandAttribute> SearchCommands(string command, List <CommandToken> cmdArgs) { // Parse arguments cmdArgs.AddRange(command.SplitCommandLine()); if (cmdArgs.Count <= 0) { yield break; } foreach (KeyValuePair <string[], PromptCommandAttribute> key in _commandCache) { if (key.Key.Length > cmdArgs.Count) { continue; } bool equal = true; for (int x = 0, m = key.Key.Length; x < m; x++) { CommandToken c = cmdArgs[x]; if (c.Value.ToLowerInvariant() != key.Key[x]) { equal = false; break; } } if (equal) { yield return(key.Value); } } }
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 cmdParser_HandlesUnterminatedSpacedCodeBlock() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("{return true", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.CodeBlock, token.Kind); }
public void cmdParser_HandlesNegativeNumbers() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("-12", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.Number, token.Kind); }
public static void TestGetNextTokenOnCommand() { const string input = "echo \"Hello, world!\""; var token = Lexer.GetNextToken(input, 0); Token correctToken = new CommandToken(Command.Echo); Assert.Equal(correctToken, token); }
public void cmdParser_HandlesCodeBlock() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("{Test()}", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.CodeBlock, token.Kind); }
private CommandToken ParseCommand(ref int index) { int commandInterval = GetInterval(index); switch (commandInterval) { case 0: // this is not a command at all, just a holding place index++; return(null); case MAJOR_SECOND: // new root note // get next interval and that is the new root note index++; // get next index _baseNote = Notes[index]; return(null); case MINOR_THIRD: // let (variable as single note, then expression) index++; // get next index CommandToken letCommand = new CommandToken() { CommandType = CommandType.Let, VariableName = Notes[index] }; index++; letCommand.ChildExpressions.Add(ParseExpression(ref index)); return(letCommand); case MAJOR_THIRD: // this indicates a block, need next note to determine type index++; ParseBlock(ref index); return(null); case MINOR_SIXTH: // minor sixth // declare CommandToken declareCommand = new CommandToken() { CommandType = CommandType.Declare, VariableName = Notes[index + 1], Type = ParseType(index + 2) }; index += 2; // get next index return(declareCommand); case MAJOR_SIXTH: // major sixth^ index++; return(ParseSpecialCommand(ref index)); default: throw new SyntaxError("Invalid first interval of command", commandInterval, index); } }
public void cmdParser_HandlesString() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("\"single_string_test\"", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.String, token.Kind); Assert.AreEqual("single_string_test", token.String); }
public void cmdParser_HandlesDecimalNumbers() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("12.5", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.Number, token.Kind); Assert.AreEqual("12.5", token.String); }
public void cmdParser_HandlesNegativePrefixedWordAsWord() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("-hello", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.Word, token.Kind); Assert.AreEqual("-hello", token.String); }
public void cmdParser_HandlesUnterminatedSpacedString() { FakeDeveloperConsole console = new FakeDeveloperConsole(); CommandParser parser = new CommandParser("\"spaced string test", console); CommandToken token = parser.Tokens[0]; Assert.AreEqual(CommandTokenKind.String, token.Kind); Assert.AreEqual("spaced string test", token.String); }
private string TokenParamsToString(CommandToken token) { string concatenation = string.Join(" ", token.Params.Select(p => "0x" + p.ToString("x"))) + " (" + string.Join(", ", token.Params.Select(p => p.ToString())) + ")"; if (token.Value == (int)Commands.Text) { concatenation += "(" + _File.Strings[token.Params[4] - 1] + ")"; } return(concatenation); }
void writeArg(CommandToken currentToken) { Arg _currentArg = ( Arg )currentToken; _currentArg.Prefix.ColorWrite(ConsoleColor.Green); ":".ColorWrite(ConsoleColor.DarkGreen); _currentArg.Value.ColorWrite(ConsoleColor.White); if (_currentArg.Postfix != string.Empty) { ":".ColorWrite(ConsoleColor.DarkGreen); _currentArg.Postfix.ColorWrite(ConsoleColor.Green); } }
internal static T First(SqlDataReader Reader) { CommandToken <T> token = new CommandToken <T>(Reader.GetSchemaTable()); if (!CallBackDataSetters.TryGetValue(token, out Func <SqlDataReader, T> SetCallBackData)) { CallBackDataSetters.Add(token, SetCallBackData = token.GenerateCallBackDataSetter()); } Reader.Read(); return(SetCallBackData(Reader)); }
private void AddLine(CommandToken commandToken) { _currentPoint = commandToken.IsRelative ? commandToken.ReadRelativePoint(_currentPoint) : commandToken.ReadPoint(); if (_isOpen == null) { CreateFigure(); } _geometryContext.LineTo(_currentPoint); }
private void AddVerticalLine(CommandToken commandToken) { _currentPoint = commandToken.IsRelative ? new Point(_currentPoint.X, _currentPoint.Y + commandToken.ReadDouble()) : _currentPoint.WithY(commandToken.ReadDouble()); if (_isOpen == null) { CreateFigure(); } _geometryContext.LineTo(_currentPoint); }
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)); }
static private CommandToken[] CleanCommand(IEnumerable <CommandToken> tokens) { var change = false; var tks = new List <CommandToken>(); foreach (var token in tokens) { if (token.Quoted || token.Value == "[" || token.Value == "]") { tks.Add(token); } else { var val = token.Value; if (val.StartsWith("[")) { tks.Add(new CommandToken("[")); val = val.Substring(1); change = true; } CommandToken add = null; if (val.EndsWith("]")) { add = new CommandToken("]"); val = val.Substring(0, val.Length - 1); change = true; } if (!string.IsNullOrEmpty(val)) { tks.Add(new CommandToken(val, false)); } if (add != null) { tks.Add(add); } } } // Recursive if (change) { return(CleanCommand(tks)); } return(tks.ToArray()); }