TokenStreamSelector.cs :  » Inversion-of-Control-Dependency-Injection » Spring.net » Spring » Expressions » Parser » antlr » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Inversion of Control Dependency Injection » Spring.net 
Spring.net » Spring » Expressions » Parser » antlr » TokenStreamSelector.cs
using System;
using HashtableSystem.Collections.Hashtable;
using StackSystem.Collections.Stack;
  
namespace Spring.Expressions.Parser.antlr{
  /*ANTLR Translator Generator
  * Project led by Terence Parr at http://www.jGuru.com
  * Software rights: http://www.antlr.org/license.html
  *
  * $Id:$
  */

  //
  // ANTLR C# Code Generator by Micheal Jordan
  //                            Kunle Odutola       : kunle UNDERSCORE odutola AT hotmail DOT com
  //                            Anthony Oguntimehin
  //
  // With many thanks to Eric V. Smith from the ANTLR list.
  //

  /*A token stream MUX (multiplexor) knows about n token streams
  *  and can multiplex them onto the same channel for use by token
  *  stream consumer like a parser.  This is a way to have multiple
  *  lexers break up the same input stream for a single parser.
  *  Or, you can have multiple instances of the same lexer handle
  *  multiple input streams; this works great for includes.
  */
  public class TokenStreamSelector : TokenStream
  {
    /*The set of inputs to the MUX */
    protected internal Hashtable inputStreamNames;
    
    /*The currently-selected token stream input */
    protected internal TokenStream input;
    
    /*Used to track stack of input streams */
    protected internal Stack streamStack = new Stack();
    
    public TokenStreamSelector() : base()
    {
      inputStreamNames = new Hashtable();
    }
    public virtual void  addInputStream(TokenStream stream, string key)
    {
      inputStreamNames[key] = stream;
    }
    /*Return the stream from tokens are being pulled at
    *  the moment.
    */
    public virtual TokenStream getCurrentStream()
    {
      return input;
    }
    public virtual TokenStream getStream(string sname)
    {
      TokenStream stream = (TokenStream) inputStreamNames[sname];
      if (stream == null)
      {
        throw new System.ArgumentException("TokenStream " + sname + " not found");
      }
      return stream;
    }
    public virtual IToken nextToken()
    {
      // return input.nextToken();
      // keep looking for a token until you don't
      // get a retry exception.
       for (; ; )
      {
        try
        {
          return input.nextToken();
        }
        catch (TokenStreamRetryException)
        {
          // just retry "forever"
        }
      }
    }
    public virtual TokenStream pop()
    {
      TokenStream stream = (TokenStream) streamStack.Pop();
      select(stream);
      return stream;
    }
    public virtual void  push(TokenStream stream)
    {
      streamStack.Push(input); // save current stream
      select(stream);
    }
    public virtual void  push(string sname)
    {
      streamStack.Push(input);
      select(sname);
    }
    /*Abort recognition of current Token and try again.
    *  A stream can push a new stream (for include files
    *  for example, and then retry(), which will cause
    *  the current stream to abort back to this.nextToken().
    *  this.nextToken() then asks for a token from the
    *  current stream, which is the new "substream."
    */
    public virtual void  retry()
    {
      throw new TokenStreamRetryException();
    }
    /*Set the stream without pushing old stream */
    public virtual void  select(TokenStream stream)
    {
      input = stream;
      if (input is CharScanner)
      {
        ((CharScanner) input).refresh();
      }
    }
    public virtual void  select(string sname)
    {
      input = getStream(sname);
      if (input is CharScanner)
      {
        ((CharScanner) input).refresh();
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.