public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.BeginTransaction(); state.Colorize(tokens, Color.Whitespace, Color.Operator); var innerBuilder = new ExpressionBuilder(ExpressionFlags.Standard); innerBuilder.Add(new FieldSymbol("__$0")); var operatorsParser = new OperatorsParser(innerBuilder); var result = from op in operatorsParser.Scan(state) from closing in state.Scan("^ /']'", Color.Operator) select op; if (result.ValueOrOriginal(out _, out var original)) { innerBuilder.Add(new FieldSymbol("__$1")); if (innerBuilder.ToExpression().If(out var expression, out var exception)) { var lambda = new LambdaSymbol(2, expression); builder.Add(new SendBinaryMessageSymbol("foldr", Precedence.ChainedOperator)); builder.Add(lambda); state.CommitTransaction(); return(Unit.Matched()); } else { state.RollBackTransaction(); return(failedMatch <Unit>(exception)); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var source = tokens[2].Text; state.Colorize(tokens, Color.Whitespace, Color.Collection); switch (source) { case "[]": builder.Add(new EmptyArraySymbol()); break; case "{}": builder.Add(new EmptyDictionarySymbol()); break; case "()": builder.Add(new EmptyTupleSymbol()); break; case "⌈⌉": builder.Add(new EmptyListSymbol()); break; case "⎩⎭": builder.Add(new EmptySetSymbol()); break; default: return(notMatched <Unit>()); } return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var source = tokens[2].Text.Replace("_", "") + tokens[3].Text + tokens[4].Text; var type = tokens[5].Text; state.Colorize(tokens, Color.Whitespace, Color.Number, Color.NumberPart, Color.Number, Color.NumberPart); if (double.TryParse(source, out var result)) { if (type == "i") { builder.Add(new ComplexSymbol(result)); } else { builder.Add(new FloatSymbol(result)); } return(Unit.Matched()); } else { return(failedMatch <Unit>(unableToConvert(source, "Float"))); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Whitespace, Color.Keyword, Color.Whitespace); if (getBlock(state).ValueOrCast <Unit>(out var block, out var asUnit)) { block.AddReturnIf(new UnitSymbol()); var lambda = new LambdaSymbol(0, block); var invokeBuilder = new ExpressionBuilder(ExpressionFlags.Standard); invokeBuilder.Add(lambda); invokeBuilder.Add(new PostfixInvokeSymbol(new Expression[0])); if (invokeBuilder.ToExpression().If(out var invokeExpression, out var exception)) { builder.Add(new TrySymbol(invokeExpression)); return(Unit.Matched()); } else { return(failedMatch <Unit>(exception)); } } else { return(asUnit); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var className = tokens[2].Text; state.Colorize(tokens, Color.Whitespace, Color.Class); if (Module.Global.Class(className).If(out var cls)) { builder.Add(new ClassSymbol(cls.Name)); return(Unit.Matched()); } else if (Module.Global.FullDataComparisandName(className).If(out _)) { builder.Add(new FieldSymbol(className)); return(Unit.Matched()); } else if (Module.Global.Forwarded(className)) { builder.Add(new ClassSymbol(className)); return(Unit.Matched()); } else if (state.ContainsPattern(className)) { builder.Add(new FieldSymbol(className)); return(Unit.Matched()); } else { return(notMatched <Unit>()); } }
public override IMatched <Unit> Suffix(ParseState state, Expression expression) { outerBuilder.Add(new FieldSymbol(tempObjectField)); outerBuilder.Add(new SendMessageSymbol(propertyName.set(), none <LambdaSymbol>(), expression)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var precedence = tokens[2].Text == "." ? Precedence.SendMessage : Precedence.ChainedOperator; if (precedence == Precedence.ChainedOperator && builder.Flags[ExpressionFlags.InLambda]) { return(notMatched <Unit>()); } var name = tokens[3].Text; var parameterDelimiter = tokens[4].Text; var parseArguments = true; if (parameterDelimiter.IsEmpty()) { name = name.get(); parseArguments = false; } else if (name.EndsWith("=")) { name = name.Drop(-1).set(); parseArguments = true; } if (parseArguments) { state.Colorize(tokens, Color.Whitespace, Color.Message, Color.Message, Color.OpenParenthesis); } else { state.Colorize(tokens, Color.Whitespace, Color.Message, Color.Message); } if (!parseArguments) { Selector selector = name; builder.Add(new SendMessageSymbol(selector)); return(Unit.Matched()); } else if (getArgumentsPlusLambda(state, builder.Flags).ValueOrCast <Unit>(out var tuple, out var asUnit)) { var(arguments, lambda) = tuple; var selector = name.Selector(arguments.Length); builder.Add(new SendMessageSymbol(selector, lambda, arguments)); return(Unit.Matched()); } else { return(asUnit); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var insert = tokens[2].Text == "+"; state.Colorize(tokens, Color.OpenParenthesis, Color.Structure); return(getArguments(state, builder.Flags).Map(e => { if (state.Scan($"^ /(|s|) /({REGEX_ASSIGN_OPS})? /'=' -(> '=')", Color.Whitespace, Color.Operator, Color.Structure) .If(out var opSource, out var anyException)) { if (getExpression(state, builder.Flags).ValueOrCast <Unit>(out var expression, out var asUnit)) { opSource = opSource.DropWhile(" ").Keep(1); var operation = matchOperator(opSource) .FlatMap(o => o.Some(), none <Operations.Operation>, _ => none <Operations.Operation>()); if (operation.IsNone && insert) { var list = e.ToList(); list.Add(expression); builder.Add(new SendMessageSymbol("insert(at:_<Int>,value:_)", none <LambdaSymbol>(), none <Operations.Operation>(), list.ToArray())); } else { builder.Add(new IndexSetterSymbol(e, expression, operation)); } return Unit.Matched(); } else { return asUnit; } } else if (anyException.If(out var exception)) { return failedMatch <Unit>(exception); } else if (e.Length > 0) { builder.Add(new IndexerSymbol(e)); } else { return notMatched <Unit>(); } return Unit.Matched(); })); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var isSuccess = tokens[2].Text == "assert"; state.Colorize(tokens, Color.Whitespace, Color.Keyword); var result = from condition in getExpression(state, builder.Flags | ExpressionFlags.OmitColon) from colon1 in state.Scan("^ /(|s|) /':'", Color.Whitespace, Color.Structure) from value in getExpression(state, builder.Flags | ExpressionFlags.OmitColon) select(condition, value); if (isSuccess) { if (result.ValueOrOriginal(out var tuple, out var original)) { var(condition, value) = tuple; var result2 = from colon2 in state.Scan("^ /(|s|) /':'", Color.Whitespace, Color.Structure) from error in getExpression(state, builder.Flags | ExpressionFlags.OmitColon) select error; if (result2.ValueOrOriginal(out var expression, out var original2)) { builder.Add(new AssertSymbol(condition, value, expression.Some())); return(Unit.Matched()); } else { return(original2.Unmatched <Unit>()); } } else { return(original.Unmatched <Unit>()); } } else if (result.ValueOrOriginal(out var tuple, out var original)) { var(condition, value) = tuple; builder.Add(new AssertSymbol(condition, value, none <Expression>())); return(Unit.Matched()); } else { return(original.Unmatched <Unit>()); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.OpenParenthesis); var skipTakes = new List <SkipTake>(); while (state.More) { var skipTakeMatch = getSkipTake(state, builder.Flags | ExpressionFlags.OmitComma); if (skipTakeMatch.If(out var skipTake, out var _exception)) { skipTakes.Add(skipTake); if (skipTake.Terminal) { break; } } else if (_exception.If(out var exception)) { return(failedMatch <Unit>(exception)); } } builder.Add(new SliceSymbol(skipTakes.ToArray())); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.BeginTransaction(); var word1 = tokens[2].Text; var word2 = tokens[4].Text; var message = ""; state.Colorize(tokens, Color.Whitespace, Color.Keyword, Color.Whitespace, Color.Keyword); switch (word1) { case "skip": case "take": switch (word2) { case "while": case "until": message = word1.Selector($"{word2}:"); break; } break; default: state.RollBackTransaction(); return(notMatched <Unit>()); } builder.Add(new SendBinaryMessageSymbol(message, Precedence.ChainedOperator)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Whitespace, Color.Boolean); builder.Add(new BooleanSymbol(tokens[2].Text == "true")); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Whitespace, Color.Structure, Color.Whitespace, Color.Structure, Color.Whitespace); var matchItems = new List <(Expression, Expression)>(); while (state.More) { if (getMatchItem(state).If(out var matchItem, out var anyException)) { matchItems.Add(matchItem); } else if (anyException.If(out var exception)) { return(failedMatch <Unit>(exception)); } else { break; } } builder.Add(new MatchExpressionSymbol(matchItems.ToArray())); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Whitespace, Color.Operator); state.BeginTransaction(); var expressionBuilder = new ExpressionBuilder(builder.Flags); var parser = new AnyLambdaParser(expressionBuilder); var result = from parsed in parser.Scan(state) from endToken in state.Scan("/']'", Color.Operator) select parsed; if (result.ValueOrOriginal(out _, out var original)) { if (expressionBuilder.ToExpression().If(out var expression, out var exception)) { builder.Add(new ZipLambdaSymbol(expression)); state.CommitTransaction(); return(Unit.Matched()); } else { state.RollBackTransaction(); return(failedMatch <Unit>(exception)); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Whitespace, Color.Operator); builder.Add(new SendPrefixMessage("range")); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Whitespace, Color.Operator); builder.Add(new BNotSymbol()); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.BeginTransaction(); state.CreateReturnType(); var result = from parameters in ParseParameters(state, tokens) from scanned in state.Scan("^ /(|s|) /'->'", Color.Whitespace, Color.Structure) from typeConstraint in parseTypeConstraint(state) from block in getLambdaBlock(!state.CurrentSource.IsMatch("^ (/r /n | /r | /n)"), state, builder.Flags & ~ExpressionFlags.Comparisand | ExpressionFlags.InLambda, typeConstraint) select new LambdaSymbol(parameters, block); if (result.ValueOrCast <Unit>(out var lambdaSymbol, out var asUnit)) { builder.Add(lambdaSymbol); state.RemoveReturnType(); state.CommitTransaction(); return(Unit.Matched()); } else { state.RollBackTransaction(); state.RemoveReturnType(); return(asUnit); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var mutable = tokens[2].Text; var placeholderName = tokens[4].Text; var name = ""; switch (mutable) { case "use": name = placeholderName; break; case "var": name = $"+{placeholderName}"; break; default: name = $"-{placeholderName}"; break; } state.Colorize(tokens, Color.Whitespace, Color.Keyword, Color.Whitespace, Color.Identifier); builder.Add(new PlaceholderSymbol(name)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.Operator); builder.Add(new PushObjectSymbol(End.Value)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var name = tokens[3].Text; state.Colorize(tokens, Color.Whitespace, Color.Symbol, Color.Symbol); if (builder.Flags[ExpressionFlags.Comparisand]) { builder.Add(new FieldSymbol(name)); } else { builder.Add(new SymbolSymbol(name)); } return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var selector = tokens[3].Text; var parameterDelimiter = tokens[4].Text; var parseArguments = true; if (parameterDelimiter.IsEmpty()) { selector = selector.get(); parseArguments = false; } else if (selector.EndsWith("=")) { selector = selector.Drop(-1).set(); parseArguments = true; } if (!parseArguments) { state.Colorize(tokens, Color.Whitespace, Color.Structure, Color.Message); } else { state.Colorize(tokens, Color.Whitespace, Color.Structure, Color.Message, Color.OpenParenthesis); } if (!parseArguments) { builder.Add(new MessageSymbol(selector, new Expression[0], none <LambdaSymbol>())); return(Unit.Matched()); } else { if (getArgumentsPlusLambda(state, builder.Flags).ValueOrCast <Unit>(out var tuple, out var asUnit)) { var(arguments, lambda) = tuple; builder.Add(new MessageSymbol(selector, arguments, lambda)); return(Unit.Matched()); } else { return(asUnit); } } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var source = tokens[2].Text; state.Colorize(tokens, Color.Whitespace, Color.Identifier); if (state.DefExpression(source).If(out var defExpression)) { builder.Add(defExpression); } else { builder.Add(builder.Flags[ExpressionFlags.Comparisand] ? new PlaceholderSymbol($"-{source}") : new FieldSymbol(source)); } return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var source = tokens[3].Text.Replace("_", "") + tokens[4].Text + tokens[5].Text; var type = tokens[6].Text; state.Colorize(tokens, Color.Whitespace, Color.NumberPart, Color.Number, Color.NumberPart, Color.Number, Color.NumberPart); var prefix = source.Contains("p") ? source.KeepUntil("p") : source; var suffix = source.Contains("p") ? source.DropUntil("p").Drop(1) : ""; var left = convertFloat(prefix, 16, "0123456789abcdef"); if (suffix.IsEmpty()) { if (type == "i") { builder.Add(new ComplexSymbol(left)); } else { builder.Add(new FloatSymbol(left)); } return(Unit.Matched()); } else if (int.TryParse(suffix, out var right)) { var raised = Math.Pow(2, right); var result = left * raised; if (type == "i") { builder.Add(new ComplexSymbol(result)); } else { builder.Add(new FloatSymbol(result)); } return(Unit.Matched()); } else { return(failedMatch <Unit>(unableToConvert(suffix, "Long"))); } }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { Selector selector = tokens[3].Text + tokens[4].Text; state.Colorize(tokens, Color.Whitespace, Color.Operator, Color.Invokable, Color.Structure); builder.Add(new FieldSymbol(selector)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var inclusive = tokens[2].Text == ".."; state.Colorize(tokens, Color.Whitespace, Color.Operator, Color.Operator); builder.Add(new RangeSymbol(inclusive)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var fieldName = tokens[4].Text; state.Colorize(tokens, Color.Whitespace, Color.Operator, Color.Whitespace, Color.Identifier); builder.Add(new CallSysFunctionSymbol0(s => s.GetReference(fieldName), $"ref {fieldName}")); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var index = tokens[3].Text; state.Colorize(tokens, Color.Whitespace, Color.Identifier, Color.Identifier); builder.Add(new FieldSymbol($"__${index}")); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var lazy = tokens[2].Text == "!!"; var indexed = tokens[2].Text == "?"; state.Colorize(tokens, Color.Whitespace, Color.Operator); builder.Add(new IteratorSymbol(lazy, indexed)); return(Unit.Matched()); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { state.Colorize(tokens, Color.OpenParenthesis); return(getArguments(state, builder.Flags).Map(arguments => { builder.Add(new PostfixInvokeSymbol(arguments)); return Unit.Value; })); }
public override IMatched <Unit> Parse(ParseState state, Token[] tokens, ExpressionBuilder builder) { var source = tokens[3].Text; state.Colorize(tokens, Color.Whitespace, Color.Collection, Color.Collection, Color.Collection); builder.Add(new StringArraySymbol(source)); return(Unit.Matched()); }