public INode Parse(ITokenEnumerator input, bool autoDisposing)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (OnParsePrepare() == false)
            {
                return(null);
            }

            Stack <int>   tempstack = new Stack <int>();
            Stack <INode> tempnodes = new Stack <INode>();

            m_handler.Reset();

            input.MoveNext();
            INode result = OnParse(input, tempstack, tempnodes);

            tempstack.Clear();
            tempnodes.Clear();

            if (autoDisposing)
            {
                input.Dispose();
            }

            OnParseCleanup(m_handler.FailCount > 0);
            return(result);
        }
        /// <summary>
        /// Skips tokens in the stream while the token kind is the same as the supplied kind.
        /// </summary>
        /// <param name="enumerator">The enumerator to perform the operation on.</param>
        /// <param name="kind">The token kind to test against to determine whether the token should be skipped.</param>
        public static void Skip(this ITokenEnumerator enumerator, TokenKind kind)
        {
            if (enumerator == null)
            {
                throw new ArgumentNullException(nameof(enumerator));
            }

            Skip(enumerator, t => t.Kind == kind);
        }
Beispiel #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (source != null)
            {
                source.Dispose();
                source = null;
            }

            current = null;
        }
        /// <summary>
        /// Skips tokens in the stream while the given predicate is true.
        /// </summary>
        /// <param name="enumerator">The enumerator to perform the operation on.</param>
        /// <param name="predicate">The predicate to use for evaluating whether or not to consume a token.</param>
        public static void Skip(this ITokenEnumerator enumerator, Func <Token, bool> predicate)
        {
            if (enumerator == null)
            {
                throw new ArgumentNullException(nameof(enumerator));
            }

            while (predicate(enumerator.Peek()))
            {
                enumerator.Take();
            }
        }
Beispiel #5
0
 public Append(ITokenEnumerator enm, Token value)
 {
     IsInnerEOF = false;
     Enm = enm;
     Value = value;
 }
Beispiel #6
0
 public Prepend(ITokenEnumerator enm, Token value)
 {
     IsFirst = true;
     Enm = enm;
     Value = value;
 }
Beispiel #7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="options">The SMTP server options.</param>
 /// <param name="enumerator">The token enumerator to handle the incoming tokens.</param>
 public SmtpParser(ISmtpServerOptions options, ITokenEnumerator enumerator) : base(enumerator)
 {
     _options = options;
 }
Beispiel #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="enumerator">The token enumerator to handle the incoming tokens.</param>
 protected TokenParser(ITokenEnumerator enumerator)
 {
     Enumerator = enumerator;
 }
 public static INode Parse(Grammar g, ITokenEnumerator tokE) => new LALRParser(g).Parse(tokE);
Beispiel #10
0
 public void Init(ITokenEnumerator tokens)
 {
     Token src;
     src = new Token();
     src.Value = Token.ZSourceValue;
     Tokens = new Prepend(tokens, src);
     Tokens = new Append(Tokens, Token.ZEnd);
     InfixAzr.Init(Tokens);
     PrefixAzr.Init(Tokens);
 }
Beispiel #11
0
        public void Test()
        {
            Func<TestCase, string> f = delegate(TestCase c)
            {
                TokenizerBase tkz = new ScriptTokenizer();
                LineBufferedReader r = LineBufferedReader.GetInstanceWithText(c.Input, /*path*/ "");
                tkz.Init(r);

                ITokenEnumerator tokens = tkz;

                Token src;
                src = new Token();
                src.Value = Token.ZSourceValue;
                Tokens = new Prepend(tokens, src);
                Tokens = new Append(Tokens, Token.ZEnd);
                string cur = Tokens.Cur.ToString();
                return cur;
            };

            new TestCase("", Inp, Epc, f).Run();
        }
 public INode Parse(ITokenEnumerator inpu) => Parse(inpu, true);
 public TypeNameFixPP(ITokenEnumerator source, bool ignoreEOL) : base(source, ignoreEOL)
 {
 }
Beispiel #14
0
 protected PreParserBase(ITokenEnumerator source, bool ignoreEOL)
 {
     this.source    = source;
     this.ignoreEOL = ignoreEOL;
     current        = Token.Empty;
 }