Permalink
Browse files

Parsing works now

  • Loading branch information...
1 parent bbf3a10 commit b39b3d7d6214c6865bc1891e7e9a3b670f407fa1 @bytbox committed Nov 28, 2011
Showing with 26 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. +25 −8 Data/HEPEVT.hs
View
@@ -6,3 +6,4 @@ _build
*.lhe
dist
*.dat
+*.dat.full
View
@@ -19,15 +19,32 @@ parseEventFile :: String -> IO [Event]
parseEventFile fname = do
S.readFile fname >>= return . parseEvents fname
+data Line = Meta String | E [Double] | P [Double] | V [Double] | Blank
+ deriving (Show, Eq)
+
+parseLine :: String -> Line
+parseLine line =
+ let ws = words line in
+ parseLine' ws line
+ where
+ parseLine' ("E":xs) _ = E $ map parseDouble xs
+ parseLine' ("P":xs) _ = P $ map parseDouble xs
+ parseLine' ("V":xs) _ = V $ map parseDouble xs
+ parseLine' _ line = if length line > 1 then Meta line else Blank
+
+getLines :: [String] -> [Line]
+getLines = map parseLine
+
+type ParseState = [Event]
+
parseEvents :: String -> S.ByteString -> [Event]
parseEvents fname dat =
let ls = S.split '\n' dat in
- foldl procLine [] ls
+ reverse $ foldl process [] $ getLines (map S.unpack ls)
where
- procLine events line =
- let ws = S.split ' ' line in
- if length ws < 1 then events else
- let h = head ws in
- process (S.unpack h) events (tail ws)
- process "P" events line = ([], []) : events
- process _ events _ = events
+ process events (E ds) = (ds, []):events
+ process ((el, vl):events) (V ds) = (el, ds:vl):events
+ process events _ = events
+
+parseDouble :: String -> Double
+parseDouble = read . reverse . dropWhile (=='.') . reverse

0 comments on commit b39b3d7

Please sign in to comment.