Example #1
0
        public void Array(string input, int arrayDimension, DescriptorTokenKind tokenKind)
        {
            var lexer  = new DescriptorLexer(input.AsMemory());
            var tokens = Utils.GetAllTokens(lexer.Lex());

            Assert.Equal(2 + arrayDimension, tokens.Count);
            Assert.Equal(tokenKind, tokens[arrayDimension].Kind);
        }
Example #2
0
        private static void Commence(string input, DescriptorTokenKind tokenKind)
        {
            var lexer  = new DescriptorLexer(input.AsMemory());
            var tokens = Utils.GetAllTokens(lexer.Lex());

            Assert.Equal(2, tokens.Count);
            Assert.True(tokens[0].Kind == tokenKind, $"Expected <{tokenKind}>, but got <{tokens[0].Kind}>.");
        }
Example #3
0
        private static void Commence(string input, DescriptorTokenKind tokenKind, int tokenKindCount)
        {
            var lexer  = new DescriptorLexer(input.AsMemory());
            var tokens = Utils.GetAllTokens(lexer.Lex());

            Assert.Equal(1 + tokenKindCount, tokens.Count);
            Assert.All(tokens, token =>
            {
                var type = token.Kind;
                Assert.True(type == tokenKind || type == DescriptorTokenKind.EndOfFile);
            });
        }
Example #4
0
 /// <summary>
 /// Creates a new <see cref="DescriptorToken"/>.
 /// </summary>
 /// <param name="span">The <see cref="TextSpan"/> indicating the start and the end positions.</param>
 /// <param name="kind">The type of the token.</param>
 /// <param name="value">The raw text.</param>
 public DescriptorToken(TextSpan span, DescriptorTokenKind kind, ReadOnlyMemory <char> value)
 {
     Span  = span;
     Kind  = kind;
     Value = value;
 }
Example #5
0
 /// <summary>
 /// Throws a <see cref="DescriptorParserException"/> with an unexpected token message.
 /// </summary>
 /// <param name="token">The <see cref="DescriptorToken"/> that wasn't expected.</param>
 /// <param name="expected">The token that was expected.</param>
 public static void ThrowUnexpectedToken(DescriptorToken token, DescriptorTokenKind expected) =>
 throw new DescriptorParserException($"Unexpected token <{token.Kind}>, expected <{expected}>.");