Ejemplo n.º 1
0
        /// <summary>
        /// Accept the specified token and value.
        /// </summary>
        /// <param name="token">Token.</param>
        /// <param name="strval">Strval.</param>
        public bool Accept(LoreToken token, string strval)
        {
            var match = Match(token) && Match(strval);

            Skip(match ? 1 : 0);
            return(match);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Accept the specified token.
        /// </summary>
        /// <param name="token">Token.</param>
        public bool Accept(LoreToken token)
        {
            var match = Match(token);

            Skip(match ? 1 : 0);
            return(match);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Expect the specified token and string.
        /// </summary>
        /// <param name="token">Token.</param>
        /// <param name="strval">Strval.</param>
        public Lexeme <LoreToken> Expect(LoreToken token, string strval)
        {
            var current = Current;

            if (Accept(token, strval))
            {
                return(current);
            }
            if (!See())
            {
                throw LoreException.Create(Location).Describe("Unexpected end of file.");
            }
            var next = Read();

            throw LoreException.Create(Location).Describe($"Unexpected token: '{next.Value}' ({next.Token})");
        }
Ejemplo n.º 4
0
 public bool Match(LoreToken token, string strval) => Current != null && Match(token) && Match(strval);
Ejemplo n.º 5
0
 public bool Match(LoreToken token) => Current != null && Current.Token == token;