private static bool TryReadNumberToken(PositionedChar[] chars, ref int index, out NumberToken token) { int startIndex = index; List <PositionedChar> tokenChars = new List <PositionedChar>(); bool read; char c; do { c = chars[index].Value; read = char.IsDigit(c) || c == '.'; if (read) { tokenChars.Add(chars[index]); index++; } }while (read && index < chars.Length); if (!tokenChars.Any() || (tokenChars.Count == 1 && tokenChars[0].Value == '.')) { index = startIndex; token = null; return(false); } string readString = PositionedChar.CreateString(tokenChars); if (double.TryParse(readString, NumberToken.AllowedStyle, CultureInfo.InvariantCulture, out double d)) { token = new NumberToken(chars[startIndex].Index, chars[index - 1].Index, d); return(true); } index = startIndex; token = null; return(false); }
private static bool TryReadPropertyToken(PositionedChar[] chars, ref int index, out PropertyToken token) { int startIndex = index; bool read; char c; List <PositionedChar> currentValue = new List <PositionedChar>(); do { c = chars[index].Value; read = char.IsLetter(c) || c == '$' || c == '_'; if (!read && currentValue.Any() && char.IsDigit(c)) { read = true; } if (read) { currentValue.Add(chars[index]); index++; } }while (read && index < chars.Length); if (currentValue.Any()) { token = new PropertyToken(chars[startIndex].Index, chars[index - 1].Index, PositionedChar.CreateString(currentValue), false); return(true); } token = null; index = startIndex; return(false); }