private IEnumerable <Parselet> FuncArgs(Token <R> fromToken, RantFunctionGroup group) { Token <R> funcToken = null; var actions = new List <RantAction>(); var sequences = new List <RantAction>(); while (!reader.End) { funcToken = reader.ReadToken(); if (funcToken.ID == R.Semicolon) { // add action to args and continue sequences.Add(actions.Count == 1 ? actions[0] : new RASequence(actions, funcToken)); actions.Clear(); reader.SkipSpace(); continue; } else if (funcToken.ID == R.RightSquare) { // add action to args and return sequences.Add(actions.Count == 1 ? actions[0] : new RASequence(actions, funcToken)); AddToOutput(new RAFunction(Stringe.Range(fromToken, funcToken), compiler.GetFunctionInfo(group, sequences.Count, fromToken, funcToken), sequences)); yield break; } yield return(GetParselet(funcToken, actions.Add)); } compiler.SyntaxError(fromToken, "Unterminated function: unexpected end of file"); }
void RightAngle(Token <R> token, Token <R> fromToken) { if (query.Name == null && query.Carrier.GetTotalCount() == 0) { compiler.SyntaxError(token, "Carrier delete query specified without any carriers"); } AddToOutput(new RAQuery(query, Stringe.Range(fromToken, token))); }
public RASequence(List <RantAction> actions, Stringe defaultRange) : base(actions.Any() ? Stringe.Range(actions[0].Range, actions[actions.Count - 1].Range) : defaultRange) { if (actions == null) { return; } _actions.AddRange(actions); }
private IEnumerable <Parselet> ReplacerArgs(Token <R> fromToken, Regex regex) { Token <R> funcToken = null; var actions = new List <RantAction>(); var sequences = new List <RantAction>(); while (!reader.End) { funcToken = reader.ReadToken(); if (funcToken.ID == R.Whitespace) { switch (reader.PeekType()) { case R.RightSquare: continue; } } else if (funcToken.ID == R.Semicolon) { // add action to args and continue if (sequences.Count == 1) { compiler.SyntaxError(funcToken, "Too many arguments in replacer"); } sequences.Add(actions.Count == 1 ? actions[0] : new RASequence(actions, funcToken)); actions.Clear(); reader.SkipSpace(); continue; } else if (funcToken.ID == R.RightSquare) { // add action to args and return sequences.Add(actions.Count == 1 ? actions[0] : new RASequence(actions, funcToken)); if (sequences.Count != 2) { compiler.SyntaxError(Stringe.Between(funcToken, fromToken), "Replacer must have two arguments"); } AddToOutput(new RAReplacer(Stringe.Range(fromToken, funcToken), regex, sequences[0], sequences[1])); yield break; } yield return(GetParselet(funcToken, actions.Add)); } compiler.SyntaxError(fromToken, "Unterminated function: unexpected end of file"); }
private IEnumerable <Parselet> FunctionText(Token <R> token) { var name = token.Value; var group = RantFunctions.GetFunctionGroup(name); if (group == null) { compiler.SyntaxError(token, $"Unknown function: '{name}'"); } if (reader.TakeLoose(R.Colon)) { foreach (var parselet in FuncArgs(token, group)) { yield return(parselet); } } else { var end = reader.Read(R.RightSquare); AddToOutput(new RAFunction(Stringe.Range(token, end), compiler.GetFunctionInfo(group, 0, token, end), new List <RantAction>())); } }
private IEnumerable <Parselet> LeftCurly(Token <R> token) { reader.SkipSpace(); // LOOK AT ME. I'M THE COMPILER NOW Token <R> readToken = null; var actions = new List <RantAction>(); var sequences = new List <RantAction>(); List <_ <int, double> > constantWeights = null; List <_ <int, RantAction> > dynamicWeights = null; while (!reader.End) { readToken = reader.ReadToken(); // TODO: kinda stupid having this handle it's own whitespace when we have a parselet for whitespace if (readToken.ID == R.Whitespace) { switch (reader.PeekType()) { case R.RightCurly: case R.Pipe: continue; } } else if (readToken.ID == R.LeftParen) // weight { RantAction weightAction = null; // i like this AddToOutput thing because it's just a delegate that takes in a RantAction. // it can do anything with the RantAction, in this case it sets it to our weightAction // :> yield return(Parselet.GetParselet("BlockWeight", readToken, a => weightAction = a)); constantWeights = constantWeights ?? new List <_ <int, double> >(); dynamicWeights = dynamicWeights ?? new List <_ <int, RantAction> >(); if (weightAction is RAText) // constant { var strWeight = (weightAction as RAText).Text; double d; if (!Util.ParseDouble(strWeight, out d)) { compiler.SyntaxError(weightAction.Range, $"Invalid weight value '{strWeight}'."); } constantWeights.Add(_.Create(sequences.Count, d)); } else // dynamic { // TODO: there's some weird issue going on with doubles being seen as dynamic weights dynamicWeights.Add(_.Create(sequences.Count, weightAction)); } continue; } else if (readToken.ID == R.Pipe) { // add action to block and continue sequences.Add(actions.Count == 1 ? actions[0] : new RASequence(actions, readToken)); reader.SkipSpace(); actions.Clear(); continue; } else if (readToken.ID == R.RightCurly) { // add action to block and return sequences.Add(actions.Count == 1 ? actions[0] : new RASequence(actions, readToken)); AddToOutput(new RABlock(Stringe.Range(token, readToken), sequences, dynamicWeights, constantWeights)); yield break; } yield return(Parselet.GetParselet(readToken, actions.Add)); } compiler.SyntaxError(token, "Unterminated block: unexpected end of file."); }