mirror of https://github.com/zachjs/sv2v.git
fixed ParseDecl mischaracterizing block decl as stmt
This commit is contained in:
parent
704e867c0c
commit
638adb3538
|
|
@ -183,8 +183,8 @@ parseDTsAsDeclOrAsgn :: [DeclToken] -> ([Decl], [Stmt])
|
||||||
parseDTsAsDeclOrAsgn [DTIdent f] = ([], [Subroutine (Nothing) f (Args [] [])])
|
parseDTsAsDeclOrAsgn [DTIdent f] = ([], [Subroutine (Nothing) f (Args [] [])])
|
||||||
parseDTsAsDeclOrAsgn [DTPSIdent p f] = ([], [Subroutine (Just p) f (Args [] [])])
|
parseDTsAsDeclOrAsgn [DTPSIdent p f] = ([], [Subroutine (Just p) f (Args [] [])])
|
||||||
parseDTsAsDeclOrAsgn tokens =
|
parseDTsAsDeclOrAsgn tokens =
|
||||||
if any isAsgnToken tokens || tripLookahead tokens
|
if (any isAsgnToken tokens || tripLookahead tokens) && lhs /= Nothing
|
||||||
then ([], [constructor lhs expr])
|
then ([], [constructor (fromJust lhs) expr])
|
||||||
else (parseDTsAsDecl tokens, [])
|
else (parseDTsAsDecl tokens, [])
|
||||||
where
|
where
|
||||||
(constructor, expr) = case last tokens of
|
(constructor, expr) = case last tokens of
|
||||||
|
|
@ -201,7 +201,10 @@ parseDTsAsDeclsAndAsgns tokens =
|
||||||
if hasLeadingAsgn || tripLookahead tokens
|
if hasLeadingAsgn || tripLookahead tokens
|
||||||
then
|
then
|
||||||
let (lhsToks, l0) = break isDTAsgn tokens
|
let (lhsToks, l0) = break isDTAsgn tokens
|
||||||
lhs = takeLHS lhsToks
|
lhs = case takeLHS lhsToks of
|
||||||
|
Nothing ->
|
||||||
|
error $ "could not parse as LHS: " ++ show lhsToks
|
||||||
|
Just l -> l
|
||||||
DTAsgn AsgnOpEq expr : l1 = l0
|
DTAsgn AsgnOpEq expr : l1 = l0
|
||||||
asgn = Right (lhs, expr)
|
asgn = Right (lhs, expr)
|
||||||
in case l1 of
|
in case l1 of
|
||||||
|
|
@ -231,17 +234,21 @@ isAsgnToken (DTAsgnNBlk _ _) = True
|
||||||
isAsgnToken (DTAsgn (AsgnOp _) _) = True
|
isAsgnToken (DTAsgn (AsgnOp _) _) = True
|
||||||
isAsgnToken _ = False
|
isAsgnToken _ = False
|
||||||
|
|
||||||
takeLHS :: [DeclToken] -> LHS
|
takeLHS :: [DeclToken] -> Maybe LHS
|
||||||
takeLHS tokens = fromJust $ foldl takeLHSStep Nothing tokens
|
takeLHS [] = Nothing
|
||||||
|
takeLHS (t : ts) =
|
||||||
|
foldl takeLHSStep (takeLHSStart t) ts
|
||||||
|
|
||||||
|
takeLHSStart :: DeclToken -> Maybe LHS
|
||||||
|
takeLHSStart (DTConcat lhss) = Just $ LHSConcat lhss
|
||||||
|
takeLHSStart (DTIdent x ) = Just $ LHSIdent x
|
||||||
|
takeLHSStart _ = Nothing
|
||||||
|
|
||||||
takeLHSStep :: Maybe LHS -> DeclToken -> Maybe LHS
|
takeLHSStep :: Maybe LHS -> DeclToken -> Maybe LHS
|
||||||
takeLHSStep (Nothing ) (DTConcat lhss) = Just $ LHSConcat lhss
|
|
||||||
takeLHSStep (Nothing ) (DTIdent x ) = Just $ LHSIdent x
|
|
||||||
takeLHSStep (Just curr) (DTBit e ) = Just $ LHSBit curr e
|
takeLHSStep (Just curr) (DTBit e ) = Just $ LHSBit curr e
|
||||||
takeLHSStep (Just curr) (DTRange (m,r)) = Just $ LHSRange curr m r
|
takeLHSStep (Just curr) (DTRange (m,r)) = Just $ LHSRange curr m r
|
||||||
takeLHSStep (Just curr) (DTDot x ) = Just $ LHSDot curr x
|
takeLHSStep (Just curr) (DTDot x ) = Just $ LHSDot curr x
|
||||||
takeLHSStep (maybeCurr) token =
|
takeLHSStep _ _ = Nothing
|
||||||
error $ "unexpected token in LHS: " ++ show (maybeCurr, token)
|
|
||||||
|
|
||||||
|
|
||||||
-- batches together seperate declaration lists
|
-- batches together seperate declaration lists
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue