Beispiel #1
0
        public static TinyToken Parse(IEnumerable <TinyTokenizer.Token> tokens)
        {
            TinyToken result  = null;
            var       context = new ParseContext(tokens, r => result = r);

            TinyTokenizer.Token previousToken = null;
            while (context.CurrentToken != null)
            {
                if (context.CurrentToken != previousToken)
                {
                    //Debug.Print($"{context.CurrentToken}");
                    previousToken = context.CurrentToken;
                }

                switch (context.CurrentToken.TokenType)
                {
                case TinyTokenizer.TokenType.Indent:
                    context.Indent(context.CurrentToken.Value.Length / 2);
                    context.ConsumeToken();
                    continue;

                case TinyTokenizer.TokenType.EndLine:
                    context.NewLine();
                    context.ConsumeToken();
                    continue;
                }
                //Debug.Print($"  - {context.Parser.GetType().Name} ({context.ParserCount})");
                context.Parser.Parse(context);
            }

            while (context.Parser != null)
            {
                context.Parser.End();
                context.PopParser();
            }

            return(result);
        }
Beispiel #2
0
 public void ConsumeToken()
 {
     CurrentToken   = LookaheadToken;
     LookaheadToken = tokenEnumerator.MoveNext() ? tokenEnumerator.Current : null;
 }