diff -r 04439bfc92ef obfusc/trunk/src/Language/C/Parser/Parser.y --- a/obfusc/trunk/src/Language/C/Parser/Parser.y Mon Dec 25 15:10:09 2017 +0000 +++ b/obfusc/trunk/src/Language/C/Parser/Parser.y Thu Dec 28 21:25:45 2017 +0000 @@ -393,11 +393,7 @@ compound_statement :: { CStat } compound_statement : '{' enter_scope block_item_list leave_scope '}' - {% withNodeInfo $1 $ CCompound [] (reverse $3) } - - | '{' enter_scope label_declarations block_item_list leave_scope '}' - {% withNodeInfo $1 $ CCompound (reverse $3) (reverse $4) } - + {% withNodeInfo $1 $ CCompound (rights $ reverse $3)(lefts $ reverse $3) } -- No syntax for these, just side effecting semantic actions. -- @@ -407,15 +403,16 @@ leave_scope : {% leaveScope } -block_item_list :: { Reversed [CBlockItem] } +block_item_list :: { Reversed [Either CBlockItem (Reversed [Ident])] } block_item_list : {- empty -} { empty } | block_item_list block_item { $1 `snoc` $2 } -block_item :: { CBlockItem } +block_item :: { Either CBlockItem (Reversed [Ident])} block_item - : statement { CBlockStmt $1 } - | nested_declaration { $1 } + : statement { Left (CBlockStmt $1) } + | nested_declaration { Left $1 } + | "__label__" identifier_list ';' { Right $2 } nested_declaration :: { CBlockItem } nested_declaration @@ -2342,4 +2339,15 @@ -- | @expressionP@ provides a parser for C expressions expressionP :: P CExpr expressionP = expression + +-- split up mixed lists +rights :: [Either x (Reversed [y])] -> [y] +rights (Left _:zs) = rights zs +rights (Right rs:zs) = reverse rs ++ rights zs +rights [] = [] +lefts :: [Either x (Reversed [y])] -> [x] +lefts (Left l:zs) = l:lefts zs +lefts (Right _:zs) = lefts zs +lefts [] = [] + }