public override void AcceptEvaluator(RCToken token) { FinishValue(true); MakeExpression(); // When this applies there is no actual opening bracket defining the block. // This happens in the shell. // I call it an "implied" block. if (_block == null) { _block = RCBlock.Empty; } FinishBlock(); if (_maybeOperator != null) { // _maybeOp is not an operator, its a variable. _variable = _maybeOperator; _maybeOperator = null; } if (_variable == null) { // It is an unnamed block. _variable = ""; } // If anything was left over on the right, it doesn't belong here. // Should this be an invalid state for the parser? _result = null; _evaluator = RCEvaluator.For(token.Text); }
static RCEvaluator() { Let = new RCEvaluator(":", true, false, false, false, false, true, Let); Quote = new RCEvaluator("::", false, false, false, false, true, true, Let); Yield = new RCEvaluator("<-", true, true, false, false, false, false, Yield); Yiote = new RCEvaluator("<-:", false, false, false, false, true, true, Yield); Yiyi = new RCEvaluator("<--", true, false, false, false, false, true, Yield); Apply = new RCEvaluator("<+", false, false, true, false, false, false, Apply); Expand = new RCEvaluator("<&", false, true, false, true, false, false, Expand); }
public RCBlock(RCBlock previous, string name, RCEvaluator evaluator, RCValue val) { if (val == null) { throw new ArgumentNullException("value"); } Previous = previous != null ? previous : Empty; RCName nameInfo = RCName.GetName(name); Name = nameInfo.Text; EscapeName = nameInfo.Escaped; Evaluator = evaluator; Value = val; _count = Previous.Count + 1; }
public override void AcceptContent(RCToken token) { TemplateVars template = _templates.Peek(); int firstNewline = token.Text.IndexOfAny(CRLF); if (firstNewline > -1) { template._multilineTemplate = true; } // I want it to be AS IF we saw something like {:"foo bar with newlines"} // AcceptEvaluator (new RCToken (":", RCTokenType.Evaluator, token.Start, // token.Index)); // soo... _variable = ""; _evaluator = RCEvaluator.Let; _result = new RCString(token.Text); }
public RCEvaluator(string symbol, bool evaluate, bool @return, bool invoke, bool template, bool pass, bool finishBlock, RCEvaluator next) { Symbol = symbol; Pass = pass; Return = @return; Invoke = invoke; Template = template; FinishBlock = finishBlock; Next = next == null ? this : next; }
public override void AcceptBlock(RCToken token) { bool isStartTemplate = token.Text.StartsWith("[?"); bool isEndTemplate = token.Text.EndsWith("?]"); int escapeCount = token.Text.Length - 1; if (token.Text == "{" || isStartTemplate) { FinishValue(true); PushArgument(); PushExpression(); PushInlineDyadicOperator(); _lefts.Push(new Stack <RCValue> ()); _operators.Push(new Stack <RCValue> ()); if (isStartTemplate) { _templates.Push(new TemplateVars()); } if (_block != null) { _variables.Push(_variable); _evaluators.Push(_evaluator); _variable = null; } _blocks.Push(_block); _block = RCBlock.Empty; } else if (token.Text == "}" || isEndTemplate) { FinishValue(true); MakeExpression(); FinishBlock(); if (_variables.Count > 0) { _variable = _variables.Pop(); _evaluator = _evaluators.Pop(); if (isEndTemplate) { FinishTemplate(escapeCount); _templates.Pop(); } else { _result = _block; } _block = _blocks.Pop(); } else { if (isEndTemplate) { FinishTemplate(escapeCount); _templates.Pop(); } else { _result = _block; } _block = null; } _lefts.Pop(); _operators.Pop(); // If the stack contains a null on top, that is the signal // that this block should be used as an operator. Stack <RCValue> operators = _operators.Peek(); if (operators.Count > 0 && operators.Peek() == null) { operators.Pop(); operators.Push(_result); } } else if (token.Text.StartsWith("[!")) { FinishBlock(); _result = null; } else if (token.Text.EndsWith("!]")) { FinishValue(true); MakeExpression(); _variable = ""; _evaluator = RCEvaluator.Let; FinishBlock(); } else { throw new ArgumentException(token.Text); } }
public RCBlock(RCBlock previous, string name, string instr, RCValue val) : this(previous, name, RCEvaluator.For(instr), val) { }
public RCBlock(RCBlock previous, string name, string instr, params RCSymbolScalar[] val) : this(previous, name, RCEvaluator.For(instr), new RCSymbol(val)) { }
public RCBlock(RCBlock previous, string name, string instr, params bool[] val) : this(previous, name, RCEvaluator.For(instr), new RCBoolean(val)) { }
public RCBlock(RCBlock previous, string name, string instr, params decimal[] val) : this(previous, name, RCEvaluator.For(instr), new RCDecimal(val)) { }
public RCBlock(RCBlock previous, string name, string instr, params long[] val) : this(previous, name, RCEvaluator.For(instr), new RCLong(val)) { }