{- ------------------------------
   Records and Projections
   ------------------------------ -}

-- Fields can either be named or not.  If they are not, then they
-- are numbered starting with 1.  To keep parsing the fields simple,
-- we label them with -1 at first if they have no name.  We then
-- replace the -1's with the correct index as a post-processing step.
parseRecord = braces $ liftM TmRecord $ liftM (addNumbers 1) $ 
              sepBy parseRecordField comma
    where addNumbers _ [] = []
          addNumbers i (("-1",t):fs) = (show i, t) : (addNumbers (i+1) fs)
          addNumbers i (       f:fs) =           f : (addNumbers (i+1) fs)
parseRecord = braces $ liftM TmRecord $ liftM (addNumbers 1) $ 
              sepBy parseRecordField comma
    where addNumbers _ [] = []
          addNumbers i (("-1",t):fs) = (show i, t) : (addNumbers (i+1) fs)
          addNumbers i (       f:fs) =           f : (addNumbers (i+1) fs)
parseRecord = braces $ liftM TmRecord $ liftM (addNumbers 1) $ 
              sepBy parseRecordField comma
    where addNumbers _ [] = []
          addNumbers i (("-1",t):fs) = (show i, t) : (addNumbers (i+1) fs)
          addNumbers i (       f:fs) =           f : (addNumbers (i+1) fs)