private void AdvanceUntil(LexemeKind kind) { while (Current.Kind != kind) { Advance(); } }
public Lexeme(LexemeKind kind, SourceLocation begin, SourceLocation end, string content) { this.Kind = kind; this.Begin = begin; this.End = end; this.Content = content; }
private Lexeme Lexeme(LexemeKind kind) { var content = Builder.ToString(); Builder.Clear(); return(Lexeme(kind, content)); }
private bool Peek(LexemeKind kind, bool ignoreWhitespace = true) { if (ignoreWhitespace) { SkipWhitespaces(); } return(Index < Lexemes.Length - 1 && Lexemes[Index + 1].Kind == kind); }
private Lexeme Lexeme(LexemeKind kind, string content = null) { content = content ?? Buffer; Buffer = ""; var begin = Location; var end = new SourceLocation(Line, Column + content.Length, Index + content.Length); return(new Lexeme(kind, begin, end, content)); }
private Lexeme Lexeme(LexemeKind kind, string content = null) { if (kind == LexemeKind.NewLine) { Column = 0; Line++; } content = content ?? kind.GetCharacter() ?? Buffer.ToString(); Buffer.Clear(); return(new Lexeme(kind, Location, content)); }
private Lexeme Take(LexemeKind lexemeKind, bool ignoreWhitespace = true) { if (ignoreWhitespace) { SkipWhitespaces(); } if (Current.Kind != lexemeKind) { Error($"Unexpected lexeme: expected {lexemeKind}, found {Current}"); } return(TakeAny()); }
private Lexeme Take(LexemeKind lexemeKind, string expected = null, bool ignoreWhitespace = true) { if (ignoreWhitespace) { SkipWhitespaces(); } if (Current.Kind != lexemeKind) { var lexemeChar = lexemeKind.GetCharacter(); Error($"expected {expected ?? lexemeKind.ToString()}{(lexemeChar != null ? $" '{lexemeChar}'" : "")}, found '{Current.Content}' ({Current.Kind})"); } return(TakeAny()); }
private bool Take(LexemeKind lexemeKind, out Lexeme lexeme, bool ignoreWhitespace = true) { if (ignoreWhitespace) { SkipWhitespaces(); } if (Current.Kind == lexemeKind) { lexeme = TakeAny(); return(true); } lexeme = null; return(false); }
private Lexeme Lexeme(LexemeKind kind, string content) => new Lexeme(kind, content, new SourceLocation(Line, Column - (content?.Length ?? 0)));
public static string GetCharacter(this LexemeKind kind) { return(CharCache.TryGetValue(kind, out var c) ? c : CharCache[kind] = typeof(LexemeKind).GetField(kind.ToString()).GetCustomAttribute <DescriptionAttribute>()?.Description); }
public Lexeme(LexemeKind kind) { Kind = kind; }
public Lexeme(LexemeKind kind, string content, SourceLocation location) { this.Kind = kind; this.Content = content; this.Location = location; }