diff --git a/ParseSyntaxFiles.hs b/ParseSyntaxFiles.hs
--- a/ParseSyntaxFiles.hs
+++ b/ParseSyntaxFiles.hs
@@ -332,10 +332,12 @@
                      else empty) <>
                   if parserType parser == "IncludeRules"
                      then mainParser <> char ')'
-                     else (if parserLookAhead parser
-                             then text "lookAhead (" <> mainParser <> text ") >> return (NormalTok,\"\") "
-                             else mainParser <> text " >>= withAttribute " <> text (show attr')) <>
-                          char ')' <> switchContext (parserContext parser) (text " >>~ " <>)
+                     else if parserLookAhead parser
+                            then text "lookAhead (" <> mainParser <> char ')'
+                                  <> switchContext (parserContext parser) (text " >> " <>)
+                                  <> text " >> currentContext >>= parseRules)"
+                            else mainParser <> text " >>= withAttribute " <> text (show attr') <> char ')'
+                                  <> switchContext (parserContext parser) (text " >>~ " <>)
       childParsers = parserChildren parser
   in  char '(' <>
       (if null childParsers
diff --git a/Text/Highlighting/Kate/Syntax/Bash.hs b/Text/Highlighting/Kate/Syntax/Bash.hs
--- a/Text/Highlighting/Kate/Syntax/Bash.hs
+++ b/Text/Highlighting/Kate/Syntax/Bash.hs
@@ -286,7 +286,7 @@
    <|>
    ((pRegExpr regex_'5cd'2a'3c'3c'3c >>= withAttribute KeywordTok))
    <|>
-   ((lookAhead (pString False "<<") >> return (NormalTok,"") ) >>~ pushContext "HereDoc")
+   ((lookAhead (pString False "<<") >> pushContext "HereDoc" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5b'3c'3e'5d'5c'28 >>= withAttribute KeywordTok) >>~ pushContext "ProcessSubst")
    <|>
@@ -617,26 +617,26 @@
 parseRules "CaseExpr" =
   (((pDetect2Chars False ';' ';' >>= withAttribute KeywordTok) >>~ (popContext))
    <|>
-   ((pFirstNonSpace >> lookAhead (pRegExpr regex_esac'28'3f'3d'24'7c'5b'5cs'3b'29'5d'29) >> return (NormalTok,"") ) >>~ (popContext))
+   ((pFirstNonSpace >> lookAhead (pRegExpr regex_esac'28'3f'3d'24'7c'5b'5cs'3b'29'5d'29) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "FindAll")))
 
 parseRules "HereDoc" =
-  (((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'22'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'22'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocIQ")
+  (((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'22'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'22'29) >> pushContext "HereDocIQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'27'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'27'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocIQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'27'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'27'29) >> pushContext "HereDocIQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'5c'5c'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocIQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'5c'5c'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> pushContext "HereDocIQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocINQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'2d'5cs'2a'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> pushContext "HereDocINQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'22'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'22'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'22'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'22'29) >> pushContext "HereDocQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'27'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'27'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'27'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'27'29) >> pushContext "HereDocQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'5c'5c'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'5c'5c'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> pushContext "HereDocQ" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> return (NormalTok,"") ) >>~ pushContext "HereDocNQ")
+   ((lookAhead (pRegExpr regex_'28'3c'3c'5cs'2a'28'5b'5e'7c'26'3b'28'29'3c'3e'5cs'5d'2b'29'29) >> pushContext "HereDocNQ" >> currentContext >>= parseRules))
    <|>
    ((pString False "<<" >>= withAttribute KeywordTok) >>~ (popContext)))
 
diff --git a/Text/Highlighting/Kate/Syntax/Bibtex.hs b/Text/Highlighting/Kate/Syntax/Bibtex.hs
--- a/Text/Highlighting/Kate/Syntax/Bibtex.hs
+++ b/Text/Highlighting/Kate/Syntax/Bibtex.hs
@@ -117,7 +117,7 @@
    <|>
    ((pDetectChar False '{' >>= withAttribute NormalTok) >>~ pushContext "CurlyBracket")
    <|>
-   ((lookAhead (pDetectChar False '}') >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pDetectChar False '}') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectChar False '"' >>= withAttribute NormalTok) >>~ pushContext "QuotedText")
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/C.hs b/Text/Highlighting/Kate/Syntax/C.hs
--- a/Text/Highlighting/Kate/Syntax/C.hs
+++ b/Text/Highlighting/Kate/Syntax/C.hs
@@ -89,7 +89,7 @@
    <|>
    ((pFirstNonSpace >> pRegExpr regex_'23'5cs'2aif'5cs'2b0'5cs'2a'24 >>= withAttribute OtherTok) >>~ pushContext "Outscoped")
    <|>
-   ((pFirstNonSpace >> lookAhead (pDetectChar False '#') >> return (NormalTok,"") ) >>~ pushContext "AfterHash")
+   ((pFirstNonSpace >> lookAhead (pDetectChar False '#') >> pushContext "AfterHash" >> currentContext >>= parseRules))
    <|>
    ((pFirstNonSpace >> pString False "//BEGIN" >>= withAttribute RegionMarkerTok) >>~ pushContext "Region Marker")
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Cpp.hs b/Text/Highlighting/Kate/Syntax/Cpp.hs
--- a/Text/Highlighting/Kate/Syntax/Cpp.hs
+++ b/Text/Highlighting/Kate/Syntax/Cpp.hs
@@ -90,7 +90,7 @@
    <|>
    ((pFirstNonSpace >> pRegExpr regex_'23'5cs'2aif'5cs'2b0'5cs'2a'24 >>= withAttribute OtherTok) >>~ pushContext "Outscoped")
    <|>
-   ((pFirstNonSpace >> lookAhead (pDetectChar False '#') >> return (NormalTok,"") ) >>~ pushContext "AfterHash")
+   ((pFirstNonSpace >> lookAhead (pDetectChar False '#') >> pushContext "AfterHash" >> currentContext >>= parseRules))
    <|>
    ((pFirstNonSpace >> pString False "//BEGIN" >>= withAttribute RegionMarkerTok) >>~ pushContext "Region Marker")
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/D.hs b/Text/Highlighting/Kate/Syntax/D.hs
--- a/Text/Highlighting/Kate/Syntax/D.hs
+++ b/Text/Highlighting/Kate/Syntax/D.hs
@@ -161,7 +161,7 @@
 parseRules "normal" =
   (((pDetectSpaces >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5f'5d) >> return (NormalTok,"") ) >>~ pushContext "StartingLetter")
+   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5f'5d) >> pushContext "StartingLetter" >> currentContext >>= parseRules))
    <|>
    ((pHlCStringChar >>= withAttribute StringTok))
    <|>
@@ -191,7 +191,7 @@
    <|>
    ((pDetectChar False '.' >>= withAttribute NormalTok) >>~ pushContext "Properties")
    <|>
-   ((lookAhead (pRegExpr regex_'5cd) >> return (NormalTok,"") ) >>~ pushContext "NumberLiteral")
+   ((lookAhead (pRegExpr regex_'5cd) >> pushContext "NumberLiteral" >> currentContext >>= parseRules))
    <|>
    ((pString False "#line" >>= withAttribute KeywordTok) >>~ pushContext "LinePragma")
    <|>
@@ -204,7 +204,7 @@
 parseRules "StartingLetter" =
   (((pDetectSpaces >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5b'5ea'2dzA'2dZ'5f'5d) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'5b'5ea'2dzA'2dZ'5f'5d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_in'5cs'2a'28'3f'3d'5c'7b'29 >>= withAttribute KeywordTok))
    <|>
@@ -303,7 +303,7 @@
    <|>
    ((parseRules "CommentRules"))
    <|>
-   ((lookAhead (pRegExpr regex_'5b'5e'5cs'5cw'2e'3a'2c'3d'5d) >> return (NormalTok,"") ) >>~ (popContext)))
+   ((lookAhead (pRegExpr regex_'5b'5e'5cs'5cw'2e'3a'2c'3d'5d) >> (popContext) >> currentContext >>= parseRules)))
 
 parseRules "Linkage" =
   (((pDetectSpaces >>= withAttribute NormalTok))
diff --git a/Text/Highlighting/Kate/Syntax/Diff.hs b/Text/Highlighting/Kate/Syntax/Diff.hs
--- a/Text/Highlighting/Kate/Syntax/Diff.hs
+++ b/Text/Highlighting/Kate/Syntax/Diff.hs
@@ -128,23 +128,23 @@
 parseRules "Chunk" =
   (((parseRules "FindDiff"))
    <|>
-   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext))
+   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pColumn 0 >> pDetectChar False '!' >>= withAttribute StringTok) >>~ pushContext "ChangedOld"))
 
 parseRules "ChunkInFile" =
   (((parseRules "FindDiff"))
    <|>
-   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext))
+   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pColumn 0 >> pRegExpr regex_Index'3a'2e'2a >>= withAttribute NormalTok) >>~ (popContext))
    <|>
-   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'3d'3d'3d'3d'7c'5c'2a'5c'2a'5c'2a'7c'5c'2d'5c'2d'5c'2d'7cdiff'7cOnly_in_'2e'2a'3a'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext))
+   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'3d'3d'3d'3d'7c'5c'2a'5c'2a'5c'2a'7c'5c'2d'5c'2d'5c'2d'7cdiff'7cOnly_in_'2e'2a'3a'29'2e'2a'24) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pColumn 0 >> pDetectChar False '!' >>= withAttribute StringTok) >>~ pushContext "ChangedOld"))
 
 parseRules "RFile" =
-  (((pColumn 0 >> lookAhead (pRegExpr regex_'28diff'7cOnly_in_'2e'2a'3a'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext))
+  (((pColumn 0 >> lookAhead (pRegExpr regex_'28diff'7cOnly_in_'2e'2a'3a'29'2e'2a'24) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pColumn 0 >> pRegExpr regex_'28'3d'3d'3d'3d'7c'5c'2a'5c'2a'5c'2a'7c'5c'2d'5c'2d'5c'2d'7cdiff'7cOnly_in_'2e'2a'3a'29'2e'2a'24 >>= withAttribute DataTypeTok))
    <|>
@@ -167,16 +167,16 @@
    ((parseRules "ChunkInFile")))
 
 parseRules "RChunkNew" =
-  (((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext >> popContext))
+  (((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> (popContext >> popContext) >> currentContext >>= parseRules))
    <|>
    ((pColumn 0 >> pDetectChar False '!' >>= withAttribute OtherTok) >>~ pushContext "ChangedNew")
    <|>
    ((parseRules "FindDiff")))
 
 parseRules "RChunkInFileNew" =
-  (((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext >> popContext))
+  (((pColumn 0 >> lookAhead (pRegExpr regex_'28'5c'40'5c'40'7c'5cd'29'2e'2a'24) >> (popContext >> popContext) >> currentContext >>= parseRules))
    <|>
-   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'3d'3d'3d'3d'7c'5c'2a'5c'2a'5c'2a'7c'5c'2d'5c'2d'5c'2d'7cdiff'7cOnly_in_'2e'2a'3a'29'2e'2a'24) >> return (NormalTok,"") ) >>~ (popContext >> popContext))
+   ((pColumn 0 >> lookAhead (pRegExpr regex_'28'3d'3d'3d'3d'7c'5c'2a'5c'2a'5c'2a'7c'5c'2d'5c'2d'5c'2d'7cdiff'7cOnly_in_'2e'2a'3a'29'2e'2a'24) >> (popContext >> popContext) >> currentContext >>= parseRules))
    <|>
    ((pColumn 0 >> pDetectChar False '!' >>= withAttribute OtherTok) >>~ pushContext "ChangedNew")
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Djangotemplate.hs b/Text/Highlighting/Kate/Syntax/Djangotemplate.hs
--- a/Text/Highlighting/Kate/Syntax/Djangotemplate.hs
+++ b/Text/Highlighting/Kate/Syntax/Djangotemplate.hs
@@ -141,7 +141,7 @@
    ((parseRules "FindHTML")))
 
 parseRules "In Block" =
-  (((lookAhead (pRegExpr regex_'5c'7b'25'5cs'2aend'5ba'2dz'5d'2b'5cs'2a'25'5c'7d) >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pRegExpr regex_'5c'7b'25'5cs'2aend'5ba'2dz'5d'2b'5cs'2a'25'5c'7d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "FindTemplate"))
    <|>
@@ -182,7 +182,7 @@
    ((pDetect2Chars False '%' '}' >>= withAttribute ErrorTok)))
 
 parseRules "Template Tag" =
-  (((lookAhead (pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_blocktags) >> return (NormalTok,"") ) >>~ pushContext "Found Block Tag")
+  (((lookAhead (pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_blocktags) >> pushContext "Found Block Tag" >> currentContext >>= parseRules))
    <|>
    ((pDetectIdentifier >>= withAttribute FunctionTok) >>~ pushContext "In Template Tag"))
 
@@ -192,7 +192,7 @@
 parseRules "In Block Tag" =
   (((pRegExprDynamic "\\{%\\s*end%1\\s*%\\}" >>= withAttribute FunctionTok) >>~ (popContext >> popContext >> popContext))
    <|>
-   ((lookAhead (pRegExpr regex_'5c'7b'25'5cs'2aend'5ba'2dz'5d'2b'5cs'2a'25'5c'7d) >> return (NormalTok,"") ) >>~ pushContext "Non Matching Tag")
+   ((lookAhead (pRegExpr regex_'5c'7b'25'5cs'2aend'5ba'2dz'5d'2b'5cs'2a'25'5c'7d) >> pushContext "Non Matching Tag" >> currentContext >>= parseRules))
    <|>
    ((pDetect2Chars False '%' '}' >>= withAttribute FunctionTok) >>~ pushContext "In Block")
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Doxygen.hs b/Text/Highlighting/Kate/Syntax/Doxygen.hs
--- a/Text/Highlighting/Kate/Syntax/Doxygen.hs
+++ b/Text/Highlighting/Kate/Syntax/Doxygen.hs
@@ -201,12 +201,12 @@
    ((pString False "<!--" >>= withAttribute CommentTok) >>~ pushContext "ML_htmlcomment"))
 
 parseRules "ML_TagWord" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "SL_TagWord")))
 
 parseRules "ML_TagParam" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectSpaces >>= withAttribute CommentTok))
    <|>
@@ -221,7 +221,7 @@
    ((pRegExpr regex_'5cS >>= withAttribute KeywordTok)))
 
 parseRules "ML_TagWordWord" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectSpaces >>= withAttribute CommentTok))
    <|>
@@ -230,14 +230,14 @@
    ((pRegExpr regex_'5cS >>= withAttribute KeywordTok)))
 
 parseRules "ML_Tag2ndWord" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext >> popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext >> popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "SL_Tag2ndWord")))
 
 parseRules "ML_TagString" =
   (((pDetectSpaces >>= withAttribute CommentTok))
    <|>
-   ((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pString False "<!--" >>= withAttribute CommentTok) >>~ pushContext "ML_htmlcomment")
    <|>
@@ -248,12 +248,12 @@
    ((pRegExpr regex_'2e >>= withAttribute StringTok)))
 
 parseRules "ML_TagWordString" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "SL_TagWordString")))
 
 parseRules "ML_htmltag" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetect2Chars False '/' '>' >>= withAttribute KeywordTok) >>~ (popContext))
    <|>
@@ -262,14 +262,14 @@
    ((pRegExpr regex_'5cs'2a'3d'5cs'2a >>= withAttribute OtherTok) >>~ pushContext "ML_identifiers"))
 
 parseRules "ML_htmlcomment" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((Text.Highlighting.Kate.Syntax.Alert.parseExpression >>= ((withAttribute CommentTok) . snd)))
    <|>
    ((pString False "-->" >>= withAttribute CommentTok) >>~ (popContext)))
 
 parseRules "ML_identifiers" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5cs'2a'23'3f'5ba'2dzA'2dZ0'2d9'5d'2a >>= withAttribute NormalTok) >>~ (popContext))
    <|>
@@ -278,19 +278,19 @@
    ((pDetectChar False '"' >>= withAttribute DataTypeTok) >>~ pushContext "ML_types2"))
 
 parseRules "ML_types1" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectChar False '\'' >>= withAttribute DataTypeTok) >>~ (popContext >> popContext)))
 
 parseRules "ML_types2" =
-  (((lookAhead (pDetect2Chars False '*' '/') >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pDetect2Chars False '*' '/') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectChar False '"' >>= withAttribute DataTypeTok) >>~ (popContext >> popContext)))
 
 parseRules "SL_TagWord" =
   (((pDetectSpaces >>= withAttribute CommentTok))
    <|>
-   ((lookAhead (pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWord) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}" list_TagWord) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5cS'28'3f'3d'28'5b'5d'5b'2c'3f'3b'28'29'5d'7c'5c'2e'24'7c'5c'2e'3f'5cs'29'29 >>= withAttribute KeywordTok) >>~ (popContext))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Erlang.hs b/Text/Highlighting/Kate/Syntax/Erlang.hs
--- a/Text/Highlighting/Kate/Syntax/Erlang.hs
+++ b/Text/Highlighting/Kate/Syntax/Erlang.hs
@@ -102,7 +102,7 @@
    <|>
    ((pRegExpr regex_'5cb'5ba'2dz'5d'5b'5fa'2dz'40'2dZ0'2d9'5d'2a'28'3f'3a'28'3f'3d'5b'5e'5fa'2dz'40'2dZ0'2d9'5d'29'7c'24'29'3a'5cb'5ba'2dz'5d'5b'5fa'2dz'40'2dZ0'2d9'5d'2a'28'3f'3a'28'3f'3d'5b'5e'5fa'2dz'40'2dZ0'2d9'5d'29'7c'24'29 >>= withAttribute FunctionTok) >>~ (popContext))
    <|>
-   ((lookAhead (pRegExpr regex_'5cb'5ba'2dz'5d'5b'5fa'2dz'40'2dZ0'2d9'5d'2a'28'3f'3a'28'3f'3d'5b'5e'5fa'2dz'40'2dZ0'2d9'5d'29'7c'24'29'5c'28) >> return (NormalTok,"") ) >>~ pushContext "isfunction")
+   ((lookAhead (pRegExpr regex_'5cb'5ba'2dz'5d'5b'5fa'2dz'40'2dZ0'2d9'5d'2a'28'3f'3a'28'3f'3d'5b'5e'5fa'2dz'40'2dZ0'2d9'5d'29'7c'24'29'5c'28) >> pushContext "isfunction" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5cb'5b'5fA'2dZ'5d'5b'5fa'2dz'40'2dZ0'2d9'5d'2a'28'3f'3a'28'3f'3d'5b'5e'5fa'2dz'40'2dZ0'2d9'5d'29'7c'24'29 >>= withAttribute DataTypeTok) >>~ (popContext))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Fsharp.hs b/Text/Highlighting/Kate/Syntax/Fsharp.hs
--- a/Text/Highlighting/Kate/Syntax/Fsharp.hs
+++ b/Text/Highlighting/Kate/Syntax/Fsharp.hs
@@ -140,7 +140,7 @@
    <|>
    ((pRegExpr regex_'60'5cs'2a'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c0377'5f'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> return (NormalTok,"") ) >>~ pushContext "ModuleEnv2")
+   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> pushContext "ModuleEnv2" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a >>= withAttribute NormalTok))
    <|>
@@ -208,7 +208,7 @@
 parseRules "ModuleEnv" =
   (((pDetectSpaces >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> return (NormalTok,"") ) >>~ pushContext "ModuleEnv2")
+   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> pushContext "ModuleEnv2" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a >>= withAttribute NormalTok) >>~ (popContext))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Javascript.hs b/Text/Highlighting/Kate/Syntax/Javascript.hs
--- a/Text/Highlighting/Kate/Syntax/Javascript.hs
+++ b/Text/Highlighting/Kate/Syntax/Javascript.hs
@@ -227,7 +227,7 @@
    <|>
    ((pDetectSpaces >>= withAttribute NormalTok) >>~ (popContext))
    <|>
-   ((lookAhead (pAnyChar "(){}:!%&+,-/.*<=>?[]|~^;") >> return (NormalTok,"") ) >>~ (popContext)))
+   ((lookAhead (pAnyChar "(){}:!%&+,-/.*<=>?[]|~^;") >> (popContext) >> currentContext >>= parseRules)))
 
 parseRules "" = parseRules "Normal"
 
diff --git a/Text/Highlighting/Kate/Syntax/Json.hs b/Text/Highlighting/Kate/Syntax/Json.hs
--- a/Text/Highlighting/Kate/Syntax/Json.hs
+++ b/Text/Highlighting/Kate/Syntax/Json.hs
@@ -101,9 +101,9 @@
    <|>
    ((pDetectChar False '[' >>= withAttribute NormalTok) >>~ pushContext "Array")
    <|>
-   ((lookAhead (pDetectChar False '}') >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pDetectChar False '}') >> (popContext) >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pDetectChar False ',') >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pDetectChar False ',') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectSpaces >>= withAttribute NormalTok))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Latex.hs b/Text/Highlighting/Kate/Syntax/Latex.hs
--- a/Text/Highlighting/Kate/Syntax/Latex.hs
+++ b/Text/Highlighting/Kate/Syntax/Latex.hs
@@ -483,7 +483,7 @@
 parseRules "VerbatimEnv" =
   (((pDetectChar False '}' >>= withAttribute NormalTok) >>~ pushContext "Verbatim")
    <|>
-   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "EnvCommon"))
    <|>
@@ -513,7 +513,7 @@
 parseRules "CommentEnv" =
   (((pDetectChar False '}' >>= withAttribute NormalTok) >>~ pushContext "BlockComment")
    <|>
-   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "EnvCommon"))
    <|>
@@ -536,7 +536,7 @@
 parseRules "MathEnv" =
   (((pDetectChar False '}' >>= withAttribute NormalTok) >>~ pushContext "MathModeEnv")
    <|>
-   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "EnvCommon")))
 
@@ -545,7 +545,7 @@
    <|>
    ((pDetectChar False '}' >>= withAttribute NormalTok) >>~ pushContext "MathModeEnv")
    <|>
-   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "EnvCommon")))
 
@@ -599,7 +599,7 @@
 parseRules "TabEnv" =
   (((pDetectChar False '}' >>= withAttribute NormalTok) >>~ pushContext "Tab")
    <|>
-   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'5ba'2dzA'2dZ'5d) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "EnvCommon"))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Lex.hs b/Text/Highlighting/Kate/Syntax/Lex.hs
--- a/Text/Highlighting/Kate/Syntax/Lex.hs
+++ b/Text/Highlighting/Kate/Syntax/Lex.hs
@@ -94,7 +94,7 @@
 defaultAttributes = [("Pre Start",NormalTok),("Definitions",NormalTok),("Rules",NormalTok),("User Code",NormalTok),("Percent Command",KeywordTok),("Comment",CommentTok),("Definition RegExpr",StringTok),("Rule RegExpr",StringTok),("RegExpr (",StringTok),("RegExpr [",StringTok),("RegExpr {",StringTok),("RegExpr Q",StringTok),("RegExpr Base",StringTok),("Start Conditions Scope",NormalTok),("Action",NormalTok),("Detect C",NormalTok),("Indented C",NormalTok),("Lex C Bloc",NormalTok),("Lex Rule C Bloc",NormalTok),("Normal C Bloc",NormalTok),("Action C",NormalTok)]
 
 parseRules "Pre Start" =
-  ((lookAhead (pRegExpr regex_'2e) >> return (NormalTok,"") ) >>~ pushContext "Definitions")
+  ((lookAhead (pRegExpr regex_'2e) >> pushContext "Definitions" >> currentContext >>= parseRules))
 
 parseRules "Definitions" =
   (((parseRules "Detect C"))
diff --git a/Text/Highlighting/Kate/Syntax/Noweb.hs b/Text/Highlighting/Kate/Syntax/Noweb.hs
--- a/Text/Highlighting/Kate/Syntax/Noweb.hs
+++ b/Text/Highlighting/Kate/Syntax/Noweb.hs
@@ -95,7 +95,7 @@
    <|>
    ((pColumn 0 >> pRegExpr regex_'40'28'3f'3d'5b'5cs'25'5d'29 >>= withAttribute RegionMarkerTok) >>~ pushContext "RawDocumentation")
    <|>
-   ((pColumn 0 >> lookAhead (pRegExpr regex_'3c'3c'2e'2a'3e'3e'3d'24) >> return (NormalTok,"") ) >>~ pushContext "RawDocumentation")
+   ((pColumn 0 >> lookAhead (pRegExpr regex_'3c'3c'2e'2a'3e'3e'3d'24) >> pushContext "RawDocumentation" >> currentContext >>= parseRules))
    <|>
    ((parseRules "SectionNames"))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Ocaml.hs b/Text/Highlighting/Kate/Syntax/Ocaml.hs
--- a/Text/Highlighting/Kate/Syntax/Ocaml.hs
+++ b/Text/Highlighting/Kate/Syntax/Ocaml.hs
@@ -134,7 +134,7 @@
    <|>
    ((pRegExpr regex_'60'5cs'2a'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c0377'5f'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a >>= withAttribute DataTypeTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> return (NormalTok,"") ) >>~ pushContext "ModuleEnv2")
+   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> pushContext "ModuleEnv2" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a >>= withAttribute DataTypeTok))
    <|>
@@ -201,7 +201,7 @@
 parseRules "ModuleEnv" =
   (((pDetectSpaces >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> return (NormalTok,"") ) >>~ pushContext "ModuleEnv2")
+   ((lookAhead (pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a'5cs'2a'5c'2e) >> pushContext "ModuleEnv2" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5bA'2dZ'5d'5bA'2dZa'2dz'5c0300'2d'5c0326'5c0330'2d'5c0366'5c0370'2d'5c03770'2d9'5f'27'5d'2a >>= withAttribute NormalTok) >>~ (popContext))
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Perl.hs b/Text/Highlighting/Kate/Syntax/Perl.hs
--- a/Text/Highlighting/Kate/Syntax/Perl.hs
+++ b/Text/Highlighting/Kate/Syntax/Perl.hs
@@ -249,7 +249,7 @@
    <|>
    ((pDetectChar False '`' >>= withAttribute KeywordTok) >>~ pushContext "Backticked")
    <|>
-   ((lookAhead (pRegExpr regex_'28'3f'3a'5b'24'40'5d'5cS'7c'25'5b'5cw'7b'5d'7c'5c'2a'5b'5e'5cd'5c'2a'7b'5c'24'40'25'3d'28'5d'29) >> return (NormalTok,"") ) >>~ pushContext "find_variable")
+   ((lookAhead (pRegExpr regex_'28'3f'3a'5b'24'40'5d'5cS'7c'25'5b'5cw'7b'5d'7c'5c'2a'5b'5e'5cd'5c'2a'7b'5c'24'40'25'3d'28'5d'29) >> pushContext "find_variable" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'3c'5bA'2dZ0'2d9'5f'5d'2b'3e >>= withAttribute KeywordTok))
    <|>
@@ -333,7 +333,7 @@
    <|>
    ((pRegExpr regex_'5c'5c'2e >>= withAttribute StringTok))
    <|>
-   ((lookAhead (pRegExpr regex_'28'3f'3a'5b'5c'24'40'5d'5cS'7c'25'5b'5cw'7b'5d'29) >> return (NormalTok,"") ) >>~ pushContext "find_variable_unsafe"))
+   ((lookAhead (pRegExpr regex_'28'3f'3a'5b'5c'24'40'5d'5cS'7c'25'5b'5cw'7b'5d'29) >> pushContext "find_variable_unsafe" >> currentContext >>= parseRules)))
 
 parseRules "ip_string" =
   (((pDetectChar False '"' >>= withAttribute KeywordTok) >>~ (popContext))
@@ -620,7 +620,7 @@
 parseRules "regex_pattern_internal_ip" =
   (((parseRules "regex_pattern_internal_rules_1"))
    <|>
-   ((lookAhead (pRegExpr regex_'5b'24'40'5d'5b'5e'5c'5d'5cs'7b'7d'28'29'7c'3e'27'5d) >> return (NormalTok,"") ) >>~ pushContext "find_variable_unsafe")
+   ((lookAhead (pRegExpr regex_'5b'24'40'5d'5b'5e'5c'5d'5cs'7b'7d'28'29'7c'3e'27'5d) >> pushContext "find_variable_unsafe" >> currentContext >>= parseRules))
    <|>
    ((parseRules "regex_pattern_internal_rules_2")))
 
@@ -810,7 +810,7 @@
 parseRules "sub_name_def" =
   (((pRegExpr regex_'5cw'2b >>= withAttribute FunctionTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5c'24'5cS) >> return (NormalTok,"") ) >>~ pushContext "find_variable")
+   ((lookAhead (pRegExpr regex_'5c'24'5cS) >> pushContext "find_variable" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'5cs'2a'5c'28 >>= withAttribute NormalTok) >>~ pushContext "sub_arg_definition")
    <|>
diff --git a/Text/Highlighting/Kate/Syntax/Php.hs b/Text/Highlighting/Kate/Syntax/Php.hs
--- a/Text/Highlighting/Kate/Syntax/Php.hs
+++ b/Text/Highlighting/Kate/Syntax/Php.hs
@@ -117,7 +117,7 @@
 parseRules "phpsource" =
   (((pDetectSpaces >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pString False "?>") >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pString False "?>") >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectChar False '?' >>= withAttribute OtherTok) >>~ pushContext "ternary")
    <|>
@@ -206,7 +206,7 @@
   ((parseRules "ternary"))
 
 parseRules "onelinecomment" =
-  (((lookAhead (pString False "?>") >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pString False "?>") >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((Text.Highlighting.Kate.Syntax.Alert.parseExpression >>= ((withAttribute CommentTok) . snd))))
 
diff --git a/Text/Highlighting/Kate/Syntax/Relaxngcompact.hs b/Text/Highlighting/Kate/Syntax/Relaxngcompact.hs
--- a/Text/Highlighting/Kate/Syntax/Relaxngcompact.hs
+++ b/Text/Highlighting/Kate/Syntax/Relaxngcompact.hs
@@ -81,7 +81,7 @@
    <|>
    ((pKeyword " \n\t.()!+,<=>%&*/;?[]^{|}~\\" list_Datatypes >>= withAttribute DataTypeTok))
    <|>
-   ((lookAhead (pRegExpr regex_'5b'5cw'5c'2e'2d'5d'2b'5b'5cs'5d'2b'3d) >> return (NormalTok,"") ) >>~ pushContext "Definitions"))
+   ((lookAhead (pRegExpr regex_'5b'5cw'5c'2e'2d'5d'2b'5b'5cs'5d'2b'3d) >> pushContext "Definitions" >> currentContext >>= parseRules)))
 
 parseRules "Comments" =
   pzero
@@ -90,10 +90,10 @@
   ((pDetectChar False '"' >>= withAttribute StringTok) >>~ (popContext))
 
 parseRules "Node Names" =
-  ((lookAhead (pDetectChar False '{') >> return (NormalTok,"") ) >>~ (popContext))
+  ((lookAhead (pDetectChar False '{') >> (popContext) >> currentContext >>= parseRules))
 
 parseRules "Definitions" =
-  ((lookAhead (pDetectChar False '=') >> return (NormalTok,"") ) >>~ (popContext >> popContext))
+  ((lookAhead (pDetectChar False '=') >> (popContext >> popContext) >> currentContext >>= parseRules))
 
 parseRules "" = parseRules "Normal Text"
 
diff --git a/Text/Highlighting/Kate/Syntax/Tcl.hs b/Text/Highlighting/Kate/Syntax/Tcl.hs
--- a/Text/Highlighting/Kate/Syntax/Tcl.hs
+++ b/Text/Highlighting/Kate/Syntax/Tcl.hs
@@ -127,7 +127,7 @@
 parseRules "New command line" =
   (((pRegExpr regex_'5cs'2a'23 >>= withAttribute CommentTok) >>~ pushContext "Comment")
    <|>
-   ((lookAhead (pRegExpr regex_'2e) >> return (NormalTok,"") ) >>~ (popContext)))
+   ((lookAhead (pRegExpr regex_'2e) >> (popContext) >> currentContext >>= parseRules)))
 
 parseRules "" = parseRules "Base"
 
diff --git a/Text/Highlighting/Kate/Syntax/Texinfo.hs b/Text/Highlighting/Kate/Syntax/Texinfo.hs
--- a/Text/Highlighting/Kate/Syntax/Texinfo.hs
+++ b/Text/Highlighting/Kate/Syntax/Texinfo.hs
@@ -92,7 +92,7 @@
    ((Text.Highlighting.Kate.Syntax.Alert.parseExpression >>= ((withAttribute CommentTok) . snd))))
 
 parseRules "nodeFolding" =
-  (((lookAhead (pRegExpr regex_'40node'5cb) >> return (NormalTok,"") ) >>~ (popContext))
+  (((lookAhead (pRegExpr regex_'40node'5cb) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "Normal Text")))
 
diff --git a/Text/Highlighting/Kate/Syntax/Vhdl.hs b/Text/Highlighting/Kate/Syntax/Vhdl.hs
--- a/Text/Highlighting/Kate/Syntax/Vhdl.hs
+++ b/Text/Highlighting/Kate/Syntax/Vhdl.hs
@@ -114,13 +114,13 @@
 parseRules "start" =
   (((parseRules "preDetection"))
    <|>
-   ((lookAhead (pRegExprDynamic "architecture\\s+(\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)") >> return (NormalTok,"") ) >>~ pushContext "architecture_main")
+   ((lookAhead (pRegExprDynamic "architecture\\s+(\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)") >> pushContext "architecture_main" >> currentContext >>= parseRules))
    <|>
    ((pString False "entity" >>= withAttribute KeywordTok) >>~ pushContext "entity")
    <|>
-   ((lookAhead (pRegExpr regex_'28'5cb'29'28package'5cs'2b'28'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'5cs'2bis'29'5cb) >> return (NormalTok,"") ) >>~ pushContext "package")
+   ((lookAhead (pRegExpr regex_'28'5cb'29'28package'5cs'2b'28'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'5cs'2bis'29'5cb) >> pushContext "package" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'5cb'29'28package'5cs'2bbody'5cs'2b'28'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'5cs'2bis'29'5cb) >> return (NormalTok,"") ) >>~ pushContext "packagebody")
+   ((lookAhead (pRegExpr regex_'28'5cb'29'28package'5cs'2bbody'5cs'2b'28'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'5cs'2bis'29'5cb) >> pushContext "packagebody" >> currentContext >>= parseRules))
    <|>
    ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" list_keywordsToplevel >>= withAttribute KeywordTok)))
 
@@ -169,11 +169,11 @@
    ((parseRules "generalDetection")))
 
 parseRules "detect_arch_parts" =
-  (((lookAhead (pRegExprDynamic "(\\b)((\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)\\s*:\\s*)(if|for).*\\s+generate\\b") >> return (NormalTok,"") ) >>~ pushContext "generate1")
+  (((lookAhead (pRegExprDynamic "(\\b)((\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)\\s*:\\s*)(if|for).*\\s+generate\\b") >> pushContext "generate1" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExprDynamic "(\\b)((\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)\\s*:\\s*)?process\\b") >> return (NormalTok,"") ) >>~ pushContext "process1")
+   ((lookAhead (pRegExprDynamic "(\\b)((\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)\\s*:\\s*)?process\\b") >> pushContext "process1" >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExprDynamic "\\b(\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)\\s*:\\s*(\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)") >> return (NormalTok,"") ) >>~ pushContext "instance")
+   ((lookAhead (pRegExprDynamic "\\b(\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)\\s*:\\s*(\\b(?!(?:process|constant|signal|variable))([A-Za-z_][A-Za-z0-9_]*)\\b)") >> pushContext "instance" >> currentContext >>= parseRules))
    <|>
    ((parseRules "generalDetection")))
 
@@ -217,7 +217,7 @@
    <|>
    ((pRegExpr regex_'28'5cb'29'28if'29'5cb >>= withAttribute KeywordTok) >>~ pushContext "if_start")
    <|>
-   ((lookAhead (pRegExprDynamic "(\\b)(case)\\b") >> return (NormalTok,"") ) >>~ pushContext "case1")
+   ((lookAhead (pRegExprDynamic "(\\b)(case)\\b") >> pushContext "case1" >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'28'5cb'29'28'28'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'5cs'2a'3a'5cs'2a'29'3f'28'28for'7cwhile'29'5cs'2b'2e'2b'5cs'2b'29'3floop'5cb >>= withAttribute KeywordTok) >>~ pushContext "forOrWhile")
    <|>
@@ -276,9 +276,9 @@
 parseRules "caseWhen" =
   (((parseRules "preDetection"))
    <|>
-   ((lookAhead (pRegExpr regex_'28'5cb'29when'5cb) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'28'5cb'29when'5cb) >> (popContext) >> currentContext >>= parseRules))
    <|>
-   ((lookAhead (pRegExpr regex_'28'5cb'29end'5cs'2bcase'28'5cs'2b'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'3f'5cs'2a'3b) >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pRegExpr regex_'28'5cb'29end'5cs'2bcase'28'5cs'2b'5cb'28'3f'21'28'3f'3aprocess'7cconstant'7csignal'7cvariable'29'29'28'5bA'2dZa'2dz'5f'5d'5bA'2dZa'2dz0'2d9'5f'5d'2a'29'5cb'29'3f'5cs'2a'3b) >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((parseRules "proc_rules")))
 
diff --git a/Text/Highlighting/Kate/Syntax/Yacc.hs b/Text/Highlighting/Kate/Syntax/Yacc.hs
--- a/Text/Highlighting/Kate/Syntax/Yacc.hs
+++ b/Text/Highlighting/Kate/Syntax/Yacc.hs
@@ -95,7 +95,7 @@
    <|>
    ((pColumn 0 >> pDetect2Chars False '%' '{' >>= withAttribute BaseNTok) >>~ pushContext "C Declarations")
    <|>
-   ((lookAhead (pRegExpr regex_'2e) >> return (NormalTok,"") ) >>~ pushContext "Declarations"))
+   ((lookAhead (pRegExpr regex_'2e) >> pushContext "Declarations" >> currentContext >>= parseRules)))
 
 parseRules "C Declarations" =
   (((parseRules "Comment"))
@@ -162,7 +162,7 @@
 parseRules "Percent Command" =
   (((parseRules "Comment"))
    <|>
-   ((lookAhead (pRegExpr regex_'5cW) >> return (NormalTok,"") ) >>~ pushContext "Percent Command In"))
+   ((lookAhead (pRegExpr regex_'5cW) >> pushContext "Percent Command In" >> currentContext >>= parseRules)))
 
 parseRules "Percent Command In" =
   (((parseRules "StringOrChar"))
diff --git a/Text/Highlighting/Kate/Syntax/Yaml.hs b/Text/Highlighting/Kate/Syntax/Yaml.hs
--- a/Text/Highlighting/Kate/Syntax/Yaml.hs
+++ b/Text/Highlighting/Kate/Syntax/Yaml.hs
@@ -139,7 +139,7 @@
    <|>
    ((pRegExpr regex_'5c'2a'5cS'2b >>= withAttribute DataTypeTok))
    <|>
-   ((lookAhead (pRegExpr regex_'2e) >> return (NormalTok,"") ) >>~ (popContext)))
+   ((lookAhead (pRegExpr regex_'2e) >> (popContext) >> currentContext >>= parseRules)))
 
 parseRules "header" =
   ((pDetectChar False '#' >>= withAttribute CommentTok) >>~ pushContext "comment")
@@ -156,7 +156,7 @@
 parseRules "attribute-inline" =
   (((pDetectChar False ',' >>= withAttribute KeywordTok) >>~ (popContext >> popContext))
    <|>
-   ((lookAhead (pDetectChar False '}') >> return (NormalTok,"") ) >>~ (popContext >> popContext))
+   ((lookAhead (pDetectChar False '}') >> (popContext >> popContext) >> currentContext >>= parseRules))
    <|>
    ((pDetectChar False '#' >>= withAttribute CommentTok) >>~ pushContext "comment"))
 
@@ -206,7 +206,7 @@
    <|>
    ((pDetectChar False ',' >>= withAttribute KeywordTok) >>~ (popContext))
    <|>
-   ((lookAhead (pDetectChar False '}') >> return (NormalTok,"") ) >>~ (popContext))
+   ((lookAhead (pDetectChar False '}') >> (popContext) >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'2e >>= withAttribute NormalTok) >>~ pushContext "attribute-inline"))
 
@@ -280,7 +280,7 @@
 parseRules "attribute-end-inline" =
   (((pRegExpr regex_'5cs'2a >>= withAttribute NormalTok))
    <|>
-   ((lookAhead (pDetectChar False '}') >> return (NormalTok,"") ) >>~ (popContext >> popContext >> popContext))
+   ((lookAhead (pDetectChar False '}') >> (popContext >> popContext >> popContext) >> currentContext >>= parseRules))
    <|>
    ((pRegExpr regex_'2c'5cs >>= withAttribute KeywordTok) >>~ (popContext >> popContext >> popContext)))
 
diff --git a/highlighting-kate.cabal b/highlighting-kate.cabal
--- a/highlighting-kate.cabal
+++ b/highlighting-kate.cabal
@@ -1,5 +1,5 @@
 Name:                highlighting-kate
-Version:             0.5.0.1
+Version:             0.5.0.2
 Cabal-Version:       >= 1.6
 Build-Type:          Simple
 Category:            Text
