Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Extend saw-core parser to handle pattern matches on nested record con…
Browse files Browse the repository at this point in the history
…structors
  • Loading branch information
Brian Huffman committed Sep 26, 2015
1 parent a16b784 commit 43085ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/Verifier/SAW/Grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,24 @@ Pat : AtomPat { $1 }
| ConDotList list1(AtomPat) { PCtor (identFromList1 $1) $2 }

AtomPat :: { Pat }
AtomPat : SimplePat { PSimple $1 }
| ConDotList { PCtor (identFromList1 $1) [] }
| '(' sepBy(Pat, ',') ')' { parseParen (\_ v -> v) mkPTuple (pos $1) $2 }
| '(' Pat '|' Pat ')' { PPair (pos $1) $2 $4 }
| '{' recList('=', Pat) '}' { mkPRecord (pos $1) $2 }
AtomPat : SimplePat { PSimple $1 }
| ConDotList { PCtor (identFromList1 $1) [] }
| '(' sepBy(Pat, ',') ')' { parseParen (\_ v -> v) mkPTuple (pos $1) $2 }
| '(' Pat '|' Pat ')' { PPair (pos $1) $2 $4 }
| '{' sepBy(FieldPat, ',') '}' { mkPRecord (pos $1) $2 }
| '{' FieldPat '|' Pat '}' { PField $2 $4 }

SimplePat :: { SimplePat }
SimplePat : unvar { PUnused (fmap tokVar $1) }
| Var { PVar $1 }

LabelPat :: { Pat }
LabelPat : FieldName { mkFieldNamePat $1 }
| '(' Pat ')' { $2 }

FieldPat :: { (Pat, Pat) }
FieldPat : LabelPat '=' Pat { ($1, $3) }

Term :: { Term }
Term : TTerm { $1 }
| 'let' '{' list(SAWEqDecl) '}' 'in' Term { LetTerm (pos $1) $3 $6 }
Expand Down
6 changes: 3 additions & 3 deletions src/Verifier/SAW/UntypedAST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Verifier.SAW.UntypedAST
, Pat(..), ppPat
, mkPTuple
, mkPRecord
, mkFieldNamePat
, SimplePat(..)
, FieldName
, Ident, localIdent, asLocalIdent, mkIdent, identModule, setIdentModule
Expand Down Expand Up @@ -153,9 +154,8 @@ data Pat
mkPTuple :: Pos -> [Pat] -> Pat
mkPTuple p = foldr (PPair p) (PUnit p)

mkPRecord :: Pos -> [(PosPair FieldName, Pat)] -> Pat
mkPRecord p xs = foldr PField (PEmpty p) xs'
where xs' = [ (mkFieldNamePat x, y) | (x, y) <- xs ]
mkPRecord :: Pos -> [(Pat, Pat)] -> Pat
mkPRecord p = foldr PField (PEmpty p)

mkFieldNamePat :: PosPair FieldName -> Pat
mkFieldNamePat (PosPair p s) = PString p s
Expand Down

0 comments on commit 43085ae

Please sign in to comment.