Entry ParseEntry(BibTexDatabase database, string entryType) { var entryName = Consume(TokenType.Text).Data; var entry = new Entry(entryType, entryName, Helper.GetClassificationForType(entryType)); while (true) { var token = Consume(); switch (token.TokenType) { case TokenType.EOF: return(entry); case TokenType.ClosingBrace: return(entry); case TokenType.Equals: break; case TokenType.Comma: break; case TokenType.Text: ParseTag(database, entry, token.Data); break; case TokenType.OpeningBrace: break; default: throw new TemplateParseException("Unexpected token: " + token.TokenType, currentToken.Line, currentToken.Column); } } }
void ParseRootEntry(BibTexDatabase database) { Consume(TokenType.At); var entryType = Consume(TokenType.Text).Data; Consume(TokenType.OpeningBrace); switch (entryType.ToLower()) { case "string": ParseAbbreviation(database); break; case "preamble": ParsePreamble(); break; case "comment": ParseComment(); break; default: var entry = ParseEntry(database, entryType); database.AddEntry(entry); //Console.WriteLine("@{0}{{{1},", entry.EntryType, entry.Name); break; } }
void ParseTag(BibTexDatabase database, Entry entry, string tagName) { Consume(TokenType.Equals); string value = null; Token LastToken; while (true) { LastToken = Current; switch (Current.TokenType) { case TokenType.QuotedString: value += Consume().Data; break; case TokenType.BracedString: value += Consume().Data; break; case TokenType.Text: var token = Consume().Data; value += database.GetAbbreviation(token, token); break; case TokenType.Hash: break; default: throw new NotImplementedException(); } // [Allen] Check the invalid token like: // ************************* // owner = {Norman} # LastToken.TokenType == TokenType.BracedString // timestamp = {2012-07-19} # Current.TokenType == TokenType.Text // ************************* if (LastToken.TokenType == TokenType.BracedString && Current.TokenType == TokenType.Text) { throw new TemplateParseException("Unexpected token: " + LastToken.TokenType + ". Was expecting: '" + LastToken.Data + ",'", LastToken.Line, LastToken.Column); } if (Current.TokenType != TokenType.Hash) { break; } Consume(); } entry.AddTag(new TagEntry(tagName, value)); }
public BibTexDatabase CreateSubsetDatabase(params string[] keys) { var result = new BibTexDatabase(abbreviations); foreach (var key in keys) { var entry = this[key]; if (entry == null) { continue; } result.AddEntry(entry); } return(result); }
void ParseAbbreviation(BibTexDatabase database) { var entryName = Consume(TokenType.Text).Data; Consume(TokenType.Equals); var entryValue = Consume().Data; // Consume any trailing comma if (Current.TokenType == TokenType.Comma) { Consume(); } Consume(TokenType.ClosingBrace); //Console.WriteLine("@string{{{0} = \"{1}\"}}", entryName, entryValue); database.AddAbbreviation(entryName, entryValue); }
void ParseTag(BibTexDatabase database, Entry entry, string tagName) { Consume(TokenType.Equals); string value = null; while (true) { switch (Current.TokenType) { case TokenType.QuotedString: value += Consume().Data; break; case TokenType.BracedString: value += Consume().Data; break; case TokenType.Text: var token = Consume().Data; value += database.GetAbbreviation(token, token); break; case TokenType.Hash: break; default: throw new NotImplementedException(); } if (Current.TokenType != TokenType.Hash) { break; } Consume(); } entry.AddTag(new TagEntry(tagName, value)); }
public BibTexDatabase Parse() { var database = new BibTexDatabase(); Consume(); while (true) { switch (Current.TokenType) { case TokenType.EOF: return(database); case TokenType.At: ParseRootEntry(database); break; default: Consume(); break; } } }