public RichIfStatement(Stringe token, RichActionBase expr, RichActionBase body, RichActionBase elseBody = null) : base(token) { _expression = expr; _body = body; _elseBody = elseBody; }
public RichFunctionCall(Stringe token, RichActionBase function, RichGroup args, string _sourceName) : base(token) { _function = function; List <RichActionBase> argValues = new List <RichActionBase>(); if (args.Actions.Count > 0) { RichActionBase lastArg = null; for (var i = 0; i < args.Actions.Count; i++) { var action = args.Actions[i]; if (action is RichArgumentSeperator) { if (lastArg == null) { throw new RantCompilerException(_sourceName, Range, "Blank argument in function call."); } argValues.Add(lastArg); } else { lastArg = action; } } argValues.Add(lastArg); } _argValues = argValues.ToArray(); Returnable = true; }
public REAIfStatement(Stringe token, RantExpressionAction expr, RantExpressionAction body, RantExpressionAction elseBody = null) : base(token) { _expression = expr; _body = body; _elseBody = elseBody; }
public REAList(Stringe origin, List<RantExpressionAction> items, bool concatSyntax = true) : base(origin) { _items = items; Type = ActionValueType.List; _concatSyntax = concatSyntax; }
public RichObjectPropertyAssignment(Stringe origin, RichActionBase nameExp, RichActionBase obj, RichActionBase value) : base(origin) { Name = nameExp; _value = value; _object = obj; }
public RichFunctionCall(Stringe token, RichActionBase function, RichGroup args, string _sourceName) : base(token) { _function = function; List<RichActionBase> argValues = new List<RichActionBase>(); if (args.Actions.Count > 0) { RichActionBase lastArg = null; for (var i = 0; i < args.Actions.Count; i++) { var action = args.Actions[i]; if (action is RichArgumentSeperator) { if (lastArg == null) throw new RantCompilerException(_sourceName, Range, "Blank argument in function call."); argValues.Add(lastArg); } else lastArg = action; } argValues.Add(lastArg); } _argValues = argValues.ToArray(); Returnable = true; }
public RichGreaterThanOperator(Stringe origin, bool orEqual = false) : base(origin) { Type = ActionValueType.Boolean; _orEqual = orEqual; Precedence = 15; }
internal Chare(Stringe source, char c, int offset) { _src = source; _character = c; _offset = offset; _line = _column = 0; }
public RichLessThanOperator(Stringe origin, bool orEqual = false) : base(origin) { Type = ActionValueType.Boolean; _orEqual = orEqual; Precedence = 15; }
public RACallSubroutine(Stringe name, string moduleFunctionName = null) : base(name) { if (moduleFunctionName != null) _inModule = true; _moduleFunctionName = moduleFunctionName; }
public RAFunction(Stringe range, RantFunctionSignature funcInfo, List <RantAction> argActions) : base(range) { _funcInfo = funcInfo; _argActions = argActions; _argc = argActions.Count; }
public RichFunction(Stringe origin, RichActionBase body, RichGroup args) : base(origin) { List <string> argNames = new List <string>(); if (args.Actions.Count > 0) { string lastArg = ""; for (var i = 0; i < args.Actions.Count; i++) { var action = args.Actions[i]; if (action is RichArgumentSeperator) { argNames.Add(lastArg); } else { lastArg = (action as RichVariable).Name; } } argNames.Add(lastArg); } // reverse it, since things are popped from the object stack in reverse order argNames.Reverse(); _argNames = argNames.ToArray(); _body = body; Type = ActionValueType.Function; Returnable = true; }
public TagBlueprint(Interpreter interpreter, Source source, Stringe name, IEnumerable<Token<TokenType>>[] args = null) : base(interpreter) { Source = source; Name = name; if (!Interpreter.TagFuncs.TryGetValue(Name.Value.ToLower().Trim(), out _tagDef)) { throw new ManhoodException(Source, Name, "The tag '" + Name.Value + "' does not exist."); } _tagDef.ValidateArgCount(source, name, args != null ? args.Length : 0); if (args == null) { _args = Enumerable.Empty<TagArg>().ToArray(); } else { // Insert token arguments into the array, set string args to null. _args = args.Select((a, i) => _tagDef.ArgTypes[i] == TagArgType.Tokens ? TagArg.FromTokens(a) : null).ToArray(); // Queue string arguments on the stack. for (int i = 0; i < _tagDef.ArgTypes.Length; i++) { if (_tagDef.ArgTypes[i] == TagArgType.Result) { interpreter.PushState(Interpreter.State.CreateDerivedDistinct(source, args[i], interpreter)); } } } }
public RichList(Stringe origin, List<RichActionBase> items, bool concatSyntax = true) : base(origin) { _items = items; Type = ActionValueType.List; _concatSyntax = concatSyntax; }
private static bool CapsInfer(Interpreter interpreter, Source source, Stringe tagname, TagArg[] args) { // TODO: Make capsinfer properly infer "first" capitalization given multiple sentences. Currently, it mistakes it for "word" mode. var words = Regex.Matches(args[0].GetString(), @"\w+").OfType<Match>().Select(m => m.Value).ToArray(); int wCount = words.Length; int uCount = 0; int fwCount = 0; bool firstCharIsUpper = false; for (int i = 0; i < wCount; i++) { if (words[i].All(Char.IsUpper)) { uCount++; } if (Char.IsUpper(words[i][0])) { fwCount++; if (i == 0) firstCharIsUpper = true; } } if (uCount == wCount) { interpreter.CurrentState.Output.SetCaps(Capitalization.Upper); } else if (wCount > 1 && fwCount == wCount) { interpreter.CurrentState.Output.SetCaps(Capitalization.Word); } else if (firstCharIsUpper) { interpreter.CurrentState.Output.SetCaps(Capitalization.First); } return false; }
internal void SetToken(Stringe token) { _line = token.Line; _col = token.Column; _index = token.Offset; _length = token.Length; }
private static bool Nth(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { int offset, interval; if (!Int32.TryParse(args[0].GetString(), out interval)) { throw new RantException(source, tagname, "Invalid interval value."); } if (interval <= 0) { throw new RantException(source, tagname, "Interval must be greater than zero."); } if (!Int32.TryParse(args[1].GetString(), out offset)) { throw new RantException(source, tagname, "Invalid offset value."); } if (interpreter.CurrentRepeater == null || !interpreter.CurrentRepeater.Nth(offset, interval)) { return(false); } interpreter.PushState(State.CreateDerivedDistinct(source, args[2].GetTokens(), interpreter, interpreter.CurrentState.Output)); return(true); }
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"); }
public RAFunction(Stringe range, RantFunctionInfo funcInfo, List<RantAction> argActions) : base(range) { _funcInfo = funcInfo; _argActions = argActions; _argc = argActions.Count; }
private static bool Arg(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { if (!interpreter.SubArgStack.Any()) { throw new RantException(source, tagname, "Tried to access arguments outside of a subroutine body."); } Argument arg; var argName = args[0].GetString().Trim(); if (!interpreter.SubArgStack.Peek().TryGetValue(argName, out arg)) { throw new RantException(source, tagname, "Could not find argument '" + argName + "'."); } // Argument is string if (arg.Flags == ParamFlags.None) { interpreter.Print(arg.GetString()); return(false); } // Argument is tokens interpreter.PushState(State.CreateDerivedShared(source, arg.GetTokens(), interpreter)); return(true); }
public REAObjectPropertyAssignment(Stringe origin, RantExpressionAction nameExp, RantExpressionAction obj, RantExpressionAction value) : base(origin) { Name = nameExp; _value = value; _object = obj; }
public RichList(Stringe origin, List <RichActionBase> items, bool concatSyntax = true) : base(origin) { _items = items; Type = ActionValueType.List; _concatSyntax = concatSyntax; }
public RichWhile(Stringe token, RichActionBase test, RichActionBase body) : base(token) { _test = test; _body = body; Breakable = true; }
internal RantPattern(string name, RantPatternSource type, string code) { _name = name; _type = type; _code = code; _stringe = code.ToStringe(); _tokens = RantLexer.GenerateTokens(_stringe); }
internal Chare(Stringe source, char c, int offset, int line, int col) { _src = source; _character = c; _offset = offset; _line = line; _column = col; }
public REAWhile(Stringe token, RantExpressionAction test, RantExpressionAction body) : base(token) { _test = test; _body = body; Breakable = true; }
internal RantTableLoadException(string origin, Stringe token, string message) : base($"{origin}: (Ln {token.Line}, Col {token.Column}) {message}") { Line = token.Line; Column = token.Column; Offset = token.Offset; Origin = origin; }
public RichObject(Stringe token, RichObjectKeyValue[] values) : base(token) { Type = ActionValueType.Object; Values = new Dictionary<string, RichActionBase>(); foreach (RichObjectKeyValue val in values) Values[val.Name] = val.Value; }
private static bool Else(Interpreter interpreter, RantPattern source, Stringe tagname, Argument[] args) { if (!interpreter.UseElse()) { return(false); } interpreter.PushState(Interpreter.State.CreateSub(source, args[0].GetTokens(), interpreter, interpreter.CurrentState.Output)); return(true); }
private static bool Extern(VM vm, RantPattern source, Stringe tagname, Argument[] args) { var name = args[0].AsString(); var result = vm.Engine.CallHook(name, args.Skip(1).Select(arg => arg.AsString()).ToArray()); if (result == null) { throw Error(source, tagname, "A hook with the name '\{name}' does not exist."); }
private static bool Else(VM vm, RantPattern source, Stringe tagname, Argument[] args) { if (!vm.UseElse()) { return(false); } vm.PushState(VM.State.CreateSub(source, args[0].AsPattern(), vm, vm.CurrentState.Output)); return(true); }
public RACallSubroutine(Stringe name, string moduleFunctionName = null) : base(name) { if (moduleFunctionName != null) { _inModule = true; } _moduleFunctionName = moduleFunctionName; }
private static bool First(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { if (interpreter.CurrentRepeater == null || !interpreter.CurrentRepeater.IsFirst) { return(false); } interpreter.PushState(State.CreateDerivedDistinct(source, args[0].GetTokens(), interpreter, interpreter.CurrentState.Output)); return(true); }
internal RantPattern(string name, RantPattern derived, IEnumerable <Token <R> > sub) { _name = name; _type = derived._type; _code = derived._code; _stringe = derived._stringe; _blockJumpTable = derived._blockJumpTable; _tokens = sub; }
private static bool RepNum(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { if (interpreter.CurrentRepeater == null) { throw new RantException(source, tagname, "No active repeaters."); } interpreter.Print(interpreter.FormatNumber(interpreter.CurrentRepeater.Index + 1)); return(false); }
private static bool Alt(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { var testState = State.CreateDerivedDistinct(source, args[0].GetTokens(), interpreter, interpreter.CurrentState.Output); testState.AddPostBlueprint(new AltBlueprint(interpreter, testState, args[1].GetTokens())); interpreter.PushState(testState); return(true); }
private static bool Else(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { if (!interpreter.UseElse()) { return(false); } interpreter.PushState(State.CreateDerivedShared(source, args[0].GetTokens(), interpreter)); return(true); }
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); }
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))); }
/// <summary> /// Generates beautiful tokens. /// </summary> /// <param name="input">The input string to tokenize.</param> /// <returns></returns> public static IEnumerable <Token <R> > GenerateTokens(Stringe input) { var reader = new StringeReader(input); while (!reader.EndOfStringe) { yield return(reader.ReadToken(Rules)); } }
public RantFunctionInfo GetFunctionInfo(RantFunctionGroup group, int argc, Stringe from, Stringe to) { var func = group.GetFunction(argc); if (func == null) SyntaxError(Stringe.Between(from, to), $"No overload of function '{group.Name}' can take {argc} arguments"); return func; }
private static bool IfDef(Interpreter interpreter, Source source, Stringe tagname, Argument[] args) { if (interpreter.Engine.Flags.Contains(args[0])) { interpreter.PushState(State.CreateDerivedShared(source, args[1].GetTokens(), interpreter)); return(true); } interpreter.SetElse(); return(false); }
private static bool IfDef(Interpreter interpreter, RantPattern source, Stringe tagname, Argument[] args) { if (interpreter.Engine.Flags.Contains(args[0])) { interpreter.PushState(Interpreter.State.CreateSub(source, args[1].GetTokens(), interpreter, interpreter.CurrentState.Output)); return(true); } interpreter.SetElse(); return(false); }
public static RantExpressionAction ConvertToAction(Stringe token, object value) { if (value is double) return new REANumber((double)value, token); if (value is string) return new REAString((string)value, token); if (value is bool) return new REABoolean(token, (bool)value); return value as RantExpressionAction; }
private static bool IfDef(VM vm, RantPattern source, Stringe tagname, Argument[] args) { if (vm.Engine.Flags.Contains(args[0])) { vm.PushState(VM.State.CreateSub(source, args[1].AsPattern(), vm, vm.CurrentState.Output)); return(true); } vm.SetElse(); return(false); }
public RichObject(Stringe token, RichObjectKeyValue[] values) : base(token) { Type = ActionValueType.Object; Values = new Dictionary <string, RichActionBase>(); foreach (RichObjectKeyValue val in values) { Values[val.Name] = val.Value; } }
public static RichActionBase ConvertToAction(Stringe token, object value) { if (value is double) return new RichNumber((double)value, token); if (value is string) return new RichString((string)value, token); if (value is bool) return new RichBoolean(token, (bool)value); return value as RichActionBase; }
private static bool Extern(Interpreter interpreter, Source source, Stringe tagname, TagArg[] args) { var name = args[0].GetString(); var result = interpreter.Engine.Hooks.Call(name); if (result == null) { throw new ProcessusException(source, tagname, "A hook with the name '" + name + "' does not exist."); } interpreter.Print(result); return false; }
public RichGroup(IEnumerable<RichActionBase> actions, Stringe token, string sourceName) : base(token) { Type = ActionValueType.Number; Actions = (List<RichActionBase>)actions; if (Actions.Any(x => x is RichConcatOperator)) Type = ActionValueType.String; Condense(); _origin = token; _sourceName = sourceName; }
internal RantCompilerException(string name, Stringe source, string message) : base(source != null ? $"{name} @ Line {source.Line}, Col {source.Column}: {message}" : $"{name}: {message}") { if (source == null) return; Line = source.Line; Column = source.Column; Index = source.Offset; Length = source.Length; }
public REAFor( Stringe token, string indexName, RantExpressionAction body, RantExpressionAction expr) : base(token) { _expr = expr; _body = body; _indexName = indexName; }
public RichFor( Stringe token, string indexName, RichActionBase body, RichActionBase expr) : base(token) { _expr = expr; _body = body; _indexName = indexName; }
internal ManhoodException(Source source, Stringe token, string message = "A generic syntax error was encountered.") : base((token != null ? ("(Ln " + token.Line + ", Col " + token.Column + ") - ") : "") + message) { _source = source.Code; if (token != null) { _line = token.Line; _col = token.Column; _index = token.Offset; _length = token.Length; } else { _line = _col = 1; _index = 0; _length = 0; } }
internal RantRuntimeException(RantPattern source, Stringe token, string message = "A generic syntax error was encountered.") : base((token != null ? ($"({source.Name} @ Ln {token.Line}, Col {token.Column}): ") : "") + message) { _source = source.Code; if (token != null) { _line = token.Line; _col = token.Column; _index = token.Offset; _length = token.Length; } else { _line = _col = 1; _index = 0; _length = 0; } }
public RABlock(Stringe range, List<RantAction> items, List<_<int, RantAction>> dynamicWeights, List<_<int, double>> constantWeights) : base(range) { _items.AddRange(items); _count = items.Count; if (dynamicWeights != null && constantWeights != null) { _dynamicWeights = dynamicWeights; _weights = new double[_count]; for (int i = 0; i < _count; i++) _weights[i] = 1; foreach (var cw in constantWeights) { _weights[cw.Item1] = cw.Item2; } _constantWeightSum = _weights.Sum() - _dynamicWeights.Count; _weighted = true; } }