Exemple #1
0
        public void Dispatch(CharToken token)
        {
            this.currentWordToken.AddChar(token);

            this.isWhitespace = false;
            this.isNewline    = false;
        }
Exemple #2
0
 public static Expectation<CharToken> ExpectEquals(CharToken identifier, CharToken next)
 {
     if (next.IsOperatorOf("="))
         return Expectation.Valid(identifier);
     else
         return Expectation.Invalid(next, "Expected equals operator");
 }
Exemple #3
0
 public static Expectation<CharToken> ExpectIdentifier(CharToken next)
 {
     if (next.Kind != DjinniLexTokenKind.Word)
         return Expectation.Invalid(next, "Identifier must be a word");
     if (!char.IsLetter(next.Contents.FirstOrDefault()))
         return Expectation.Invalid(next, "Identifier must begin with a letter");
     return Expectation.Valid(next);
 }
Exemple #4
0
        public void Extract_ReturnsCharTokenFromSource()
        {
            var mockSource = Mock.Of <ISource>(x => x.NextChar() == 'A');

            var charToken = new CharToken(mockSource);

            charToken.Extract();

            charToken.Text.Should().Be("A");
        }
Exemple #5
0
        private CharToken ParseCloseBrace()
        {
            if (BraceDepth <= 0)
            {
                throw new ExceptedTokenException("OPEN_BRACE_NOT_FOUND", "Cannot close unopened brace");
            }
            CharToken token = new CharToken(Stream.Current, Stream.Index);

            BraceDepth--;

            return(token);
        }
Exemple #6
0
        private CharToken ParseOpenBrace()
        {
            CharToken token = new CharToken(Stream.Current, Stream.Index);

            BraceDepth++;

            if (!Stream.HasMore)
            {
                throw new ExceptedTokenException("UNCLOSED_BRACE", "The brace must be closed");
            }

            return(token);
        }
Exemple #7
0
        protected override Token ExtractToken()
        {
            Token token;
            var   currentChar = CurrentChar();

            // Construct the next token.  The current character determines the
            // token type.
            if (currentChar == Constants.EOF)
            {
                token = new EofToken(Source);
            }
            else
            {
                token = new CharToken(Source);
            }

            return(token);
        }
Exemple #8
0
 public static Expectation<(CharToken, TypeKind)> ExpectKeyword(CharToken identifier, CharToken keyword)
 {
     if (Enum.TryParse<TypeKind>(new string(keyword.Contents.ToArray()), out var kind))
         return // bugger. type system ahoy.
 }