public ParseletToken(Parselet <TInput, TValue, TOutput> parselet, TValue value) { _parselet = parselet; Value = value; TokenTypeId = _parselet.TokenTypeId; LeftBindingPower = _parselet.Lbp; RightBindingPower = _parselet.Rbp; Name = _parselet.Name ?? string.Empty; IsValid = true; }
public RantCompiler(string sourceName, string source) { Module = new RantModule(sourceName); this.source = source; this.sourceName = sourceName; reader = new TokenReader(sourceName, RantLexer.GenerateTokens(sourceName, source.ToStringe())); richardCompiler = new RichardCompiler(sourceName, source, reader, this); Parselet.SetCompilerAndReader(this, reader); }
public RantAction Read() { var output = new List <RantAction>(); // NOTE: since parselets are more like containers for multiple parsers, maybe figure out something to stuff a stack full of rather than parselets //var parseletStack = new Stack<Parselet>(); var enumeratorStack = new Stack <IEnumerator <Parselet> >(); Token <R> token = null; while (!reader.End) { token = reader.ReadToken(); if (token.ID == R.EOF) { goto done; } var parselet = Parselet.GetParselet(token, output.Add); //parseletStack.Push(parselet); enumeratorStack.Push(parselet.Parse()); top: while (enumeratorStack.Any()) { var enumerator = enumeratorStack.Peek(); while (enumerator.MoveNext()) { if (enumerator.Current == null) { break; } //parseletStack.Push(enumerator.Current); enumeratorStack.Push(enumerator.Current.Parse()); goto top; } //parseletStack.Pop(); enumeratorStack.Pop(); } } done: return(new RASequence(output, token)); }
static RantEngine() { RantFunctionRegistry.Load(); Parselet.Load(); }