public override Verb CreateVerb(string[] tokens) { Color(position, length, KeyWords); if (parser.Parse(source, NextPosition) is Some <(string[], int)> some) { (var fields, var index) = some.Value; var parameters = new Parameters(fields); if (freeParser.Scan(source, index, "^ /s* 'in' /b")) { index = freeParser.Position; freeParser.ColorAll(KeyWords); if (GetExpressionThenBlock(source, index) is Some <(Block, Block, int)> some2) { (var expression, var block, var blkIndex) = some2.Value; overridePosition = blkIndex; return(new ForExecute(parameters, expression, block) { Index = position }); } } } return(null); }
public override Verb CreateVerb(string[] tokens) { var visibility = ParseVisibility(tokens[2].Trim()); var type = tokens[3]; var fieldName = tokens[5]; var readOnly = type == "val"; Color(position, tokens[1].Length, Whitespaces); Color(tokens[2].Length, KeyWords); Color(type.Length, KeyWords); Color(tokens[4].Length, Whitespaces); Color(fieldName.Length, Variables); if (parser.Scan(source, NextPosition, "^ /s* ','")) { var fieldListParser = new FieldListParser(); if (fieldListParser.Parse(source, parser.Position).If(out var fieldNames, out var index)) { overridePosition = index; var fields = new string[fieldNames.Length + 1]; System.Array.Copy(fieldNames, 0, fields, 1, fieldNames.Length); fields[0] = fieldName; return(new CreateFields(readOnly, fields, visibility) { Index = position }); } return(null); } return(new CreateField(readOnly, fieldName, visibility) { Index = position }); }
public override Verb CreateVerb(string[] tokens) { Color(position, length, KeyWords); if (parser.Parse(source, NextPosition).If(out var fields, out var index)) { var parameters = new Parameters(fields); if (freeParser.Scan(source, index, "^ /s* 'in' /b")) { index = freeParser.Position; freeParser.ColorAll(KeyWords); if (GetExpression(source, index, EndOfLineConsuming()).If(out var expression, out var i)) { index = i; var block = GetBlock(source, index, true); if (block.IsSome) { index = block.Value.Item2; var firstParser = new FirstParser(); var first = when(firstParser.Scan(source, index), () => firstParser.Block); if (first.IsSome) { index = firstParser.Position; } var middleParser = new MiddleParser(); var middle = when(middleParser.Scan(source, index), () => middleParser.Block); if (middle.IsSome) { index = middleParser.Position; } else { return(null); } var lastParser = new LastParser(); var last = when(lastParser.Scan(source, index), () => lastParser.Block); if (last.IsSome) { index = lastParser.Position; } overridePosition = index; return(new Iterate(parameters, expression, first, middle.Value, last, block.Value.Item1) { Index = position }); } } } } return(null); }
public override Verb CreateVerb(string[] tokens) { if (fieldListParser.Parse(source, position).If(out var fields, out var i)) { var index = i; var parameters = new Parameters(fields); if (freeParser.Scan(source, index, "^ ' '* 'in' /b")) { index = freeParser.Position; freeParser.ColorAll(KeyWords); if (GetExpression(source, index, PassAlong("^ ' '* 'do' /b", true, KeyWords)).If(out var arrayExp, out var j)) { index = j; var newSource = new Block(); var ifExpression = new Block(); var addingToIf = false; foreach (var verb in arrayExp.AsAdded) { if (verb is If) { addingToIf = true; continue; } if (addingToIf) { ifExpression.Add(verb); } else { newSource.Add(verb); } } if (GetExpression(source, index, PassAlong("^ ' '* [',)']", false)).If(out var yieldExp, out var k)) { overridePosition = k; var comprehension = new Comprehension(yieldExp, parameters, new Region()) { ArrayBlock = newSource }; if (ifExpression.Count > 0) { comprehension.SetIf(ifExpression); } result.Value = comprehension; return(new NullOp()); } } } } return(null); }
public override Verb CreateVerb(string[] tokens) { Color(position, length, KeyWords); if (parser.Parse(source, NextPosition).If(out var fields, out var index)) { var parameters = new Parameters(fields); if (freeParser.Scan(source, index, "^ /s* 'in' /b")) { index = freeParser.Position; freeParser.ColorAll(KeyWords); if (GetExpressionThenBlock(source, index).If(out var expression, out var block, out var blkIndex)) { overridePosition = blkIndex; return(new ForExecute(parameters, expression, block) { Index = position }); } } } return(null); }
public override Verb CreateVerb(string[] tokens) { if (fieldListParser.Parse(source, position).If(out var fields, out var i)) { var index = i; var parameters = new Parameters(fields); if (freeParser.Scan(source, index, "^ /s* 'in' /b")) { index = freeParser.Position; freeParser.ColorAll(KeyWords); var stop = ComprehensionEnd(); if (GetExpression(source, index, stop).If(out var generatorSource, out var j)) { if (!freeParser.Scan(source, j, stop.Pattern)) { return(null); } index = freeParser.Position; var token = freeParser.Tokens[1]; var ifBlock = none <Block>(); switch (token) { case ",": Last = false; freeParser.ColorAll(Structures); break; case "if": freeParser.ColorAll(KeyWords); if (GetExpression(source, index, stop).If(out var block, out var k)) { ifBlock = block.Some(); index = k; freeParser.Scan(source, index, stop.Pattern); index = freeParser.Position; token = freeParser.Tokens[0].TrimLeft(); switch (token) { case ",": Last = false; freeParser.ColorAll(Structures); break; case "if": return(null); case ":": Last = true; freeParser.ColorAll(Structures); break; } } break; case ":": Last = true; freeParser.ColorAll(Structures); break; } overridePosition = index; result.Value = new NSInnerComprehension(parameters, generatorSource, ifBlock); return(new NullOp()); } } } return(null); }