Added TokenToMatch SemanticType to avoid defaulting to matched_elements
This commit is contained in:
parent
388c92679d
commit
8e15a30b5d
|
|
@ -361,8 +361,8 @@ class ContextManager:
|
||||||
self.dict_lookahead = {
|
self.dict_lookahead = {
|
||||||
"list:ulist": ["list:ulist"],
|
"list:ulist": ["list:ulist"],
|
||||||
"list:olist": ["list:olist"],
|
"list:olist": ["list:olist"],
|
||||||
"table:row": ["table:separator", "table:row"], # TODO: Implement tables
|
"table:row": ["table:separator", "table:row"], # future: Implement tables
|
||||||
"blockquotes": [], # TODO: Implement blockquotes
|
"blockquotes": [], # future: Implement blockquotes
|
||||||
"linebreak": ["linebreak"],
|
"linebreak": ["linebreak"],
|
||||||
}
|
}
|
||||||
self.contextualised = False
|
self.contextualised = False
|
||||||
|
|
@ -470,7 +470,7 @@ class ContextManager:
|
||||||
index += lookahead_return[0]
|
index += lookahead_return[0]
|
||||||
line_number += lookahead_return[1]
|
line_number += lookahead_return[1]
|
||||||
|
|
||||||
# TODO: advanced lookahead for * logic
|
# future: advanced lookahead for * logic
|
||||||
# elif token.label in self.dict_advanced_lookahead:
|
# elif token.label in self.dict_advanced_lookahead:
|
||||||
|
|
||||||
elif isinstance(token, syntax.FinalSemanticType): # one-liners
|
elif isinstance(token, syntax.FinalSemanticType): # one-liners
|
||||||
|
|
@ -485,8 +485,12 @@ class ContextManager:
|
||||||
raise MismatchedContainerError(token)
|
raise MismatchedContainerError(token)
|
||||||
|
|
||||||
# Starting token by default (can cause unintended behaviours on bad implementations)
|
# Starting token by default (can cause unintended behaviours on bad implementations)
|
||||||
else: # TODO: remove this default behaviour, error instead
|
elif isinstance(token, syntax.TokensToMatch):
|
||||||
self._add_matched(token.label, index)
|
self._add_matched(token.label, index)
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise MismatchedContainerError(token)
|
||||||
|
|
||||||
except MismatchedContainerError as e:
|
except MismatchedContainerError as e:
|
||||||
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Be more specific.
|
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Be more specific.
|
||||||
index += 1
|
index += 1
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,12 @@ class SemanticType:
|
||||||
raise MismatchedContainerError(self)
|
raise MismatchedContainerError(self)
|
||||||
|
|
||||||
|
|
||||||
|
class TokensToMatch:
|
||||||
|
"""Class used for verification in the context manager.
|
||||||
|
Classes inheriting this should be added to matched_elements."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AddFirstElementToLabel(SemanticType):
|
class AddFirstElementToLabel(SemanticType):
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
super().__init__(content)
|
super().__init__(content)
|
||||||
|
|
@ -183,32 +189,27 @@ class TextToken(EmptySemanticType):
|
||||||
|
|
||||||
|
|
||||||
# FUTURE: all one-line elements should to inherit FinalSemanticType
|
# FUTURE: all one-line elements should to inherit FinalSemanticType
|
||||||
class EnhancedToken(ExplicitSemanticType):
|
class EtEmToken(ExplicitSemanticType, TokensToMatch):
|
||||||
"""Mother of all EtTokens"""
|
|
||||||
label = "text:enhanced"
|
|
||||||
|
|
||||||
|
|
||||||
class EtEmToken(ExplicitSemanticType):
|
|
||||||
"""*"""
|
"""*"""
|
||||||
label = "text:em"
|
label = "text:em"
|
||||||
|
|
||||||
|
|
||||||
class EtStrongToken(ExplicitSemanticType):
|
class EtStrongToken(ExplicitSemanticType, TokensToMatch):
|
||||||
"""**"""
|
"""**"""
|
||||||
label = "text:strong"
|
label = "text:strong"
|
||||||
|
|
||||||
|
|
||||||
class EtUnderlineToken(ExplicitSemanticType):
|
class EtUnderlineToken(ExplicitSemanticType, TokensToMatch):
|
||||||
"""__"""
|
"""__"""
|
||||||
label = "text:underline"
|
label = "text:underline"
|
||||||
|
|
||||||
|
|
||||||
class EtStrikethroughToken(ExplicitSemanticType):
|
class EtStrikethroughToken(ExplicitSemanticType, TokensToMatch):
|
||||||
"""~~"""
|
"""~~"""
|
||||||
label = "text:strikethrough"
|
label = "text:strikethrough"
|
||||||
|
|
||||||
|
|
||||||
class EtCustomSpanToken(AddFirstElementToLabel, ExplicitSemanticType):
|
class EtCustomSpanToken(AddFirstElementToLabel, ExplicitSemanticType, TokensToMatch):
|
||||||
"""(#int)"""
|
"""(#int)"""
|
||||||
label = "text:custom_span"
|
label = "text:custom_span"
|
||||||
|
|
||||||
|
|
@ -239,7 +240,7 @@ class DisplayToken(FinalSemanticType):
|
||||||
label = "display"
|
label = "display"
|
||||||
|
|
||||||
|
|
||||||
class StructuralElementStartToken(AddFirstElementToLabel, OpenedSemanticType):
|
class StructuralElementStartToken(AddFirstElementToLabel, OpenedSemanticType, TokensToMatch):
|
||||||
"""<<div|article|section|aside"""
|
"""<<div|article|section|aside"""
|
||||||
label = 'se:start'
|
label = 'se:start'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue