Exemple #1
0
        public TokenStreamVisualizerForm(ITokenStream tokenStream)
        {
            if (tokenStream == null)
            {
                throw new ArgumentNullException("tokenStream");
            }

            InitializeComponent();

            List <IToken> tokens = new List <IToken>();

            int marker          = tokenStream.Mark();
            int currentPosition = tokenStream.Index;

            try
            {
                tokenStream.Seek(0);
                while (tokenStream.LA(1) != CharStreamConstants.EndOfFile)
                {
                    tokenStream.Consume();
                }

                for (int i = 0; i < tokenStream.Count; i++)
                {
                    tokens.Add(tokenStream.Get(i));
                }
            }
            finally
            {
                tokenStream.Rewind(marker);
            }

            this._tokenStream = tokenStream;
            this._tokens      = tokens.ToArray();

            if (tokenStream.TokenSource != null)
            {
                this._tokenNames = tokenStream.TokenSource.TokenNames;
            }

            this._tokenNames = this._tokenNames ?? new string[0];

            UpdateTokenTypes();
            UpdateHighlighting();

            listBox1.BackColor = Color.Wheat;
        }
Exemple #2
0
        protected bool EvaluatePredicate(System.Action predicate)
        {
            state.backtracking++;
            int start = input.Mark();

            try
            {
                predicate();
            }
            catch (RecognitionException re)
            {
                System.Console.Error.WriteLine("impossible: " + re);
            }
            bool success = !state.failed;

            input.Rewind(start);
            state.backtracking--;
            state.failed = false;
            return(success);
        }
        public TokenStreamVisualizerForm( ITokenStream tokenStream )
        {
            if (tokenStream == null)
                throw new ArgumentNullException("tokenStream");

            InitializeComponent();

            List<IToken> tokens = new List<IToken>();

            int marker = tokenStream.Mark();
            int currentPosition = tokenStream.Index;
            try
            {
                tokenStream.Seek(0);
                while (tokenStream.LA(1) != CharStreamConstants.EndOfFile)
                    tokenStream.Consume();

                for (int i = 0; i < tokenStream.Count; i++)
                    tokens.Add(tokenStream.Get(i));
            }
            finally
            {
                tokenStream.Rewind(marker);
            }

            this._tokenStream = tokenStream;
            this._tokens = tokens.ToArray();

            if (tokenStream.TokenSource != null)
                this._tokenNames = tokenStream.TokenSource.TokenNames;

            this._tokenNames = this._tokenNames ?? new string[0];

            UpdateTokenTypes();
            UpdateHighlighting();

            listBox1.BackColor = Color.Wheat;
        }
Exemple #4
0
 public virtual void Rewind(int marker)
 {
     dbg.Rewind(marker);
     input.Rewind(marker);
 }