public static object ParseStringLiteral(char ch, StringIterator reader) { if (ch != '"') { return(null); } var builder = new StringBuilder(); reader.Read(); while (true) { var pk = reader.Peek(); if (pk == -1) { break; } ch = (char)pk; if (ch == '"') { reader.Read(); break; } builder.Append(ch); reader.Read(); } return(builder); }
public static object ParseIdentifier(char ch, StringIterator reader) { if (!char.IsLetter(ch) && ch != '_') { return(null); } var builder = new StringBuilder(); builder.Append(ch); reader.Read(); while (true) { var pk = reader.Peek(); if (pk == -1) { break; } ch = (char)pk; if (!char.IsLetterOrDigit(ch) && ch != '_') { break; } builder.Append(ch); reader.Read(); } return(builder.ToString()); }
public static object EatWhitespace(char ch, StringIterator reader) { if (char.IsWhiteSpace(ch)) { reader.Read(); return(Eat); } else { return(null); } }
public static object ParseFloat(char ch, StringIterator reader) { if (!char.IsDigit(ch) && !(ch == '-' && char.IsDigit((char)reader.Peek(2)))) { return(null); } var builder = new StringBuilder(); builder.Append(ch); reader.Read(); //read while (true) { var pk = reader.Peek(); if (pk == -1) { break; } ch = (char)pk; if (ch == 'e') { if (reader.Peek(2) == (int)'-' || reader.Peek(2) == (int)'+') { reader.Read(); builder.Append("e"); builder.Append((char)reader.Read()); } } else if (ch != '.' && !char.IsDigit(ch)) { break; } else { builder.Append(ch); reader.Read(); } } return(float.Parse(builder.ToString(), CultureInfo.InvariantCulture)); }
public static object ParseComment(char ch, StringIterator reader) { if (ch != '-' || (char)reader.Peek(2) != '-') { return(null); } while (true) { int pk = reader.Peek(); if (pk == -1 || pk == (char)'\n') { break; } reader.Read(); } return(Eat); }