Changeset 406
- Timestamp:
- 07/29/08 19:17:36 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAnalysis/DatasetParser.cs
r405 r406 194 194 using(StreamReader reader = new StreamReader(importFileName)) { 195 195 tokenizer = new Tokenizer(reader, numberFormat); 196 tokenizer.Separators = new string[] { " ", ";", "\t" };197 196 try { 198 197 // parse the file … … 210 209 #region tokenizer 211 210 internal enum TokenTypeEnum { 212 At, Assign, NewLine, String, Double, Int 211 At, Assign, NewLine, String, Double, Int, WhiteSpace 213 212 } 214 213 … … 235 234 private StreamReader reader; 236 235 private List<Token> tokens; 237 private string[] separators ;236 private string[] separators = new string[] { "@", "=", ";", "\t" }; 238 237 private NumberFormatInfo numberFormatInfo; 239 238 … … 244 243 public static Token AtToken = new Token(TokenTypeEnum.At, "@"); 245 244 public static Token AssignmentToken = new Token(TokenTypeEnum.Assign, "="); 246 245 public static Token SeparatorToken = new Token(TokenTypeEnum.WhiteSpace, ""); 247 246 public string[] Separators { 248 247 get { return separators; } … … 262 261 CurrentLine = reader.ReadLine(); 263 262 Token[] newTokens = Array.ConvertAll(CurrentLine.Split(separators, StringSplitOptions.RemoveEmptyEntries), delegate(string str) { 264 return MakeToken(str );263 return MakeToken(str.Trim()); 265 264 }); 266 265 267 tokens.AddRange(newTokens); 266 foreach(Token tok in newTokens) { 267 if(tok != SeparatorToken) tokens.Add(tok); 268 } 268 269 tokens.Add(NewlineToken); 269 270 CurrentLineNumber++; … … 272 273 273 274 private Token MakeToken(string strToken) { 274 if(strToken == "@") 275 return AtToken; 276 else if(strToken == "=") 277 return AssignmentToken; 278 else { 279 Token token = new Token(TokenTypeEnum.String, strToken); 280 281 if(int.TryParse(strToken, NumberStyles.Integer, numberFormatInfo, out token.intValue)) { 282 token.type = TokenTypeEnum.Int; 283 return token; 284 } else if(double.TryParse(strToken, NumberStyles.Float, numberFormatInfo, out token.doubleValue)) { 285 token.type = TokenTypeEnum.Double; 286 return token; 287 } 288 // couldn't parse the token as an int or float number 275 Token token = new Token(TokenTypeEnum.String, strToken); 276 277 // try to parse as a number first 278 if(int.TryParse(strToken, NumberStyles.Integer, numberFormatInfo, out token.intValue)) { 279 token.type = TokenTypeEnum.Int; 289 280 return token; 290 } 281 } else if(double.TryParse(strToken, NumberStyles.Float, numberFormatInfo, out token.doubleValue)) { 282 token.type = TokenTypeEnum.Double; 283 return token; 284 } 285 // couldn't parse the token as an int or float number so return a string token 286 return token; 291 287 } 292 288 … … 363 359 364 360 private void ParseMetaData(bool strict) { 365 while(tokenizer.Peek() == Tokenizer.AtToken) { 366 Expect(Tokenizer.AtToken); 367 361 while(tokenizer.Peek().type==TokenTypeEnum.String) { 368 362 Token nameToken = tokenizer.Next(); 369 363 if(nameToken.type != TokenTypeEnum.String) 370 364 Error("Expected a variable name.", nameToken.stringValue, tokenizer.CurrentLineNumber); 371 372 Expect(Tokenizer.AssignmentToken);373 365 374 366 List<Token> tokens = new List<Token>();
Note: See TracChangeset
for help on using the changeset viewer.