diff --git a/mwparserfromhell/parser/contexts.py b/mwparserfromhell/parser/contexts.py index d3f0254..5e4793b 100644 --- a/mwparserfromhell/parser/contexts.py +++ b/mwparserfromhell/parser/contexts.py @@ -90,6 +90,13 @@ Local (stack-specific) contexts: Global contexts: * :py:const:`GL_HEADING` + +Aggregate contexts: + +* :py:const:`FAIL` +* :py:const:`UNSAFE` +* :py:const:`DOUBLE` + """ # Local contexts: @@ -144,3 +151,10 @@ SAFETY_CHECK = (HAS_TEXT + FAIL_ON_TEXT + FAIL_NEXT + FAIL_ON_LBRACE + # Global contexts: GL_HEADING = 1 << 0 + +# Aggregate contexts: + +FAIL = TEMPLATE + ARGUMENT + WIKILINK + HEADING + COMMENT + TAG + STYLE +UNSAFE = (TEMPLATE_NAME + WIKILINK_TITLE + TEMPLATE_PARAM_KEY + ARGUMENT_NAME + + TAG_CLOSE) +DOUBLE = TEMPLATE_PARAM_KEY + TAG_CLOSE diff --git a/mwparserfromhell/parser/tokenizer.py b/mwparserfromhell/parser/tokenizer.py index d4197e6..e9f565c 100644 --- a/mwparserfromhell/parser/tokenizer.py +++ b/mwparserfromhell/parser/tokenizer.py @@ -787,15 +787,11 @@ class Tokenizer(object): def _handle_end(self): """Handle the end of the stream of wikitext.""" - fail = (contexts.TEMPLATE | contexts.ARGUMENT | contexts.WIKILINK | - contexts.HEADING | contexts.COMMENT | contexts.TAG | - contexts.STYLE) - double_fail = (contexts.TEMPLATE_PARAM_KEY | contexts.TAG_CLOSE) - if self._context & fail: + if self._context & contexts.FAIL: if self._context & contexts.TAG_BODY: if is_single(self._stack[1].text): return self._handle_single_tag_end() - if self._context & double_fail: + if self._context & contexts.DOUBLE: self._pop() self._fail_route() return self._pop() @@ -859,17 +855,13 @@ class Tokenizer(object): def _parse(self, context=0, push=True): """Parse the wikicode string, using *context* for when to stop.""" - unsafe = (contexts.TEMPLATE_NAME | contexts.WIKILINK_TITLE | - contexts.TEMPLATE_PARAM_KEY | contexts.ARGUMENT_NAME | - contexts.TAG_CLOSE) - double_unsafe = (contexts.TEMPLATE_PARAM_KEY | contexts.TAG_CLOSE) if push: self._push(context) while True: this = self._read() - if self._context & unsafe: + if self._context & contexts.UNSAFE: if not self._verify_safe(this): - if self._context & double_unsafe: + if self._context & contexts.DOUBLE: self._pop() self._fail_route() if this not in self.MARKERS: