resolved merge
This commit is contained in:
commit
1d9be95016
|
|
@ -1,4 +1,5 @@
|
||||||
# Dedicated module for the syntax of all the parsing
|
# Dedicated module for the syntax of all the parsing
|
||||||
|
import os
|
||||||
import pyparsing as pp
|
import pyparsing as pp
|
||||||
import rich
|
import rich
|
||||||
|
|
||||||
|
|
@ -123,15 +124,16 @@ var = '[' + pp.delimitedList(assignation ^ value)("list_vars").set_name("list_va
|
||||||
|
|
||||||
# Enhanced text
|
# Enhanced text
|
||||||
enhanced_text = pp.Forward()
|
enhanced_text = pp.Forward()
|
||||||
et_em = (pps('*') + enhanced_text + pps('*'))('em').add_parse_action(of_type(EtEmToken))
|
et_em = ('*' + enhanced_text + '*')('em').add_parse_action(of_type(EtEmToken))
|
||||||
et_strong = (pps('**') + enhanced_text + pps('**'))('strong').add_parse_action(of_type(EtStrongToken))
|
et_strong = ('**' + enhanced_text + '**')('strong').add_parse_action(of_type(EtStrongToken))
|
||||||
et_underline = (pps('__') + enhanced_text + pps('__'))('underline').add_parse_action(of_type(EtUnderlineToken))
|
et_underline = ('__' + enhanced_text + '__')('underline').add_parse_action(of_type(EtUnderlineToken))
|
||||||
et_strikethrough = (pps('~~') + enhanced_text + pps('~~'))('strikethrough').add_parse_action(of_type(EtStrikethroughToken))
|
et_strikethrough = ('~~' + enhanced_text + '~~')('strikethrough').add_parse_action(of_type(EtStrikethroughToken))
|
||||||
custom_span = ('(#' + pp.Word(pp.nums)('span_id') + ')').set_name('span_tag')
|
custom_span = ('(#' + pp.Word(pp.nums)('span_id') + ')').set_name('span_tag')
|
||||||
et_custom_span = \
|
et_custom_span = \
|
||||||
(custom_span + enhanced_text + pp.match_previous_literal(custom_span))('custom_span')\
|
(custom_span + enhanced_text + pp.match_previous_literal(custom_span))('custom_span')\
|
||||||
.add_parse_action(of_type(EtCustomSpanToken))
|
.add_parse_action(of_type(EtCustomSpanToken))
|
||||||
enhanced_text <<= (text | et_strong | et_em | et_underline | et_strikethrough | et_custom_span) + pp.Opt(enhanced_text)
|
enhanced_text <<= (text | et_strong | et_em | et_underline | et_strikethrough | et_custom_span) + pp.Opt(enhanced_text)
|
||||||
|
enhanced_text.enablePackrat()
|
||||||
|
|
||||||
# Multiline elements
|
# Multiline elements
|
||||||
div_start = '~~' + text
|
div_start = '~~' + text
|
||||||
|
|
@ -168,6 +170,18 @@ line_to_replace = pp.OneOrMore(pp.SkipTo(image ^ alias)('text').add_parse_action
|
||||||
# Temporary tests
|
# Temporary tests
|
||||||
if __name__ == '__main__': # pragma: no cover
|
if __name__ == '__main__': # pragma: no cover
|
||||||
pp.autoname_elements()
|
pp.autoname_elements()
|
||||||
|
|
||||||
|
def find_color(new_time, old_time):
|
||||||
|
pct = percent(new_time, old_time)
|
||||||
|
if pct < 80:
|
||||||
|
return "red"
|
||||||
|
elif pct > 130:
|
||||||
|
return "green"
|
||||||
|
return "yellow"
|
||||||
|
|
||||||
|
def percent(new_time, old_time):
|
||||||
|
return round((old_time/new_time) * 100, 2)
|
||||||
|
|
||||||
list_strings = [
|
list_strings = [
|
||||||
"Normal text",
|
"Normal text",
|
||||||
"Normal text *em text*",
|
"Normal text *em text*",
|
||||||
|
|
@ -184,7 +198,6 @@ if __name__ == '__main__': # pragma: no cover
|
||||||
"1. ordered list",
|
"1. ordered list",
|
||||||
"- unordered list",
|
"- unordered list",
|
||||||
]
|
]
|
||||||
|
|
||||||
# div_start.parse_string(list_strings[8])
|
# div_start.parse_string(list_strings[8])
|
||||||
# div_end.parse_string(list_strings[9])
|
# div_end.parse_string(list_strings[9])
|
||||||
# il_link.parse_string(list_strings[10])
|
# il_link.parse_string(list_strings[10])
|
||||||
|
|
@ -200,6 +213,43 @@ if __name__ == '__main__': # pragma: no cover
|
||||||
# print('Output string:', readable_markup(output))
|
# print('Output string:', readable_markup(output))
|
||||||
# print()
|
# print()
|
||||||
|
|
||||||
# mega_string = (' '.join(list_strings) + ' ')*2
|
nominal_t = {"Normal text": 0.005791999999999992,
|
||||||
# print(mega_string)
|
"Normal text *em text*": 0.017378599999999966,
|
||||||
# output = enhanced_text.parse_string(mega_string)
|
"Normal text **strong text**": 0.021291599999999966,
|
||||||
|
"Normal text __underline text__": 0.016918500000000003,
|
||||||
|
"Normal text ~~strikethrough text~~": 0.016525699999999977,
|
||||||
|
"Normal text (#123) custom span text(#123)": 0.04130879999999998,
|
||||||
|
"**Strong text __underline__** normal text": 0.05399810000000005,
|
||||||
|
"Normal text **strong text *em text*** *em text **strong text*** normal text": 0.35971580000000003,
|
||||||
|
"mega_string": 4.5726051000000005,
|
||||||
|
}
|
||||||
|
if not os.path.exists('../../../dev_outputs/'):
|
||||||
|
os.mkdir('../../../dev_outputs/')
|
||||||
|
enhanced_text.create_diagram("../../../dev_outputs/diagram.html")
|
||||||
|
|
||||||
|
import timeit
|
||||||
|
base_time = {}
|
||||||
|
for string, time in nominal_t.items():
|
||||||
|
if string == "mega_string":
|
||||||
|
continue
|
||||||
|
print('Input string:', string)
|
||||||
|
n_time = timeit.timeit("enhanced_text.parseString(string)", number=100, globals=globals())
|
||||||
|
base_time[string] = n_time
|
||||||
|
output = enhanced_text.parseString(string)
|
||||||
|
# rich.inspect(output)
|
||||||
|
color = find_color(n_time, time)
|
||||||
|
perc = percent(n_time, time)
|
||||||
|
rich.print(f'[{color}]Output string: {readable_markup(output)} in {n_time:.2}s vs {time:.2} ({perc} %)[/{color}]')
|
||||||
|
print()
|
||||||
|
|
||||||
|
mega_string = ' '.join(list_strings)
|
||||||
|
|
||||||
|
time = timeit.timeit("enhanced_text.parseString(mega_string)", number=5, globals=globals())
|
||||||
|
color = find_color(time, nominal_t['mega_string'])
|
||||||
|
perc = percent(time, nominal_t['mega_string'])
|
||||||
|
rich.print(f'[{color}]Mega time: {time} vs {nominal_t["mega_string"]} ({perc})% [/{color}]')
|
||||||
|
base_time['mega_string'] = time
|
||||||
|
|
||||||
|
print('Base time:')
|
||||||
|
for string, time in base_time.items():
|
||||||
|
print(f' "{string}": {time},')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue