Ejemplo n.º 1
0
        public void CheckCanParseThis()
        {
            var token = new LexedToken(new SourceRange(new SourcePosition("test", 1, 0, 0), new SourcePosition("test", 1, 1, 1)), PredefinedTokenTypes.This, "this");
            var expr  = new Parser().ParseExpression(new Parser().PutbackRangeFromTokens(Enumerable.Repeat(token, 1)), null);

            Assert.That(Equality.DeepEqual(expr, new This(new TokenASTLocation(token.Location))));
        }
Ejemplo n.º 2
0
 public static void AssertTokenTypeIs(this LexedToken token, LexedTokenType ExpectedTokenType)
 {
     if (token.TokenType != ExpectedTokenType)
     {
         throw new Exception(String.Format("Token type {0} Expected but {1} found", token.TokenType.ToString(), ExpectedTokenType.ToString()));
     }
 }
        /// <summary>
        /// Advances the enumerator.
        /// </summary>
        /// <returns>False if there are no more tokens</returns>
        private bool NextToken()
        {
            bool result = tokens.MoveNext();

            currentToken = tokens.Current;
            return(result);
        }
        public Parser(IEnumerable <LexedToken> tokens)
        {
            this.tokens  = tokens.GetEnumerator();
            currentToken = null;

            stack = new Stack <ParserState>();
        }
Ejemplo n.º 5
0
 public static void AssertTokenIs(this LexedToken token, LexedTokenType ExpectedTokenType, object ExpectedTokenValue)
 {
     token.AssertTokenTypeIs(ExpectedTokenType);
     if (token.TokenText != ExpectedTokenValue.ToString())
     {
         throw new Exception(String.Format("Token value {0} Expected but {1} found", ExpectedTokenValue.ToString(), token.TokenText.ToString()));
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// The constructor used to make a parsed token. This should be called when a token is completely parsed, and all of the
 /// child tokens are instantiated, so that this token can be instantiated.
 /// </summary>
 /// <param name="token">The identification token</param>
 /// <param name="children">The children of this token</param>
 public ParsedToken(LexedToken token, List <LexedToken> children = null)
 {
     _token = token;
     if (children != null)
     {
         _children.AddRange(children);
     }
 }
Ejemplo n.º 7
0
        public void ThrowsForInvalidTokenType()
        {
            var token = new LexedToken(new SourceRange(new SourcePosition("test", 1, 0, 0), new SourcePosition("test", 1, 1, 1)), new RandomTokenType(), "");

            Assert.Throws <ParserException>(() => new Parser().ParseExpression(new Parser().PutbackRangeFromTokens(Enumerable.Repeat(token, 1)), null));
        }