Created
October 12, 2011 11:51
-
-
Save toshikazuhorii/1281026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object CsvParser3 extends RegexParsers { | |
| def eol = '\n' | |
| def cell = "\"" ~> "[^\"]*".r <~ "\"" | |
| def row = repsep(cell, ",") <~ eol | |
| def headerRow = row ^^ { cells => new HeaderRow(cells) } | |
| def dataRow = ( rep( ("\"" ~> "[^\"]*".r <~ "\",") | ("[^,\n]*".r <~ ",") ) ~ ( ("\"" ~> "[^\"]*".r <~ "\"\n") | ("[^,\n]*".r <~ "\n") ) ) ^^ { cells => new DataRow(cells._1 ::: List(cells._2)) } | |
| def all = headerRow ~ rep(dataRow) ^^ { res => res._1 :: res._2 } | |
| def parse(input: String): ParseResult[List[Row]] = parseAll(all, input) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment