public void Dispatch(CharToken token) { this.currentWordToken.AddChar(token); this.isWhitespace = false; this.isNewline = false; }
public static Expectation<CharToken> ExpectEquals(CharToken identifier, CharToken next) { if (next.IsOperatorOf("=")) return Expectation.Valid(identifier); else return Expectation.Invalid(next, "Expected equals operator"); }
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); }
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"); }
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); }
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); }
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); }
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. }