File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1
1
module Perl5Parser.Env
2
2
( get_prototype
3
3
, set_prototype
4
+ , with_new_lexical_block
5
+ , set_package
4
6
) where
5
7
6
8
import Perl5Parser.Types
@@ -24,3 +26,22 @@ set_prototype (fq, f) proto = update_Prototypes update
24
26
25
27
update_Prototypes :: (Prototypes -> Prototypes ) -> Perl5Parser ()
26
28
update_Prototypes f = updateState (\ state -> state { prototypes = f (prototypes state) })
29
+
30
+ update_Env :: (Env -> Env ) -> Perl5Parser ()
31
+ update_Env f = updateState (\ state -> state { env = f (env state) })
32
+
33
+ update_Env_lexical :: (Env_lexical -> Env_lexical ) -> Perl5Parser ()
34
+ update_Env_lexical f = update_Env (\ env -> env { env_lexical = f (env_lexical env) })
35
+
36
+ set_Env_lexical :: Env_lexical -> Perl5Parser ()
37
+ set_Env_lexical env_lex = update_Env_lexical (\ _ -> env_lex)
38
+
39
+ with_new_lexical_block :: Perl5Parser a -> Perl5Parser a
40
+ with_new_lexical_block p =
41
+ do prev_env_lex <- fmap (env_lexical . env) getState
42
+ v <- p
43
+ set_Env_lexical prev_env_lex
44
+ return v
45
+
46
+ set_package :: String -> Perl5Parser ()
47
+ set_package pkg = update_Env_lexical (\ env_lex -> env_lex { current_package = pkg })
Original file line number Diff line number Diff line change @@ -79,7 +79,14 @@ prototype = do char '('
79
79
return (Just proto, [Tokens (Prototype proto : l)])
80
80
81
81
subattrlist = option [] (toNodes Perl5Parser.Token. p_Attributes)
82
- package = newNode" package" $ pcons (symbol_node " package" ) (toNodes Perl5Parser.Token. p_Ident)
82
+
83
+ package = newNode" package" $ p
84
+ where p = do l1 <- symbol_node " package"
85
+ (fq, i) <- Perl5Parser.Token. p_Ident_raw
86
+ let pkg = case fq of LocalIdent -> i ; _ -> fq_canonical fq ++ " ::" ++ i
87
+ Env. set_package pkg
88
+ l2 <- spaces_comments_token
89
+ return $ l1 : [Tokens $ Word pkg : l2]
83
90
84
91
-- | Real conditional expressions
85
92
if_then = newNode" if_then" $ seQ l
You can’t perform that action at this time.
0 commit comments