From 85b7bc695629926641c7cb752fd478adfdf374f3 Mon Sep 17 00:00:00 2001
From: Marius <mariausol@gmail.com>
Date: Sun, 4 Jul 2010 15:32:09 +0300
Subject: stable 2010-05-24 13:10

---
 tex/context/base/m-level.tex | 94 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 tex/context/base/m-level.tex

(limited to 'tex/context/base/m-level.tex')

diff --git a/tex/context/base/m-level.tex b/tex/context/base/m-level.tex
new file mode 100644
index 000000000..67d598733
--- /dev/null
+++ b/tex/context/base/m-level.tex
@@ -0,0 +1,94 @@
+%D \module
+%D   [       file=level,
+%D        version=2002.10.20,
+%D          title=\CONTEXT\ Extra Modules,
+%D       subtitle=Catching Nesting Errors,
+%D         author=Hans Hagen,
+%D           date=\currentdate,
+%D      copyright=\PRAGMA]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
+%C details. 
+
+\unprotect 
+
+\newcount\currentnesting
+
+\def\startnesting#1%
+  {\global\advance\currentnesting\plusone
+   \setxvalue{level::\number\currentnesting}{#1}}
+
+\def\stopnesting#1%
+  {\edef\nestingstring{#1}%
+   \relax\ifnum\currentnesting>\zerocount
+     \doifelsevalue{level::\number\currentnesting}\nestingstring
+       {\global\advance\currentnesting\minusone}
+       {\@EA\reportnestingerror\@EA\stoptext}
+   \else
+     \@EA\reportnestingerror\@EA\stoptext
+   \fi}
+
+\def\checknesting
+  {\relax\ifnum\currentnesting>\zerocount
+     \def\nestingstring{end of document}%
+     \@EA\reportnestingerror
+   \fi}
+
+\def\reportnestingerror
+  {\endgraf
+   \global\let\checknesting\relax
+   \bgroup \definedfont[Mono at 18pt]\incolortrue 
+   \setupinterlinespace 
+   \raggedright
+   \bgroup \red 
+   \ifnum\currentnesting>\plusone
+     wrong end level 
+   \else  
+     too many end levels 
+   \fi
+   at \nestingstring\space in line \number\inputlineno
+   \ifnum\currentnesting>\zerocount, stack:\fi\endgraf
+   \egroup
+   \dostepwiserecurse\currentnesting\plusone\minusone
+     {\space\getvalue{level::\recurselevel}}
+   \endgraf
+   \egroup
+   \writestatus\m!systems{quitting due to level error}\wait
+   \batchmode}
+
+\prependtoks 
+  \checknesting
+\to \everystoptext 
+
+\protect \doifnotmode{demo}{\endinput}
+
+\starttext 
+
+% \startnesting{eerste}
+%   \startnesting{tweede}
+%     \startnesting{derde}
+%       \startnesting{vierde}
+%         test 
+%       \stopnesting{vierde}
+% \stopnesting{eerste}
+
+% \startnesting{eerste}
+%   \startnesting{tweede}
+%         test 
+%       \stopnesting{vierde}
+%     \stopnesting{derde}
+%   \stopnesting{tweede}
+% \stopnesting{eerste}
+
+\startnesting{eerste}
+  \startnesting{tweede}
+    \startnesting{derde}
+      \startnesting{vierde}
+        test 
+      \stopnesting{vierde}
+    \stopnesting{derde}
+  \stopnesting{tweede}
+\stopnesting{eerste}
+
+\stoptext 
-- 
cgit v1.2.3

