Merged with the latest syntax from Vky

This commit is contained in:
Dandaedre 2022-03-15 14:44:41 +01:00
commit 6e122d0c71
1 changed files with 23 additions and 10 deletions

View File

@ -86,8 +86,12 @@ class HeaderToken(SemanticType):
label = "header"
class IdentifierToken(SemanticType):
label = "identifier"
class StructuralElementStartToken(SemanticType):
label = "se:start"
class StructuralElementEndToken(SemanticType):
label = "se:end"
class HyperlinkToken(SemanticType):
@ -176,11 +180,14 @@ image_element = ('@{' + pp.common.identifier('image_name') + '}')("image_element
alias_element = ('@[' + pp.common.identifier('alias_name') + ']')("alias_element")
expression = pp.Word(pp.alphanums + r'=+-_\'",;:!<> ')
html_insert = '{' + expression('html_insert') + '}'
structural_elements = \
(pp.Word('div') ^ pp.Word('article') ^ pp.Word('aside') ^ pp.Word('section'))('structural_element')
# Optional elements
optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional")
# TODO : Everywhere : Avoid text at all costs since it is not a valid token, make a new token for it or use pp.SkipTo or (...) # noqa E501 (line too long)
# TODO :
# Everywhere : Avoid text at all costs since it is not a valid token, make a new token for it or use pp.SkipTo or (...)
# Enhanced text elements # TODO: Add all markups so that they can be parsed, they no longer need to be linked
# et_em = ('*' + enhanced_text + '*')('em').add_parse_action(of_type(EtEmToken))
# et_strong = ('**' + enhanced_text + '**')('strong').add_parse_action(of_type(EtStrongToken))
@ -194,16 +201,21 @@ optional = (pp.Opt(html_insert)("html_insert") + pp.Opt(var)("var"))("optional")
# et_strikethrough | et_custom_span) + pp.Opt(enhanced_text)
# Multiline elements
div_start = '~~' + text # TODO : It's not a text, rather a keyword and add ("name") and .add_parse_action(of_type(TextToken)) # noqa E501 (line too long)
div_end = text + '~~' # TODO : Idem
se_start = ('~~' + structural_elements).add_parse_action(of_type(StructuralElementStartToken))
se_end = (structural_elements + '~~').add_parse_action(of_type(StructuralElementEndToken))
# Inline elements
il_link = '[' + text + ']' + '(' + quotes + http_characters + pp.match_previous_literal(quotes) + ')' # Todo: change the quotes to quoted_string, get rid of text which was a placeholder # noqa E501 (line too long)
il_link = '[' + ... + ']' + '(' + pp.quoted_string(http_characters, esc_character='\\') + ')'
# Oneline elements
one_header = ('#' + text + pps('#')).add_parse_action(of_type(HeaderToken)) # 1 per hX or copy paste six times? # TODO: add a header level to the token and get rid of the text which was a placeholder # noqa E501 (line too long)
one_olist = pp.line_start + (pp.Word(pp.nums) ^ pp.Word('#')) + '.' + text # TODO: add a ("name") and add .add_parse_action(of_type(TextToken)) # noqa E501 (line too long)
one_ulist = pp.line_start + ('-' + text).add_parse_action(of_type(EtUlistToken)) # TODO: add a ("name") and add .add_parse_action(of_type(TextToken)) and get rid of the text which was a placeholder # noqa E501 (line too long)
one_header = ('#' + ... + pps('#')).add_parse_action(of_type(HeaderToken)).addParseAction(of_type(HeaderToken))
# TODO: add a header level to the token
one_olist = pp.line_start + \
((pp.Word(pp.nums) ^ pp.Word('#')) + '.' + ... + pp.line_end).add_parse_action(of_type(EtOlistToken))
# TODO: add a ("name")
one_ulist = pp.line_start + \
('-' + ... + pp.line_end).add_parse_action(of_type(EtUlistToken))
# TODO: add a ("name")
# Final elements
enhanced_text = text # TODO: It's actually text or et_em or et_strong etc..., either recursive or repeated
@ -223,8 +235,9 @@ line_to_replace = pp.OneOrMore(pp.SkipTo(image ^ alias)('text').add_parse_action
alias.add_parse_action(of_type(AliasToken)))\
^ pp.SkipTo(pp.lineEnd)('text').add_parse_action(of_type(TextToken))
###############################################################################
##############################################################################
# Temporary tests
##############################################################################
if __name__ == '__main__': # pragma: no cover
pp.autoname_elements()