示例#1
0
        public idToken ExpectTokenType(TokenType type, TokenSubType subType)
        {
            idToken token;

            if ((token = ReadToken()) == null)
            {
                Error("couldn't read expected token");
                return(null);
            }
            else if (token.Type != type)
            {
                Error("expected a '{0}' but found '{1}'", type.ToString().ToLower(), token.ToString());
                return(null);
            }
            else if (token.Type == TokenType.Number)
            {
                if ((token.SubType & subType) != subType)
                {
                    Error("expected '{0}' but found '{1}'", subType.ToString().ToLower(), token.ToString());
                    return(null);
                }
            }
            else if (token.Type == TokenType.Punctuation)
            {
                if (token.SubType != subType)
                {
                    Error("expected '{0}' but found '{1}'", _scriptStack.Peek().GetPunctuationFromID(subType), token.ToString());
                    return(null);
                }
            }

            return(token);
        }
示例#2
0
        private static void TestNumber(string code, TokenSubType targetType)
        {
            var tokenizer = new Tokenizer(code, new TokenizerOptions());

            Assert.IsTrue(
                TokenizationTestUtils.Match(
                    tokenizer.GetNextToken(),
                    new Token(
                        0, code, 0, 0,
                        Tokenizer.State.Context.Global,
                        TokenType.Number, targetType
                        )
                    ),
                $"Should tokenize number '{code}' and classify it as '{targetType.ToString()}'"
                );
            TokenizationTestUtils.TestEOF(tokenizer);
        }
示例#3
0
		public idToken ExpectTokenType(TokenType type, TokenSubType subType)
		{
			idToken token;

			if((token = ReadToken()) == null)
			{
				Error("couldn't read expected token");
				return null;
			}

			string tokenValue = token.ToString();

			if(token.Type != type)
			{
				Error("expected a '{0}' but found '{1}'", type.ToString().ToLower(), tokenValue);
				return null;
			}
			else if(token.Type == TokenType.Number)
			{
				if((token.SubType & subType) != subType)
				{
					Error("expected '{0}' but found '{1}'", subType.ToString().ToLower(), tokenValue);
					return null;
				}
			}
			else if(token.Type == TokenType.Punctuation)
			{
				if(token.SubType != subType)
				{
					Error("expected '{0}' but found '{1}'", GetPunctuationFromID(subType), tokenValue);
					return null;
				}
			}

			return token;
		}