public override Verb CreateVerb(string[] tokens) { var variable = tokens[2]; Color(position, tokens[1].Length, KeyWords); Color(variable.Length, Variables); Color(tokens[3].Length, Structures); var index = NextPosition; if (GetExpression(source, index, LoopWhile()).If(out var initialization, out index)) { var builder = new CodeBuilder(); builder.AssignToNewField(false, variable, initialization); var block = builder.Block; block.Expression = false; initialization = block; if (parser.Scan(source, index, "^ /(' '*) /('while' | 'until') /b")) { var direction = parser.Tokens[2]; var isWhile = direction == "while"; parser.Colorize(Whitespaces, KeyWords); index = parser.Position; if (GetExpression(source, index, LoopThen()).If(out var condition, out index)) { condition.Expression = false; if (GetExpression(source, index, LoopEnd()).If(out var increment, out index)) { increment.Expression = false; builder.Clear(); builder.Variable(variable); builder.Assign(); builder.Inline(increment); increment = builder.Block; if (GetOneOrMultipleBlock(source, index).If(out var body, out index)) { overridePosition = index; return(new Loop(initialization, isWhile, condition, increment, body) { Index = position }); } } } } } return(null); }
public override Verb CreateVerb(string[] tokens) { var hasPoint = tokens[1].Trim().IsNotEmpty(); var message = tokens[2]; Color(position, tokens[1].Length, Structures); Color(message.Length, Messaging); Color(1, Structures); return(GetExpression(source, NextPosition, CloseBracket(), true).Map((argumentExp, i) => { var index = i; var fieldName = ""; if (freeParser.Scan(source, index, $"^ {REGEX_ASSIGN}")) { index = freeParser.Position; freeParser.Colorize(Whitespaces, Structures, Structures); var op = freeParser.Tokens[2]; return GetExpression(source, index, EndOfLine()).Map((expression, j) => { overridePosition = j; if (!hasPoint) { fieldName = message; message = "item"; } if (op.IsNotEmpty()) { var combined = CombineOperation(message, op, argumentExp, expression); if (combined.IsNone) { return null; } expression = combined.Value; } var arguments = new Arguments(); arguments.AddBlockArgument(argumentExp); arguments.AddBlockArgument(expression); return hasPoint ? new SendMessage(SetterName(message), arguments) : new SendMessageToField(fieldName, SetterName(message), arguments); }, () => null); } overridePosition = index; return new SendMessage(GetterName(message), new Arguments(argumentExp)); }, () => null)); }
public override Verb CreateVerb(string[] tokens) { var variable = tokens[4]; Color(position, tokens[1].Length, Whitespaces); Color(tokens[2].Length, Structures); Color(tokens[3].Length, KeyWords); Color(variable.Length, Variables); Color(tokens[5].Length, Structures); var index = NextPosition; if (GetExpression(source, index, LoopWhile()).If(out var init, out index)) { if (parser.Scan(source, index, "^ /(' '*) /('while' | 'until') /b")) { var direction = parser.Tokens[2]; var positive = direction == "while"; parser.Colorize(Whitespaces, KeyWords); index = parser.Position; if (GetExpression(source, index, LoopThen()).If(out var condition, out index)) { condition.Expression = false; if (GetExpression(source, index, Yield()).If(out var increment, out index) && GetExpression(source, index, CloseParenthesis()).If(out var yielding, out index)) { overridePosition = index; var someYielding = maybe(yielding.Count > 0, () => yielding); var value = new LoopRange(variable, init, positive, condition, increment, someYielding); result.Value = value; return(value.PushedVerb); } } } } return(null); }